Beispiel #1
0
        private void ReadEndpoints()
        {
            _endpoints = new List <EndpointConfig>();

            var endpointsConfig = _configuration.GetSection(EndpointsKey).GetChildren();

            foreach (var endpointConfig in endpointsConfig)
            {
                // "EndpointName": {
                //    "Url": "https://*:5463",
                //    "Protocols": "Http1AndHttp2",
                //    "Certificate": {
                //        "Path": "testCert.pfx",
                //        "Password": "******"
                //    }
                // }

                var url = endpointConfig[UrlKey];
                if (string.IsNullOrEmpty(url))
                {
                    throw new InvalidOperationException(CoreStrings.FormatEndpointMissingUrl(endpointConfig.Key));
                }

                var endpoint = new EndpointConfig
                {
                    Name          = endpointConfig.Key,
                    Url           = url,
                    Protocols     = ParseProtocols(endpointConfig[ProtocolsKey]),
                    ConfigSection = endpointConfig,
                    Certificate   = new CertificateConfig(endpointConfig.GetSection(CertificateKey)),
                };
                _endpoints.Add(endpoint);
            }
        }
Beispiel #2
0
        private void ReadEndpoints()
        {
            _endpoints = new List <EndpointConfig>();

            var endpointsConfig = _configuration.GetSection("Endpoints").GetChildren();

            foreach (var endpointConfig in endpointsConfig)
            {
                // "EndpointName": {
                          //    "Url": "https://*:5463",
                          //    "Certificate": {
                          //        "Path": "testCert.pfx",
                          //        "Password": "******"
                          //    }
                       // }

                var url = endpointConfig["Url"];
                if (string.IsNullOrEmpty(url))
                {
                    throw new InvalidOperationException(CoreStrings.FormatEndpointMissingUrl(endpointConfig.Key));
                }

                var endpoint = new EndpointConfig()
                {
                    Name          = endpointConfig.Key,
                    Url           = url,
                    ConfigSection = endpointConfig,
                    Certificate   = new CertificateConfig(endpointConfig.GetSection("Certificate")),
                };
                _endpoints.Add(endpoint);
            }
        }
        private IEnumerable <EndpointConfig> ReadEndpoints()
        {
            var endpoints = new List <EndpointConfig>();

            var endpointsConfig = _configuration.GetSection(EndpointsKey).GetChildren();

            foreach (var endpointConfig in endpointsConfig)
            {
                // "EndpointName": {
                //     "Url": "https://*:5463",
                //     "Protocols": "Http1AndHttp2",
                //     "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
                //     "Certificate": {
                //         "Path": "testCert.pfx",
                //         "Password": "******"
                //     },
                //     "ClientCertificateMode" : "NoCertificate",
                //     "Sni": {
                //         "a.example.org": {
                //             "Certificate": {
                //                 "Path": "testCertA.pfx",
                //                 "Password": "******"
                //             }
                //         },
                //         "*.example.org": {
                //             "Protocols": "Http1",
                //         }
                //     }
                // }

                var url = endpointConfig[UrlKey];
                if (string.IsNullOrEmpty(url))
                {
                    throw new InvalidOperationException(CoreStrings.FormatEndpointMissingUrl(endpointConfig.Key));
                }

                var endpoint = new EndpointConfig(
                    endpointConfig.Key,
                    url,
                    ReadSni(endpointConfig.GetSection(SniKey), endpointConfig.Key),
                    endpointConfig)
                {
                    Protocols             = ParseProtocols(endpointConfig[ProtocolsKey]),
                    SslProtocols          = ParseSslProcotols(endpointConfig.GetSection(SslProtocolsKey)),
                    ClientCertificateMode = ParseClientCertificateMode(endpointConfig[ClientCertificateModeKey]),
                    Certificate           = new CertificateConfig(endpointConfig.GetSection(CertificateKey))
                };

                endpoints.Add(endpoint);
            }

            return(endpoints);
        }
        internal static void ThrowIfContainsHttpsOnlyConfiguration(EndpointConfig endpoint)
        {
            if (endpoint.Certificate != null && (endpoint.Certificate.IsFileCert || endpoint.Certificate.IsStoreCert))
            {
                throw new InvalidOperationException(CoreStrings.FormatEndpointHasUnusedHttpsConfig(endpoint.Name, CertificateKey));
            }

            if (endpoint.ClientCertificateMode.HasValue)
            {
                throw new InvalidOperationException(CoreStrings.FormatEndpointHasUnusedHttpsConfig(endpoint.Name, ClientCertificateModeKey));
            }

            if (endpoint.SslProtocols.HasValue)
            {
                throw new InvalidOperationException(CoreStrings.FormatEndpointHasUnusedHttpsConfig(endpoint.Name, SslProtocolsKey));
            }

            if (endpoint.Sni.Count > 0)
            {
                throw new InvalidOperationException(CoreStrings.FormatEndpointHasUnusedHttpsConfig(endpoint.Name, SniKey));
            }
        }