private void OnAuthenticateAsServer(IAsyncResult result) { SslInfo sslInfo = null; try { sslInfo = result.AsyncState as SslInfo; sslInfo.SslStream.EndAuthenticateAsServer(result); this._ConnectionCallback(this, new SecureConnectionResults(sslInfo)); } catch (Exception ex) { if (sslInfo.SslStream != null) { sslInfo.SslStream.Dispose(); } this._ConnectionCallback(this, new SecureConnectionResults(ex)); } }
private void OnAcceptConnection(IAsyncResult result) { if (!this._Started) { return; } TcpListener listener = result.AsyncState as TcpListener; SslStream sslStream = null; try { listener.BeginAcceptTcpClient(this.OnAcceptConnection, listener); //complete the last operation... TcpClient tcpClient = listener.EndAcceptTcpClient(result); bool leaveStreamOpen = false; //close the socket when done TraderNetworkStream networkStream = new TraderNetworkStream(tcpClient.Client, BufferManager.Default.Dequeue()); if (this._CertValidationCallback != null) { sslStream = new SslStream(networkStream, leaveStreamOpen, this._CertValidationCallback); } else { sslStream = new SslStream(networkStream, leaveStreamOpen); } SslInfo sslInfo = new SslInfo(networkStream, sslStream, tcpClient.Client); sslStream.BeginAuthenticateAsServer(this._ServerCertificate, this._ClientCertificateRequired, this._SslProtocols, this._CheckCertifcateRevocation, //checkCertifcateRevocation this.OnAuthenticateAsServer, sslInfo); } catch (Exception ex) { _Logger.Error(ex); if (sslStream != null) { sslStream.Dispose(); sslStream = null; } this._ConnectionCallback(this, new SecureConnectionResults(ex)); } }
internal SecureConnectionResults(SslInfo sslInfo) { this.sslInfo = sslInfo; }
private void OnAcceptConnection(IAsyncResult result) { if (!this._Started) return; TcpListener listener = result.AsyncState as TcpListener; SslStream sslStream = null; try { listener.BeginAcceptTcpClient(this.OnAcceptConnection, listener); //complete the last operation... TcpClient tcpClient = listener.EndAcceptTcpClient(result); bool leaveStreamOpen = false; //close the socket when done TraderNetworkStream networkStream = new TraderNetworkStream(tcpClient.Client,BufferManager.Default.SetBuffer()); if (this._CertValidationCallback != null) { sslStream = new SslStream(networkStream, leaveStreamOpen, this._CertValidationCallback); } else { sslStream = new SslStream(networkStream, leaveStreamOpen); } SslInfo sslInfo = new SslInfo(networkStream, sslStream); sslStream.BeginAuthenticateAsServer(this._ServerCertificate, this._ClientCertificateRequired, this._SslProtocols, this._CheckCertifcateRevocation, //checkCertifcateRevocation this.OnAuthenticateAsServer, sslInfo); } catch (Exception ex) { _Logger.Error(ex); if (sslStream != null) { sslStream.Dispose(); sslStream = null; } this._ConnectionCallback(this, new SecureConnectionResults(ex)); } }