Skip to content

Commit 066ee97

Browse files
authored
[WinHTTP] Let OS chose SSL/TLS protocol if not set to WinHttpHandler (#113525)
* Do not set SSL/TLS protocols to WinHTTP and let the OS chose. * Remove SecurityProtocol.cs. * Feedback
1 parent c6586ed commit 066ee97

File tree

15 files changed

+23
-88
lines changed

15 files changed

+23
-88
lines changed

src/libraries/Common/src/System/Net/SecurityProtocol.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ System.Net.Http.WinHttpHandler</PackageDescription>
6464
Link="Common\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs" />
6565
<Compile Include="$(CommonPath)System\Net\HttpStatusDescription.cs"
6666
Link="Common\System\Net\Http\HttpStatusDescription.cs" />
67-
<Compile Include="$(CommonPath)\System\Net\SecurityProtocol.cs"
68-
Link="Common\System\Net\SecurityProtocol.cs" />
6967
<Compile Include="$(CommonPath)\System\Net\UriScheme.cs"
7068
Link="Common\System\Net\UriScheme.cs" />
7169
<Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs"

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,40 +1176,43 @@ private void SetSessionHandleTlsOptions(SafeWinHttpHandle sessionHandle)
11761176
{
11771177
const SslProtocols Tls13 = (SslProtocols)12288; // enum is missing in .NET Standard
11781178
uint optionData = 0;
1179-
SslProtocols sslProtocols =
1180-
(_sslProtocols == SslProtocols.None) ? SecurityProtocol.DefaultSecurityProtocols : _sslProtocols;
1179+
1180+
if (_sslProtocols == SslProtocols.None)
1181+
{
1182+
return;
1183+
}
11811184

11821185
#pragma warning disable 0618 // SSL2/SSL3 are deprecated
1183-
if ((sslProtocols & SslProtocols.Ssl2) != 0)
1186+
if ((_sslProtocols & SslProtocols.Ssl2) != 0)
11841187
{
11851188
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_SSL2;
11861189
}
11871190

1188-
if ((sslProtocols & SslProtocols.Ssl3) != 0)
1191+
if ((_sslProtocols & SslProtocols.Ssl3) != 0)
11891192
{
11901193
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_SSL3;
11911194
}
11921195
#pragma warning restore 0618
11931196

11941197
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
1195-
if ((sslProtocols & SslProtocols.Tls) != 0)
1198+
if ((_sslProtocols & SslProtocols.Tls) != 0)
11961199
{
11971200
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1;
11981201
}
11991202

1200-
if ((sslProtocols & SslProtocols.Tls11) != 0)
1203+
if ((_sslProtocols & SslProtocols.Tls11) != 0)
12011204
{
12021205
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1;
12031206
}
12041207
#pragma warning restore SYSLIB0039
12051208

1206-
if ((sslProtocols & SslProtocols.Tls12) != 0)
1209+
if ((_sslProtocols & SslProtocols.Tls12) != 0)
12071210
{
12081211
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
12091212
}
12101213

12111214
// Set this only if supported by WinHttp version.
1212-
if (s_supportsTls13.Value && (sslProtocols & Tls13) != 0)
1215+
if (s_supportsTls13.Value && (_sslProtocols & Tls13) != 0)
12131216
{
12141217
optionData |= Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
12151218
}

src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
4141
<Compile Include="$(CommonPath)System\Net\UriScheme.cs"
4242
Link="Common\System\Net\UriScheme.cs" />
43-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
44-
Link="Common\System\Net\SecurityProtocol.cs" />
4543
<Compile Include="$(CommonPath)System\Net\Http\HttpHandlerDefaults.cs"
4644
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
4745
<Compile Include="$(CommonPath)\System\Net\Http\WinInetProxyHelper.cs"

src/libraries/System.Net.Http/src/System.Net.Http.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@
391391
Link="Common\System\Net\HttpKnownHeaderNames.cs" />
392392
<Compile Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs"
393393
Link="Common\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs" />
394-
<Compile Include="$(CommonPath)\System\Net\SecurityProtocol.cs"
395-
Link="Common\System\Net\SecurityProtocol.cs" />
396394
<Compile Include="$(CommonPath)\System\Net\UriScheme.cs"
397395
Link="Common\System\Net\UriScheme.cs" />
398396
<Compile Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs"
@@ -410,8 +408,6 @@
410408
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows' and '$(TargetPlatformIdentifier)' != 'browser' and '$(TargetPlatformIdentifier)' != 'wasi'">
411409
<Compile Include="$(CommonPath)System\StrongToWeakReference.cs"
412410
Link="Common\Interop\Unix\StrongToWeakReference.cs" />
413-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
414-
Link="Common\System\Net\SecurityProtocol.cs" />
415411
<Compile Include="$(CommonPath)System\Net\UriScheme.cs"
416412
Link="Common\System\Net\UriScheme.cs" />
417413
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ internal sealed partial class HttpConnectionPool : IDisposable
2828
public const int DefaultHttpPort = 80;
2929
public const int DefaultHttpsPort = 443;
3030

31-
private static readonly bool s_isWindows7Or2008R2 = GetIsWindows7Or2008R2();
3231
private static readonly List<SslApplicationProtocol> s_http3ApplicationProtocols = new List<SslApplicationProtocol>() { SslApplicationProtocol.Http3 };
3332
private static readonly List<SslApplicationProtocol> s_http2ApplicationProtocols = new List<SslApplicationProtocol>() { SslApplicationProtocol.Http2, SslApplicationProtocol.Http11 };
3433
private static readonly List<SslApplicationProtocol> s_http2OnlyApplicationProtocols = new List<SslApplicationProtocol>() { SslApplicationProtocol.Http2 };
@@ -277,20 +276,6 @@ private static SslClientAuthenticationOptions ConstructSslOptions(HttpConnection
277276
// Set TargetHost for SNI
278277
sslOptions.TargetHost = sslHostName;
279278

280-
// Windows 7 and Windows 2008 R2 support TLS 1.1 and 1.2, but for legacy reasons by default those protocols
281-
// are not enabled when a developer elects to use the system default. However, in .NET Core 2.0 and earlier,
282-
// HttpClientHandler would enable them, due to being a wrapper for WinHTTP, which enabled them. Both for
283-
// compatibility and because we prefer those higher protocols whenever possible, SocketsHttpHandler also
284-
// pretends they're part of the default when running on Win7/2008R2.
285-
if (s_isWindows7Or2008R2 && sslOptions.EnabledSslProtocols == SslProtocols.None)
286-
{
287-
if (NetEventSource.Log.IsEnabled())
288-
{
289-
NetEventSource.Info(poolManager, $"Win7OrWin2K8R2 platform, Changing default TLS protocols to {SecurityProtocol.DefaultSecurityProtocols}");
290-
}
291-
sslOptions.EnabledSslProtocols = SecurityProtocol.DefaultSecurityProtocols;
292-
}
293-
294279
return sslOptions;
295280
}
296281

@@ -1026,19 +1011,6 @@ public bool CleanCacheAndDisposeIfUnused()
10261011
return false;
10271012
}
10281013

1029-
/// <summary>Gets whether we're running on Windows 7 or Windows 2008 R2.</summary>
1030-
private static bool GetIsWindows7Or2008R2()
1031-
{
1032-
OperatingSystem os = Environment.OSVersion;
1033-
if (os.Platform == PlatformID.Win32NT)
1034-
{
1035-
// Both Windows 7 and Windows 2008 R2 report version 6.1.
1036-
Version v = os.Version;
1037-
return v.Major == 6 && v.Minor == 1;
1038-
}
1039-
return false;
1040-
}
1041-
10421014
// For diagnostic purposes
10431015
public override string ToString() =>
10441016
$"{nameof(HttpConnectionPool)} " +

src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
Link="ProductionCode\Common\System\Net\Logging\NetEventSource.Common.cs" />
3636
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.Associate.cs"
3737
Link="Common\System\Net\Logging\NetEventSource.Common.Associate.cs" />
38-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
39-
Link="ProductionCode\Common\System\Net\SecurityProtocol.cs" />
4038
<Compile Include="$(CommonPath)System\Net\UriScheme.cs"
4139
Link="ProductionCode\Common\System\Net\UriScheme.cs" />
4240
<Compile Include="$(CommonPath)System\Text\SimpleRegex.cs"

src/libraries/System.Net.Mail/src/System.Net.Mail.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@
118118
Link="Common\System\Collections\Generic\BidirectionalDictionary.cs" />
119119
<Compile Include="$(CommonPath)System\NotImplemented.cs"
120120
Link="Common\System\NotImplemented.cs" />
121-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
122-
Link="Common\System\Net\SecurityProtocol.cs" />
123121
</ItemGroup>
124122

125123
<!-- Unix specific files -->

src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@
120120
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
121121
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.Associate.cs"
122122
Link="Common\System\Net\Logging\NetEventSource.Common.Associate.cs" />
123-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
124-
Link="Common\System\Net\SecurityProtocol.cs" />
125123
<Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
126124
Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
127125
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"

src/libraries/System.Net.Requests/src/System.Net.Requests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
Link="Common\System\Net\ContextAwareResult.cs" />
8282
<Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
8383
Link="Common\System\Net\ExceptionCheck.cs" />
84-
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
85-
Link="Common\System\Net\SecurityProtocol.cs" />
8684
<Compile Include="$(CommonPath)System\NotImplemented.cs"
8785
Link="Common\System\NotImplemented.cs" />
8886
</ItemGroup>

0 commit comments

Comments
 (0)