Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static bool GetIsInContainer()
return (IsLinux && File.Exists("/.dockerenv"));
}

private static bool GetProtocolSupportFromWindowsRegistry(SslProtocols protocol, bool defaultProtocolSupport)
private static bool GetProtocolSupportFromWindowsRegistry(SslProtocols protocol, bool defaultProtocolSupport, bool disabledByDefault = false)
{
string registryProtocolName = protocol switch
{
Expand All @@ -381,13 +381,18 @@ private static bool GetProtocolSupportFromWindowsRegistry(SslProtocols protocol,
string serverKey = @$"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\{registryProtocolName}\Server";

object client, server;
object clientDefault, serverDefault;
try
{
client = Registry.GetValue(clientKey, "Enabled", defaultProtocolSupport ? 1 : 0);
server = Registry.GetValue(serverKey, "Enabled", defaultProtocolSupport ? 1 : 0);
if (client is int c && server is int s)

clientDefault = Registry.GetValue(clientKey, "DisabledByDefault", 1);
serverDefault = Registry.GetValue(serverKey, "DisabledByDefault", 1);

if (client is int c && server is int s && clientDefault is int cd && serverDefault is int sd)
{
return c == 1 && s == 1;
return (c == 1 && s == 1) && (!disabledByDefault || (cd == 0 && sd == 0));
}
}
catch (SecurityException)
Expand Down Expand Up @@ -436,28 +441,35 @@ private static bool AndroidGetSslProtocolSupport(SslProtocols protocol)

private static bool GetTls10Support()
{
// on Windows, macOS, and Android TLS1.0/1.1 are supported.
// on macOS and Android TLS 1.0 is supported.
if (IsOSXLike || IsAndroid)
{
return true;
}

// Windows depend on registry, enabled by default on all supported versions.
if (IsWindows)
{
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls, true);
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls, defaultProtocolSupport: true);
}

return OpenSslGetTlsSupport(SslProtocols.Tls);
}

private static bool GetTls11Support()
{
// on Windows, macOS, and Android TLS1.0/1.1 are supported.
if (IsWindows)
{
// TLS 1.1 and 1.2 can work on Windows7 but it is not enabled by default.
bool defaultProtocolSupport = !IsWindows7;
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls11, defaultProtocolSupport);
// TLS 1.1 can work on Windows 7 but it is disabled by default.
if (IsWindows7)
{
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls11, defaultProtocolSupport: false, disabledByDefault: true);
}

// It is enabled on other versions unless explicitly disabled.
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls11, defaultProtocolSupport: true);
}
// on macOS and Android TLS 1.1 is supported.
else if (IsOSXLike || IsAndroid)
{
return true;
Expand All @@ -468,9 +480,19 @@ private static bool GetTls11Support()

private static bool GetTls12Support()
{
// TLS 1.1 and 1.2 can work on Windows7 but it is not enabled by default.
bool defaultProtocolSupport = !IsWindows7;
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls12, defaultProtocolSupport);
if (IsWindows)
{
// TLS 1.2 can work on Windows 7 but it is disabled by default.
if (IsWindows7)
{
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls12, defaultProtocolSupport: false, disabledByDefault: true);
}

// It is enabled on other versions unless explicitly disabled.
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls12, defaultProtocolSupport: true);
}

return true;
}

private static bool GetTls13Support()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public static IEnumerable<object[]> OneOrBothUseDefaulData()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/67712")]
[ConditionalTheory]
[MemberData(nameof(OneOrBothUseDefaulData))]
public async Task ClientAndServer_OneOrBothUseDefault_Ok(SslProtocols? clientProtocols, SslProtocols? serverProtocols)
Expand Down