public override void Connect() { //Connect raw tcp socket base.Connect(); X509Certificate2Collection certCollection = new X509Certificate2Collection(_certificate); _sslStream = new SslClientStream( new NetworkStream(_socket, true), _overwriteAuthenticationTargetHost != null?_overwriteAuthenticationTargetHost:_remoteHost, true, SecurityProtocolType.Tls, certCollection); ((SslClientStream)_sslStream).CheckCertRevocationStatus = true; ((SslClientStream)_sslStream).PrivateKeyCertSelectionDelegate += delegate(X509Certificate cert, string targetHost) { X509Certificate2 cert2 = _certificate as X509Certificate2 ?? new X509Certificate2(_certificate); return(cert2 != null ? cert2.PrivateKey : null); }; ((SslClientStream)_sslStream).ClientCertSelectionDelegate += SelectLocalCertificate; ((SslClientStream)_sslStream).ServerCertValidationDelegate += ValidateRemoteCertificate; _sslStream.Write(new byte[0], 0, 0); }
public override void Write(byte[] buffer, int offset, int count) { CheckConnectionAuthenticated(); ssl_stream.Write(buffer, offset, count); //EndWrite (BeginWrite (buffer, offset, count, null, null)); }
public override void Write(byte[] buffer, int offset, int length) { try { _sslStream.Write(buffer, offset, length); } catch (Exception e) { _logger.Fatal(e); _logger.Fatal("Closing connection"); RaiseDisconnectedEvent(); throw new DisconnectedException(); } }