private async Task <IAdaptedConnection> InnerOnConnectionAsync(ConnectionAdapterContext context)
        {
            var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.Password, _serverProtocols);

            try
            {
                await tlsStream.DoHandshakeAsync();

                _applicationProtocol = tlsStream.GetNegotiatedApplicationProtocol();
            }
            catch (IOException ex)
            {
                _logger?.LogInformation(1, ex, "Authentication failed.");
                tlsStream.Dispose();
                return(_closedAdaptedConnection);
            }

            // Always set the feature even though the cert might be null
            context.Features.Set <ITlsConnectionFeature>(new TlsConnectionFeature());
            context.Features.Set <ITlsApplicationProtocolFeature>(new TlsApplicationProtocolFeature(_applicationProtocol));

            return(new TlsAdaptedConnection(tlsStream));
        }
 public TlsAdaptedConnection(TlsStream tlsStream)
 {
     _tlsStream = tlsStream;
 }