/// <summary> /// Upgrade a Tcp stream to an Ssl stream using the SSL options provided. /// </summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { var helper = new SslHelper(sslOption); var remoteCertValidator = sslOption.CertificateValidationCallback ?? helper.CertificateValidationCallback; var localCertSelector = sslOption.CertificateSelectionCallback ?? helper.CertificateSelectionCallback; var sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClientAsync(sslOption.ServerName, sslOption.Certs, sslOption.Version, false).GetAwaiter().GetResult(); return(sslStream); }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { SslHelper helper = new SslHelper(sslOption); SslStream sslStream = new SslStream(tcpStream, false, new RemoteCertificateValidationCallback(helper.CertificateValidationCallback), new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback)); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { SslHelper helper = new SslHelper(sslOption); SslStream sslStream = new SslStream(tcpStream, false, new RemoteCertificateValidationCallback(helper.CertificateValidationCallback), new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback)); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return(sslStream); }
/// <summary> /// Upgrade a Tcp stream to an Ssl stream using the SSL options provided. /// </summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { var helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? helper.CertificateValidationCallback; LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? helper.CertificateSelectionCallback; var sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
/// <summary> /// Upgrade a Tcp stream to an Ssl stream using the SSL options provided. /// </summary> public static async Task <Stream> TcpUpgrade(Stream tcpStream, SslOption sslOption) { var helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? helper.CertificateValidationCallback; LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? helper.CertificateSelectionCallback; var sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); await sslStream.AuthenticateAsClientAsync(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return(sslStream); }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { SslHelper helper = new SslHelper(sslOption); // Use the client specified remote certificate validation callback if it is not null RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? new RemoteCertificateValidationCallback( helper.CertificateValidationCallback); // Use the client specified local certificate selector callback if it is not null LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? new LocalCertificateSelectionCallback( helper.CertificateSelectionCallback); SslStream sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption, int timeout) { SslHelper helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? new RemoteCertificateValidationCallback(helper.CertificateValidationCallback); LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback); SslStream sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); sslStream.ReadTimeout = timeout; sslStream.WriteTimeout = timeout; return sslStream; }
/// <summary> /// Upgrade a Tcp stream to an Ssl stream using the SSL options provided. /// </summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { var helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? helper.CertificateValidationCallback; LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? helper.CertificateSelectionCallback; var sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); if (sslOption.Certs == null || sslOption.Certs.Count == 0) { sslStream.AuthenticateAsClient(sslOption.ServerName); } else { sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); } return(sslStream); }