Skip to content

Commit c99b857

Browse files
authored
Revert changes to HttpClient/SslStream certificate revocation check mode defaults (#118456)
* Revert "Change HttpClient/SslStream default certificate revocation check mode to Online (#116098)" This reverts commit 6a4b7e3. * Reapply "Change HttpClient/SslStream default certificate revocation check mode to Online (#116098)" This reverts commit defd136. * 2nd try * Revert test expectations * revert whitespace changes * Update src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs * Fix WinHttphandlerTest
1 parent 908c827 commit c99b857

File tree

8 files changed

+16
-46
lines changed

8 files changed

+16
-46
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ServerCertificates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void Ctor_ExpectedDefaultValues()
4848
using (HttpClientHandler handler = CreateHttpClientHandler())
4949
{
5050
Assert.Null(handler.ServerCertificateCustomValidationCallback);
51-
Assert.True(handler.CheckCertificateRevocationList);
51+
Assert.False(handler.CheckCertificateRevocationList);
5252
}
5353
}
5454

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public void Ctor_ExpectedDefaultPropertyValues()
7676
Assert.False(handler.PreAuthenticate);
7777
Assert.True(handler.SupportsProxy);
7878
Assert.True(handler.SupportsRedirectConfiguration);
79+
Assert.False(handler.CheckCertificateRevocationList);
7980

8081
// Changes from .NET Framework.
81-
Assert.True(handler.CheckCertificateRevocationList);
8282
Assert.Equal(0, handler.MaxRequestContentBufferSize);
8383
Assert.Equal(SslProtocols.None, handler.SslProtocols);
8484
}

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ public class WinHttpHandler : HttpMessageHandler
4343
internal static readonly Version HttpVersion20 = new Version(2, 0);
4444
internal static readonly Version HttpVersion30 = new Version(3, 0);
4545
internal static readonly Version HttpVersionUnknown = new Version(0, 0);
46-
internal static bool DefaultCertificateRevocationCheck { get; } =
47-
AppContextSwitchHelper.GetBooleanConfig(
48-
"System.Net.Security.NoRevocationCheckByDefault",
49-
"DOTNET_SYSTEM_NET_SECURITY_NOREVOCATIONCHECKBYDEFAULT") ? false : true;
46+
internal static bool DefaultCertificateRevocationCheck { get; }
5047

5148
internal static bool CertificateCachingAppContextSwitchEnabled { get; } = AppContext.TryGetSwitch("System.Net.Http.UseWinHttpCertificateCaching", out bool enabled) && enabled;
5249
private static readonly TimeSpan s_maxTimeout = TimeSpan.FromMilliseconds(int.MaxValue);

src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpHandlerTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Ctor_ExpectedDefaultPropertyValues()
4545
Assert.Equal(CookieUsePolicy.UseInternalCookieStoreOnly, handler.CookieUsePolicy);
4646
Assert.Null(handler.CookieContainer);
4747
Assert.Null(handler.ServerCertificateValidationCallback);
48-
Assert.True(handler.CheckCertificateRevocationList);
48+
Assert.False(handler.CheckCertificateRevocationList);
4949
Assert.Equal(ClientCertificateOption.Manual, handler.ClientCertificateOption);
5050
X509Certificate2Collection certs = handler.ClientCertificates;
5151
Assert.True(certs.Count == 0);
@@ -130,7 +130,8 @@ public void TcpKeepalive_WhenEnabled_ForwardsCorrectNativeOptions()
130130
{
131131
using var handler = new WinHttpHandler();
132132

133-
SendRequestHelper.Send(handler, () => {
133+
SendRequestHelper.Send(handler, () =>
134+
{
134135
handler.TcpKeepAliveEnabled = true;
135136
handler.TcpKeepAliveTime = TimeSpan.FromMinutes(13);
136137
handler.TcpKeepAliveInterval = TimeSpan.FromSeconds(42);
@@ -148,7 +149,8 @@ public void TcpKeepalive_InfiniteTimeSpan_TranslatesToUInt32MaxValue()
148149
{
149150
using var handler = new WinHttpHandler();
150151

151-
SendRequestHelper.Send(handler, () => {
152+
SendRequestHelper.Send(handler, () =>
153+
{
152154
handler.TcpKeepAliveEnabled = true;
153155
handler.TcpKeepAliveTime = Timeout.InfiniteTimeSpan;
154156
handler.TcpKeepAliveInterval = Timeout.InfiniteTimeSpan;
@@ -312,7 +314,8 @@ public void CookieUsePolicy_SetUseSpecifiedCookieContainerAndContainer_ExpectedW
312314

313315
SendRequestHelper.Send(
314316
handler,
315-
delegate {
317+
delegate
318+
{
316319
handler.CookieUsePolicy = CookieUsePolicy.UseSpecifiedCookieContainer;
317320
handler.CookieContainer = new CookieContainer();
318321
});

src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ public void SslOptions_GetSet_Roundtrips()
25402540

25412541
Assert.True(options.AllowRenegotiation);
25422542
Assert.Null(options.ApplicationProtocols);
2543-
Assert.Equal(X509RevocationMode.Online, options.CertificateRevocationCheckMode);
2543+
Assert.Equal(X509RevocationMode.NoCheck, options.CertificateRevocationCheckMode);
25442544
Assert.Null(options.ClientCertificates);
25452545
Assert.Equal(SslProtocols.None, options.EnabledSslProtocols);
25462546
Assert.Equal(EncryptionPolicy.RequireEncryption, options.EncryptionPolicy);

src/libraries/System.Net.Security/src/System/Net/Security/SslAuthenticationOptions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ internal sealed class SslAuthenticationOptions : IDisposable
1313
{
1414
private const string EnableOcspStaplingContextSwitchName = "System.Net.Security.EnableServerOcspStaplingFromOnlyCertificateOnLinux";
1515

16-
internal static readonly X509RevocationMode DefaultRevocationMode =
17-
AppContextSwitchHelper.GetBooleanConfig(
18-
"System.Net.Security.NoRevocationCheckByDefault",
19-
"DOTNET_SYSTEM_NET_SECURITY_NOREVOCATIONCHECKBYDEFAULT")
20-
? X509RevocationMode.NoCheck : X509RevocationMode.Online;
16+
internal const X509RevocationMode DefaultRevocationMode = X509RevocationMode.NoCheck;
2117

2218
internal SslAuthenticationOptions()
2319
{

src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,5 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout(
8383
Assert.True(File.ReadAllText(tempFile).Length == 0);
8484
}
8585
}
86-
87-
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
88-
[InlineData(true)]
89-
[InlineData(false)]
90-
public void DefaultRevocationMode_OfflineRevocationByDefault_True_UsesNoCheck(bool useEnvVar)
91-
{
92-
var psi = new ProcessStartInfo();
93-
if (useEnvVar)
94-
{
95-
psi.Environment.Add("DOTNET_SYSTEM_NET_SECURITY_NOREVOCATIONCHECKBYDEFAULT", "true");
96-
}
97-
98-
Assert.Equal(X509RevocationMode.Online, new SslClientAuthenticationOptions().CertificateRevocationCheckMode);
99-
Assert.Equal(X509RevocationMode.Online, new SslServerAuthenticationOptions().CertificateRevocationCheckMode);
100-
101-
RemoteExecutor.Invoke(useEnvVar =>
102-
{
103-
if (!bool.Parse(useEnvVar))
104-
{
105-
AppContext.SetSwitch("System.Net.Security.NoRevocationCheckByDefault", true);
106-
}
107-
108-
Assert.Equal(X509RevocationMode.NoCheck, new SslClientAuthenticationOptions().CertificateRevocationCheckMode);
109-
Assert.Equal(X509RevocationMode.NoCheck, new SslServerAuthenticationOptions().CertificateRevocationCheckMode);
110-
}, useEnvVar.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
111-
}
11286
}
11387
}

src/libraries/System.Net.Security/tests/UnitTests/SslAuthenticationOptionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ public void EnabledSslProtocols_Get_Set_Succeeds()
133133
[Fact]
134134
public void CheckCertificateRevocation_Get_Set_Succeeds()
135135
{
136-
Assert.Equal(X509RevocationMode.Online, _clientOptions.CertificateRevocationCheckMode);
137-
Assert.Equal(X509RevocationMode.Online, _serverOptions.CertificateRevocationCheckMode);
136+
Assert.Equal(X509RevocationMode.NoCheck, _clientOptions.CertificateRevocationCheckMode);
137+
Assert.Equal(X509RevocationMode.NoCheck, _serverOptions.CertificateRevocationCheckMode);
138138

139-
_clientOptions.CertificateRevocationCheckMode = X509RevocationMode.NoCheck;
139+
_clientOptions.CertificateRevocationCheckMode = X509RevocationMode.Online;
140140
_serverOptions.CertificateRevocationCheckMode = X509RevocationMode.Offline;
141141

142-
Assert.Equal(X509RevocationMode.NoCheck, _clientOptions.CertificateRevocationCheckMode);
142+
Assert.Equal(X509RevocationMode.Online, _clientOptions.CertificateRevocationCheckMode);
143143
Assert.Equal(X509RevocationMode.Offline, _serverOptions.CertificateRevocationCheckMode);
144144

145145
Assert.Throws<ArgumentException>(() => _clientOptions.CertificateRevocationCheckMode = (X509RevocationMode)3);

0 commit comments

Comments
 (0)