@@ -16,14 +16,14 @@ public static SslCertBinding PreConfigureNetsh(
16
16
// and also delete a certificate which is bound to the netsh
17
17
if ( _netshWrapper . TryGetSslCertBinding ( httpsIpPort , out var sslCertBinding ) )
18
18
{
19
- Console . WriteLine ( $ "Deleting certificate (thumbprint='{ sslCertBinding . CertificateThumbprint } ') from the localmachine(my) store") ;
20
- SslCertificatesConfigurator . RemoveCertificate ( sslCertBinding . CertificateThumbprint ) ;
19
+ _certThumbprint = sslCertBinding . CertificateThumbprint ;
21
20
_netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
22
21
}
23
22
24
- if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
23
+ if ( string . IsNullOrEmpty ( _certThumbprint ) // only need to self-sign if we dont have a cert in a store, otherwise just reuse it
24
+ && ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
25
25
{
26
- throw new ApplicationException ( $ "Failed to setup ssl binding for '{ httpsIpPort } '. Please unblock the VM. ") ;
26
+ throw new ApplicationException ( $ "Failed to setup ssl binding for '{ httpsIpPort } '.") ;
27
27
}
28
28
29
29
_netshWrapper . AddCertBinding (
@@ -48,10 +48,10 @@ public static void ResetNetshConfiguration(
48
48
int certPublicKeyLength = 4096 )
49
49
{
50
50
_netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
51
- if ( ! string . IsNullOrEmpty ( _certThumbprint ) )
51
+ if ( string . IsNullOrEmpty ( _certThumbprint ) // again - if cert already exists, we can just reuse it
52
+ && ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
52
53
{
53
- Console . WriteLine ( $ "Deleting certificate (thumbprint='{ _certThumbprint } ') from the localmachine(my) store") ;
54
- SslCertificatesConfigurator . RemoveCertificate ( _certThumbprint ) ;
54
+ throw new ApplicationException ( $ "Failed to self-sign a cert for '{ httpsIpPort } '.") ;
55
55
}
56
56
57
57
_netshWrapper . AddCertBinding (
0 commit comments