Ejemplo n.º 1
0
        public TlsServerConnectionMiddleware(ConnectionDelegate next, TlsOptions options, ILoggerFactory loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next = next;

            // capture the certificate now so it can't be switched after validation
            _certificate         = options.LocalCertificate;
            _certificateSelector = options.LocalServerCertificateSelector;
            if (_certificate == null && _certificateSelector == null)
            {
                throw new ArgumentException("Server certificate is required", nameof(options));
            }

            // If a selector is provided then ignore the cert, it may be a default cert.
            if (_certificateSelector != null)
            {
                // SslStream doesn't allow both.
                _certificate = null;
            }
            else
            {
                EnsureCertificateIsAllowedForServerAuth(_certificate);
            }

            _options = options;
            _logger  = loggerFactory?.CreateLogger <TlsServerConnectionMiddleware>();
        }
        public TlsClientConnectionMiddleware(ConnectionDelegate next, TlsOptions options, ILoggerFactory loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next = next;

            // capture the certificate now so it can't be switched after validation
            _certificate = options.LocalCertificate;

            if (_certificate != null)
            {
                EnsureCertificateIsAllowedForClientAuth(_certificate);
            }

            _options = options;
            _logger  = loggerFactory?.CreateLogger <TlsServerConnectionMiddleware>();
        }