private static SslProtocols LoadSecureProtocolConfiguration(SslProtocols defaultValue)
        {
            if (!s_disableSystemDefaultTlsVersions)
            {
                defaultValue = SslProtocols.None;
            }
            else if (!s_disableStrongCrypto)
            {
                defaultValue = SslProtocols.Tls13 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
            }
            else
            {
                defaultValue = SslProtocols.Tls | SslProtocols.Ssl3;
            }

            if (!s_disableStrongCrypto || !s_disableSystemDefaultTlsVersions)
            {
                string appSetting = RegistryConfiguration.AppConfigReadString(RegistryLocalSecureProtocolName, null);

                SecurityProtocolType value;
                if (Enum.TryParse(appSetting, out value))
                {
                    ValidateSecurityProtocol(value);
                    defaultValue = (SslProtocols)value;
                }
            }

            return(defaultValue);
        }
Esempio n. 2
0
        private static void LoadDisableStrongCryptoConfiguration()
        {
            try {
                bool disableStrongCryptoInternal = false;
                int  schUseStrongCryptoKeyValue  = 0;

                if (LocalAppContextSwitches.DontEnableSchUseStrongCrypto)
                {
                    //.Net 4.5.2 and below will default to false unless the registry key is specifically set to 1.
                    schUseStrongCryptoKeyValue =
                        RegistryConfiguration.GlobalConfigReadInt(strongCryptoValueName, 0);

                    disableStrongCryptoInternal = schUseStrongCryptoKeyValue != 1;
                }
                else
                {
                    // .Net 4.6 and above will default to true unless the registry key is specifically set to 0.
                    schUseStrongCryptoKeyValue =
                        RegistryConfiguration.GlobalConfigReadInt(strongCryptoValueName, 1);

                    disableStrongCryptoInternal = schUseStrongCryptoKeyValue == 0;
                }

                if (disableStrongCryptoInternal)
                {
                    // Revert the SecurityProtocol selection to the legacy combination.
                    s_SecurityProtocolType = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                }
                else
                {
                    s_SecurityProtocolType =
                        SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

                    string appSetting = RegistryConfiguration.AppConfigReadString(secureProtocolAppSetting, null);

                    SecurityProtocolType value;
                    try {
                        value = (SecurityProtocolType)Enum.Parse(typeof(SecurityProtocolType), appSetting);
                        ValidateSecurityProtocol(value);
                        s_SecurityProtocolType = value;
                    }
                    // Ignore all potential exceptions caused by Enum.Parse.
                    catch (ArgumentNullException) { }
                    catch (ArgumentException) { }
                    catch (NotSupportedException) { }
                    catch (OverflowException) { }
                }

                disableStrongCrypto = disableStrongCryptoInternal;
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
            }
        }