protected override async Task <(Stream, SecurityMessageProperty)> OnAcceptUpgradeAsync(Stream stream) { var sslStream = new SslStream(stream, false, ValidateRemoteCertificate); try { await sslStream.AuthenticateAsServerAsync(_parent.ServerCertificate, _parent.RequireClientCertificate, _parent.SslProtocols, false); } catch (AuthenticationException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(exception.Message, exception)); } catch (IOException ioException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException( SR.Format(SR.NegotiationFailedIO, ioException.Message), ioException)); } SecurityMessageProperty remoteSecurity = _clientSecurity; if (IsChannelBindingSupportEnabled) { _channelBindingToken = ChannelBindingUtility.GetToken(sslStream); } return(sslStream, remoteSecurity); }