@@ -44,7 +44,7 @@ public sealed class CertificateManager : IDisposable
44
44
/// <summary>
45
45
/// Cache dictionary
46
46
/// </summary>
47
- private readonly ConcurrentDictionary < string , CachedCertificate > certificateCache ;
47
+ private readonly ConcurrentDictionary < string , CachedCertificate > cachedCertificates ;
48
48
49
49
private readonly CancellationTokenSource clearCertificatesTokenSource ;
50
50
@@ -58,7 +58,7 @@ public sealed class CertificateManager : IDisposable
58
58
59
59
private string rootCertificateName ;
60
60
61
- private ICertificateStorage certificateStorage ;
61
+ private ICertificateCache certificateCache ;
62
62
63
63
/// <summary>
64
64
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
@@ -98,11 +98,11 @@ internal CertificateManager(string rootCertificateName, string rootCertificateIs
98
98
99
99
CertificateEngine = CertificateEngine . BouncyCastle ;
100
100
101
- certificateCache = new ConcurrentDictionary < string , CachedCertificate > ( ) ;
101
+ cachedCertificates = new ConcurrentDictionary < string , CachedCertificate > ( ) ;
102
102
103
103
clearCertificatesTokenSource = new CancellationTokenSource ( ) ;
104
104
105
- certificateStorage = new DefaultCertificateStorage ( ) ;
105
+ certificateCache = new DefaultCertificateDiskCache ( ) ;
106
106
}
107
107
108
108
/// <summary>
@@ -224,10 +224,10 @@ public X509Certificate2 RootCertificate
224
224
/// The service to save fake certificates.
225
225
/// The default storage saves certificates in folder "crts" (will be created in proxy dll directory).
226
226
/// </summary>
227
- public ICertificateStorage CertificateStorage
227
+ public ICertificateCache CertificateStorage
228
228
{
229
- get => certificateStorage ;
230
- set => certificateStorage = value ?? new DefaultCertificateStorage ( ) ;
229
+ get => certificateCache ;
230
+ set => certificateCache = value ?? new DefaultCertificateDiskCache ( ) ;
231
231
}
232
232
233
233
/// <summary>
@@ -388,7 +388,7 @@ internal X509Certificate2 CreateCertificate(string certificateName, bool isRootC
388
388
389
389
try
390
390
{
391
- certificate = certificateStorage . LoadCertificate ( subjectName , StorageFlag ) ;
391
+ certificate = certificateCache . LoadCertificate ( subjectName , StorageFlag ) ;
392
392
}
393
393
catch ( Exception e )
394
394
{
@@ -402,7 +402,7 @@ internal X509Certificate2 CreateCertificate(string certificateName, bool isRootC
402
402
403
403
try
404
404
{
405
- certificateStorage . SaveCertificate ( subjectName , certificate ) ;
405
+ certificateCache . SaveCertificate ( subjectName , certificate ) ;
406
406
}
407
407
catch ( Exception e )
408
408
{
@@ -432,7 +432,7 @@ internal X509Certificate2 CreateCertificate(string certificateName, bool isRootC
432
432
internal async Task < X509Certificate2 > CreateCertificateAsync ( string certificateName )
433
433
{
434
434
// check in cache first
435
- var item = certificateCache . GetOrAdd ( certificateName , _ =>
435
+ var item = cachedCertificates . GetOrAdd ( certificateName , _ =>
436
436
{
437
437
var cached = new CachedCertificate ( ) ;
438
438
cached . CreationTask = Task . Run ( ( ) =>
@@ -479,11 +479,11 @@ internal async void ClearIdleCertificates()
479
479
{
480
480
var cutOff = DateTime . Now . AddMinutes ( - 1 * CertificateCacheTimeOutMinutes ) ;
481
481
482
- var outdated = certificateCache . Where ( x => x . Value . LastAccess < cutOff ) . ToList ( ) ;
482
+ var outdated = cachedCertificates . Where ( x => x . Value . LastAccess < cutOff ) . ToList ( ) ;
483
483
484
484
foreach ( var cache in outdated )
485
485
{
486
- certificateCache . TryRemove ( cache . Key , out _ ) ;
486
+ cachedCertificates . TryRemove ( cache . Key , out _ ) ;
487
487
}
488
488
489
489
// after a minute come back to check for outdated certificates in cache
@@ -529,7 +529,7 @@ public bool CreateRootCertificate(bool persistToFile = true)
529
529
{
530
530
try
531
531
{
532
- var rootCert = certificateStorage . LoadRootCertificate ( PfxFilePath , PfxPassword , X509KeyStorageFlags . Exportable ) ;
532
+ var rootCert = certificateCache . LoadRootCertificate ( PfxFilePath , PfxPassword , X509KeyStorageFlags . Exportable ) ;
533
533
if ( rootCert != null )
534
534
{
535
535
return false ;
@@ -556,14 +556,14 @@ public bool CreateRootCertificate(bool persistToFile = true)
556
556
{
557
557
try
558
558
{
559
- certificateStorage . Clear ( ) ;
559
+ certificateCache . Clear ( ) ;
560
560
}
561
561
catch
562
562
{
563
563
// ignore
564
564
}
565
565
566
- certificateStorage . SaveRootCertificate ( PfxFilePath , PfxPassword , RootCertificate ) ;
566
+ certificateCache . SaveRootCertificate ( PfxFilePath , PfxPassword , RootCertificate ) ;
567
567
}
568
568
catch ( Exception e )
569
569
{
@@ -582,7 +582,7 @@ public X509Certificate2 LoadRootCertificate()
582
582
{
583
583
try
584
584
{
585
- return certificateStorage . LoadRootCertificate ( PfxFilePath , PfxPassword , X509KeyStorageFlags . Exportable ) ;
585
+ return certificateCache . LoadRootCertificate ( PfxFilePath , PfxPassword , X509KeyStorageFlags . Exportable ) ;
586
586
}
587
587
catch ( Exception e )
588
588
{
@@ -875,8 +875,8 @@ public bool RemoveTrustedRootCertificateAsAdmin(bool machineTrusted = false)
875
875
/// </summary>
876
876
public void ClearRootCertificate ( )
877
877
{
878
- certificateStorage . Clear ( ) ;
879
878
certificateCache . Clear ( ) ;
879
+ cachedCertificates . Clear ( ) ;
880
880
rootCertificate = null ;
881
881
}
882
882
}
0 commit comments