@@ -361,7 +361,7 @@ private static bool GetIsInContainer()
361
361
return ( IsLinux && File . Exists ( "/.dockerenv" ) ) ;
362
362
}
363
363
364
- private static bool GetProtocolSupportFromWindowsRegistry ( SslProtocols protocol , bool defaultProtocolSupport )
364
+ private static bool GetProtocolSupportFromWindowsRegistry ( SslProtocols protocol , bool defaultProtocolSupport , bool disabledByDefault = false )
365
365
{
366
366
string registryProtocolName = protocol switch
367
367
{
@@ -381,13 +381,18 @@ private static bool GetProtocolSupportFromWindowsRegistry(SslProtocols protocol,
381
381
string serverKey = @$ "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\{ registryProtocolName } \Server";
382
382
383
383
object client , server ;
384
+ object clientDefault , serverDefault ;
384
385
try
385
386
{
386
387
client = Registry . GetValue ( clientKey , "Enabled" , defaultProtocolSupport ? 1 : 0 ) ;
387
388
server = Registry . GetValue ( serverKey , "Enabled" , defaultProtocolSupport ? 1 : 0 ) ;
388
- if ( client is int c && server is int s )
389
+
390
+ clientDefault = Registry . GetValue ( clientKey , "DisabledByDefault" , 1 ) ;
391
+ serverDefault = Registry . GetValue ( serverKey , "DisabledByDefault" , 1 ) ;
392
+
393
+ if ( client is int c && server is int s && clientDefault is int cd && serverDefault is int sd )
389
394
{
390
- return c == 1 && s == 1 ;
395
+ return ( c == 1 && s == 1 ) && ( ! disabledByDefault || ( cd == 0 && sd == 0 ) ) ;
391
396
}
392
397
}
393
398
catch ( SecurityException )
@@ -436,28 +441,35 @@ private static bool AndroidGetSslProtocolSupport(SslProtocols protocol)
436
441
437
442
private static bool GetTls10Support ( )
438
443
{
439
- // on Windows, macOS, and Android TLS1.0/1.1 are supported.
444
+ // on macOS and Android TLS 1.0 is supported.
440
445
if ( IsOSXLike || IsAndroid )
441
446
{
442
447
return true ;
443
448
}
449
+
450
+ // Windows depend on registry, enabled by default on all supported versions.
444
451
if ( IsWindows )
445
452
{
446
- return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls , true ) ;
453
+ return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls , defaultProtocolSupport : true ) ;
447
454
}
448
455
449
456
return OpenSslGetTlsSupport ( SslProtocols . Tls ) ;
450
457
}
451
458
452
459
private static bool GetTls11Support ( )
453
460
{
454
- // on Windows, macOS, and Android TLS1.0/1.1 are supported.
455
461
if ( IsWindows )
456
462
{
457
- // TLS 1.1 and 1.2 can work on Windows7 but it is not enabled by default.
458
- bool defaultProtocolSupport = ! IsWindows7 ;
459
- return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls11 , defaultProtocolSupport ) ;
463
+ // TLS 1.1 can work on Windows 7 but it is disabled by default.
464
+ if ( IsWindows7 )
465
+ {
466
+ return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls11 , defaultProtocolSupport : false , disabledByDefault : true ) ;
467
+ }
468
+
469
+ // It is enabled on other versions unless explicitly disabled.
470
+ return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls11 , defaultProtocolSupport : true ) ;
460
471
}
472
+ // on macOS and Android TLS 1.1 is supported.
461
473
else if ( IsOSXLike || IsAndroid )
462
474
{
463
475
return true ;
@@ -468,9 +480,19 @@ private static bool GetTls11Support()
468
480
469
481
private static bool GetTls12Support ( )
470
482
{
471
- // TLS 1.1 and 1.2 can work on Windows7 but it is not enabled by default.
472
- bool defaultProtocolSupport = ! IsWindows7 ;
473
- return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls12 , defaultProtocolSupport ) ;
483
+ if ( IsWindows )
484
+ {
485
+ // TLS 1.2 can work on Windows 7 but it is disabled by default.
486
+ if ( IsWindows7 )
487
+ {
488
+ return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls12 , defaultProtocolSupport : false , disabledByDefault : true ) ;
489
+ }
490
+
491
+ // It is enabled on other versions unless explicitly disabled.
492
+ return GetProtocolSupportFromWindowsRegistry ( SslProtocols . Tls12 , defaultProtocolSupport : true ) ;
493
+ }
494
+
495
+ return true ;
474
496
}
475
497
476
498
private static bool GetTls13Support ( )
0 commit comments