diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 27e973d5980f4..799a400f5fbfa 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -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 { @@ -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) @@ -436,14 +441,16 @@ 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); @@ -451,13 +458,18 @@ private static bool GetTls10Support() 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; @@ -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() diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamSystemDefaultsTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamSystemDefaultsTest.cs index 69ae4f6f4e26a..d40bcf9148366 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamSystemDefaultsTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamSystemDefaultsTest.cs @@ -74,7 +74,6 @@ public static IEnumerable OneOrBothUseDefaulData() } } - [ActiveIssue("https://github.com/dotnet/runtime/issues/67712")] [ConditionalTheory] [MemberData(nameof(OneOrBothUseDefaulData))] public async Task ClientAndServer_OneOrBothUseDefault_Ok(SslProtocols? clientProtocols, SslProtocols? serverProtocols)