private static void StartServer() { AsyncSocketAcceptor acceptor = new AsyncSocketAcceptor(); DefaultIoFilterChainBuilder filters = acceptor.FilterChain; // Inject the SSL filter SslFilter sslFilter = new SslFilter(AppDomain.CurrentDomain.BaseDirectory + "\\TempCert.cer"); filters.AddLast("sslFilter", sslFilter); // Inject the TestLine codec filter filters.AddLast("text", new ProtocolCodecFilter(new TextLineCodecFactory())); acceptor.MessageReceived += (s, e) => { String line = (String)e.Message; if (line.StartsWith("hello")) { Debug.WriteLine("Server got: 'hello', waiting for 'send'"); Thread.Sleep(1500); } else if (line.StartsWith("send")) { Debug.WriteLine("Server got: 'send', sending 'data'"); e.Session.Write("data"); } }; acceptor.Bind(new IPEndPoint(IPAddress.Any, port)); }
private void AuthenticateCallback(IAsyncResult ar) { try { _sslStream.EndAuthenticateAsServer(ar); } catch (AuthenticationException e) { _sslFilter.ExceptionCaught(_currentNextFilter, _session, e); return; } catch (IOException e) { _sslFilter.ExceptionCaught(_currentNextFilter, _session, e); return; } Authenticated = true; if (log.IsDebugEnabled) { // Display the properties and settings for the authenticated stream. SslFilter.DisplaySecurityLevel(_sslStream); SslFilter.DisplaySecurityServices(_sslStream); SslFilter.DisplayCertificateInformation(_sslStream); SslFilter.DisplayStreamProperties(_sslStream); } }
public SslHandler(SslFilter sslFilter, IoSession session) { _sslFilter = sslFilter; _session = session; _sessionStream = new IoSessionStream(this); _sslStream = new SslStream(_sessionStream, false); }