@@ -18,13 +18,16 @@ public class CertificateNotFoundException : Exception
18
18
public string Recipient { get ; init ; }
19
19
}
20
20
21
- class CertManagerInitializer ( ICertManager cm ) : BackgroundService
21
+ class CertManagerInitializer ( ICertManager cm , IPlumber plumber ) : BackgroundService
22
22
{
23
23
protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
24
24
{
25
25
await cm . Init ( ) ;
26
+ await plumber . Subscribe ( "$et-PublicCertificateSnapShotted" , FromRelativeStreamPosition . Start )
27
+ . WithSnapshotHandler < PubCertEventHandler > ( ) ;
26
28
}
27
29
}
30
+
28
31
class CertManager ( IPlumber plumber , IConfiguration configuration ) : ICertManager
29
32
{
30
33
private ConcurrentDictionary < string , X509Certificate2 > _private = new ( ) ;
@@ -34,19 +37,16 @@ public X509Certificate2 Get(string recipient)
34
37
return _public . GetOrAdd ( recipient , r =>
35
38
{
36
39
var certDir = configuration . GetValue < string > ( "CertsPath" ) ?? "./certs" ;
37
- var file = Path . Combine ( certDir , r + ".pfx" ) ;
40
+
38
41
if ( ! Directory . Exists ( certDir ) )
39
42
Directory . CreateDirectory ( certDir ) ;
43
+ var file = Path . Combine ( certDir , $ "{ r } .cer") ;
40
44
if ( File . Exists ( file ) )
41
45
return new X509Certificate2 ( file ) ;
42
- else
43
- {
44
- var result = plumber . GetState < PublicCertificate > ( recipient ) . Result ;
45
- if ( result == null )
46
- throw new CertificateNotFoundException ( ) { Recipient = recipient } ;
47
-
48
- return new X509Certificate2 ( result . Value . Data ) ;
49
- }
46
+ file = Path . Combine ( certDir , $ "{ r } .pfx") ;
47
+ if ( File . Exists ( file ) )
48
+ return new X509Certificate2 ( file ) ;
49
+ throw new CertificateNotFoundException ( ) { Recipient = recipient } ;
50
50
} ) ;
51
51
}
52
52
@@ -78,6 +78,7 @@ public async Task Init()
78
78
PublicCertificate pc = new PublicCertificate ( ) { Data = pubCer } ;
79
79
await plumber . AppendState ( pc , r ) ;
80
80
}
81
+
81
82
}
82
83
public X509Certificate2 GetPrivate ( string recipient )
83
84
{
0 commit comments