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);
        }
Пример #2
0
        private static void LoadDisableSendAuxRecordConfiguration()
        {
            try {
                if (LocalAppContextSwitches.DontEnableSchSendAuxRecord)
                {
                    disableSendAuxRecord = true;
                    return;
                }

                int schSendAuxRecordKeyValue = 1;
                schSendAuxRecordKeyValue = RegistryConfiguration.AppConfigReadInt(sendAuxRecordAppSetting, 1);
                if (schSendAuxRecordKeyValue == 0)
                {
                    disableSendAuxRecord = true;
                    return;
                }

                schSendAuxRecordKeyValue = RegistryConfiguration.GlobalConfigReadInt(sendAuxRecordValueName, 1);
                if (schSendAuxRecordKeyValue == 0)
                {
                    disableSendAuxRecord = true;
                    return;
                }
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
            }
        }
Пример #3
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;
                }
            }
        }
        private static bool LoadDisableSendAuxRecordConfiguration(bool disable)
        {
            int schSendAuxRecordKeyValue;

            schSendAuxRecordKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalSendAuxRecordName, 1);
            if (schSendAuxRecordKeyValue == 0)
            {
                return(true);
            }

            schSendAuxRecordKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalSendAuxRecordName, 1);
            if (schSendAuxRecordKeyValue == 0)
            {
                return(true);
            }

            return(disable);
        }
        private static bool LoadReusePortConfiguration(bool reusePortInternal)
        {
            int reusePortKeyValue = 0;

            reusePortKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalReusePortName, 0);

            if (reusePortKeyValue == 1)
            {
                if (Logging.On)
                {
                    Logging.PrintInfo(Logging.Web, typeof(ServicePointManager), SR.GetString(SR.net_log_set_socketoption_reuseport_default_on));
                }

                reusePortInternal = true;
            }

            return(reusePortInternal);
        }
        private static bool LoadUseHttpPipeliningAndBufferPoolingConfiguration(bool useFeature)
        {
            int useHttpPipeliningAndBufferPoolingKeyValue;

            useHttpPipeliningAndBufferPoolingKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalUseHttpPipeliningAndBufferPooling, 1);
            if (useHttpPipeliningAndBufferPoolingKeyValue == 0)
            {
                return(false);
            }

            useHttpPipeliningAndBufferPoolingKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalUseHttpPipeliningAndBufferPooling, 1);
            if (useHttpPipeliningAndBufferPoolingKeyValue == 0)
            {
                return(false);
            }

            return(useFeature);
        }
Пример #7
0
        private static bool LoadUseStrictIPv6AddressParsingConfiguration(bool useFeature)
        {
            int useStrictIPv6AddressParsingKeyValue;

            useStrictIPv6AddressParsingKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalUseStrictIPv6AddressParsing, 1);
            if (useStrictIPv6AddressParsingKeyValue == 0)
            {
                return(false);
            }

            useStrictIPv6AddressParsingKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalUseStrictIPv6AddressParsing, 1);
            if (useStrictIPv6AddressParsingKeyValue == 0)
            {
                return(false);
            }

            return(useFeature);
        }
        private static bool LoadAllowDangerousUnicodeDecompositionsConfiguration(bool useFeature)
        {
            int allowDangerousUnicodeDecompositionsKeyValue;

            allowDangerousUnicodeDecompositionsKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalAllowDangerousUnicodeDecompositions, 0);
            if (allowDangerousUnicodeDecompositionsKeyValue == 1)
            {
                return(true);
            }

            allowDangerousUnicodeDecompositionsKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalAllowDangerousUnicodeDecompositions, 0);
            if (allowDangerousUnicodeDecompositionsKeyValue == 1)
            {
                return(true);
            }

            return(useFeature);
        }
        private static bool LoadUseStrictRfcInterimResponseHandlingConfiguration(bool useFeature)
        {
            int useStrictRfcInterimResponseHandlingKeyValue;

            useStrictRfcInterimResponseHandlingKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalUseStrictRfcInterimResponseHandling, 1);
            if (useStrictRfcInterimResponseHandlingKeyValue == 0)
            {
                return(false);
            }

            useStrictRfcInterimResponseHandlingKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalUseStrictRfcInterimResponseHandling, 1);
            if (useStrictRfcInterimResponseHandlingKeyValue == 0)
            {
                return(false);
            }

            return(useFeature);
        }
        private static bool LoadUseSafeSynchronousClose(bool useFeature)
        {
            int useSynchronousCloseValue;

            useSynchronousCloseValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalUseSafeSynchronousClose, 1);
            if (useSynchronousCloseValue == 0)
            {
                return(false);
            }

            useSynchronousCloseValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalUseSafeSynchronousClose, 1);
            if (useSynchronousCloseValue == 0)
            {
                return(false);
            }

            return(useFeature);
        }
Пример #11
0
        private static bool LoadAllowAllUriEncodingExpansionConfiguration(bool useFeature)
        {
            int allowAllUriEncodingExpansionKeyValue;

            allowAllUriEncodingExpansionKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalAllowAllUriEncodingExpansion, 0);
            if (allowAllUriEncodingExpansionKeyValue == 1)
            {
                return(true);
            }

            allowAllUriEncodingExpansionKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalAllowAllUriEncodingExpansion, 0);
            if (allowAllUriEncodingExpansionKeyValue == 1)
            {
                return(true);
            }

            return(useFeature);
        }
        private static bool LoadDisableStrongCryptoConfiguration(bool disable)
        {
            int schUseStrongCryptoKeyValue = 0;

            if (LocalAppContextSwitches.DontEnableSchUseStrongCrypto)
            {
                // .Net 4.5.2 and below will disable SchStrongCrypto unless the registry key is specifically set to 1.
                schUseStrongCryptoKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalStrongCryptoName, 0);
                disable = schUseStrongCryptoKeyValue != 1;
            }
            else
            {
                // .Net 4.6 and above will enable SchStrongCrypto unless the registry key is specifically set to 0.
                schUseStrongCryptoKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalStrongCryptoName, 1);
                disable = schUseStrongCryptoKeyValue == 0;
            }

            return(disable);
        }
Пример #13
0
        private static int?ReadPrefixLookupMaxEntriesConfig()
        {
            int?maxPrefixLookupEntries = null;

            int configuredMaxPrefixLookupEntries =
                RegistryConfiguration.GlobalConfigReadInt(configPrefixLookupMaxCount, -1);

            if (configuredMaxPrefixLookupEntries > 0)
            {
                maxPrefixLookupEntries = configuredMaxPrefixLookupEntries;
            }

            // Per-process setting will override global configuration.
            configuredMaxPrefixLookupEntries =
                RegistryConfiguration.AppConfigReadInt(configPrefixLookupMaxCount, -1);

            if (configuredMaxPrefixLookupEntries > 0)
            {
                maxPrefixLookupEntries = configuredMaxPrefixLookupEntries;
            }
            return(maxPrefixLookupEntries);
        }
Пример #14
0
        private static IAuthenticationManager SelectAuthenticationManagerInstance()
        {
            bool highPerformance = false;

            try
            {
                if (RegistryConfiguration.GlobalConfigReadInt(configHighPerformance, 0) == 1)
                {
                    highPerformance = true;
                }
                else if (RegistryConfiguration.AppConfigReadInt(configHighPerformance, 0) == 1)
                {
                    highPerformance = true;
                }

                if (highPerformance)
                {
                    int?maxPrefixLookupEntries = ReadPrefixLookupMaxEntriesConfig();
                    if ((maxPrefixLookupEntries != null) && (maxPrefixLookupEntries > 0))
                    {
                        return(new AuthenticationManager2((int)maxPrefixLookupEntries));
                    }
                    else
                    {
                        return(new AuthenticationManager2());
                    }
                }
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
            }

            return(new AuthenticationManagerDefault());
        }
Пример #15
0
        private static void EnsureReusePortSettingsInitialized()
        {
            if (reusePortSettingsInitialized)
            {
                return;
            }

            lock (reusePortLock) {
                if (reusePortSettingsInitialized)
                {
                    return;
                }

                int reusePortKeyValue = 0;
                try {
                    reusePortKeyValue = RegistryConfiguration.GlobalConfigReadInt(reusePortValueName, 0);
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                }

                bool reusePortInternal = false;
                if (reusePortKeyValue == 1)
                {
                    if (Logging.On)
                    {
                        Logging.PrintInfo(Logging.Web, typeof(ServicePointManager), SR.GetString(SR.net_log_set_socketoption_reuseport_default_on));
                    }
                    reusePortInternal = true;
                }

                reusePort = reusePortInternal;
                reusePortSettingsInitialized = true;
            }
        }
        private static bool LoadDisableSystemDefaultTlsVersionsConfiguration(bool disable)
        {
            if (LocalAppContextSwitches.DontEnableSystemDefaultTlsVersions)
            {
                // .Net 4.6.2 and below will disable SystemDefaultTls unless the registry key is specifically set to 1.
                int globalOverride = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalSystemDefaultTlsVersionsName, 0);
                disable = globalOverride != 1;
            }
            else
            {
                // .Net 4.6.3 and above will enable SystemDefaultTls unless the registry key is specifically set to 0.
                int globalOverride = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalSystemDefaultTlsVersionsName, 1);
                disable = globalOverride == 0;
            }

            if (!disable)
            {
                int appLocalOverride = RegistryConfiguration.AppConfigReadInt(RegistryLocalSystemDefaultTlsVersionsName, 1);
                disable = appLocalOverride != 1;
            }

            return(disable);
        }
        private static bool LoadDisableCertificateEKUsConfiguration(bool disable)
        {
            int requireCertificateEKUsKeyValue;

            if (LocalAppContextSwitches.DontCheckCertificateEKUs)
            {
                return(true);
            }

            requireCertificateEKUsKeyValue = RegistryConfiguration.AppConfigReadInt(RegistryLocalRequireCertificateEKUs, 1);
            if (requireCertificateEKUsKeyValue == 0)
            {
                return(true);
            }

            requireCertificateEKUsKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalRequireCertificateEKUs, 1);
            if (requireCertificateEKUsKeyValue == 0)
            {
                return(true);
            }

            return(disable);
        }