@@ -5,6 +5,8 @@ public static class NetshConfigurator
55 private static readonly NetShWrapper _netshWrapper = new ( ) ;
66 private static string _certThumbprint ;
77
8+ private static string _resetCertThumbprint ;
9+
810 public static SslCertBinding PreConfigureNetsh (
911 string httpsIpPort ,
1012 int certPublicKeyLength = 2048 ,
@@ -43,22 +45,29 @@ public static SslCertBinding PreConfigureNetsh(
4345 public static void LogCurrentSslCertBinding ( string httpsIpPort )
4446 => _netshWrapper . LogSslCertBinding ( httpsIpPort ) ;
4547
46- public static void ResetNetshConfiguration (
47- string httpsIpPort ,
48- int certPublicKeyLength = 4096 )
48+ public static void PrepareResetNetsh ( string httpsIpPort , int certPublicKeyLength = 4096 )
49+ {
50+ if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _resetCertThumbprint ) )
51+ {
52+ throw new ApplicationException ( $ "Failed to self-sign a cert for '{ httpsIpPort } '.") ;
53+ }
54+ }
55+
56+ public static void ResetNetshConfiguration ( string httpsIpPort )
4957 {
5058 // delete cert binding and cert itself. We want it to be as clean and deterministic as possible (even if more actions are performed)
5159 _netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
5260 SslCertificatesConfigurator . RemoveCertificate ( _certThumbprint ) ;
5361
54- if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
62+ if ( string . IsNullOrEmpty ( _resetCertThumbprint ) )
5563 {
56- throw new ApplicationException ( $ "Failed to self-sign a cert for '{ httpsIpPort } '.") ;
64+ throw new ApplicationException ( $ "Reset certificate is not prepared for '{ httpsIpPort } '.") ;
5765 }
5866
67+ // reset certificate was prepared in advance - just bind it at this moment
5968 _netshWrapper . AddCertBinding (
6069 httpsIpPort ,
61- _certThumbprint ,
70+ _resetCertThumbprint ,
6271 disablesessionid : NetShFlag . NotSet ,
6372 enablesessionticket : NetShFlag . NotSet ,
6473 clientCertNegotiation : NetShFlag . NotSet ) ;
0 commit comments