@@ -5,6 +5,8 @@ public static class NetshConfigurator
5
5
private static readonly NetShWrapper _netshWrapper = new ( ) ;
6
6
private static string _certThumbprint ;
7
7
8
+ private static string _resetCertThumbprint ;
9
+
8
10
public static SslCertBinding PreConfigureNetsh (
9
11
string httpsIpPort ,
10
12
int certPublicKeyLength = 2048 ,
@@ -43,22 +45,29 @@ public static SslCertBinding PreConfigureNetsh(
43
45
public static void LogCurrentSslCertBinding ( string httpsIpPort )
44
46
=> _netshWrapper . LogSslCertBinding ( httpsIpPort ) ;
45
47
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 )
49
57
{
50
58
// delete cert binding and cert itself. We want it to be as clean and deterministic as possible (even if more actions are performed)
51
59
_netshWrapper . DeleteBindingIfExists ( httpsIpPort ) ;
52
60
SslCertificatesConfigurator . RemoveCertificate ( _certThumbprint ) ;
53
61
54
- if ( ! _netshWrapper . TrySelfSignCertificate ( httpsIpPort , certPublicKeyLength , out _certThumbprint ) )
62
+ if ( string . IsNullOrEmpty ( _resetCertThumbprint ) )
55
63
{
56
- throw new ApplicationException ( $ "Failed to self-sign a cert for '{ httpsIpPort } '.") ;
64
+ throw new ApplicationException ( $ "Reset certificate is not prepared for '{ httpsIpPort } '.") ;
57
65
}
58
66
67
+ // reset certificate was prepared in advance - just bind it at this moment
59
68
_netshWrapper . AddCertBinding (
60
69
httpsIpPort ,
61
- _certThumbprint ,
70
+ _resetCertThumbprint ,
62
71
disablesessionid : NetShFlag . NotSet ,
63
72
enablesessionticket : NetShFlag . NotSet ,
64
73
clientCertNegotiation : NetShFlag . NotSet ) ;
0 commit comments