@@ -16,12 +16,11 @@ public static SslCertBinding PreConfigureNetsh(
1616 // and also delete a certificate which is bound to the netsh
1717 if ( _netshWrapper . TryGetSslCertBinding ( httpsIpPort , out var sslCertBinding ) )
1818 {
19- _certThumbprint = sslCertBinding . CertificateThumbprint ;
19+ SslCertificatesConfigurator . RemoveCertificate ( sslCertBinding . CertificateThumbprint ) ;
2020 _netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
2121 }
2222
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 ) )
23+ if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
2524 {
2625 throw new ApplicationException ( $ "Failed to setup ssl binding for '{ httpsIpPort } '.") ;
2726 }
@@ -41,15 +40,18 @@ public static SslCertBinding PreConfigureNetsh(
4140 return sslCertBinding ;
4241 }
4342
44- public static void LogCurrentSslCertBinding ( string httpsIpPort ) => _netshWrapper . LogSslCertBinding ( httpsIpPort ) ;
43+ public static void LogCurrentSslCertBinding ( string httpsIpPort )
44+ => _netshWrapper . LogSslCertBinding ( httpsIpPort ) ;
4545
4646 public static void ResetNetshConfiguration (
4747 string httpsIpPort ,
4848 int certPublicKeyLength = 4096 )
4949 {
50+ // delete cert binding and cert itself. We want it to be as clean and deterministic as possible (even if more actions are performed)
5051 _netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
51- if ( string . IsNullOrEmpty ( _certThumbprint ) // again - if cert already exists, we can just reuse it
52- && ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
52+ SslCertificatesConfigurator . RemoveCertificate ( _certThumbprint ) ;
53+
54+ if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
5355 {
5456 throw new ApplicationException ( $ "Failed to self-sign a cert for '{ httpsIpPort } '.") ;
5557 }
0 commit comments