Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 public SslHandler(SslFilter sslFilter, IoSession session)
 {
     _sslFilter     = sslFilter;
     _session       = session;
     _sessionStream = new IoSessionStream(this);
     _sslStream     = new SslStream(_sessionStream, false);
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 public SslHandler(SslFilter sslFilter, IoSession session)
 {
     _sslFilter = sslFilter;
     _session = session;
     _sessionStream = new IoSessionStream(this);
     _sslStream = new SslStream(_sessionStream, false);
 }