/// <inheritdoc/>
        public override void FilterClose(INextFilter nextFilter, IoSession session)
        {
            SslHandler handler = session.GetAttribute <SslHandler>(SSL_HANDLER);

            if (handler == null)
            {
                // The connection might already have closed, or
                // SSL might have not started yet.
                base.FilterClose(nextFilter, session);
                return;
            }

            IWriteFuture future = null;

            try
            {
                future           = InitiateClosure(handler, nextFilter, session);
                future.Complete += (s, e) => base.FilterClose(nextFilter, session);
            }
            finally
            {
                if (future == null)
                {
                    base.FilterClose(nextFilter, session);
                }
            }
        }
 public IoSessionStream(SslHandler sslHandler)
 {
     _sslHandler     = sslHandler;
     _buf            = IoBuffer.Allocate(16);
     _buf.AutoExpand = true;
     _buf.Limit      = 0;
 }
        private IWriteFuture InitiateClosure(SslHandler handler, INextFilter nextFilter, IoSession session)
        {
            IWriteFuture future = DefaultWriteFuture.NewWrittenFuture(session);

            handler.Destroy();
            return(future);
        }
        /// <inheritdoc/>
        public override void MessageReceived(INextFilter nextFilter, IoSession session, Object message)
        {
            IoBuffer   buf     = (IoBuffer)message;
            SslHandler handler = GetSslSessionHandler(session);

            // forward read encrypted data to SSL handler
            handler.MessageReceived(nextFilter, buf);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
        {
            if (parent.Contains<SslFilter>())
                throw new InvalidOperationException("Only one SSL filter is permitted in a chain.");

            IoSession session = parent.Session;
            session.SetAttribute(NEXT_FILTER, nextFilter);
            // Create a SSL handler and start handshake.
            SslHandler handler = new SslHandler(this, session);
            session.SetAttribute(SSL_HANDLER, handler);
        }
        /// <inheritdoc/>
        public override void SessionClosed(INextFilter nextFilter, IoSession session)
        {
            SslHandler handler = GetSslSessionHandler(session);

            try
            {
                // release resources
                handler.Destroy();
            }
            finally
            {
                // notify closed session
                base.SessionClosed(nextFilter, session);
            }
        }
        /// <inheritdoc/>
        public override void OnPreAdd(IoFilterChain parent, String name, INextFilter nextFilter)
        {
            if (parent.Contains <SslFilter>())
            {
                throw new InvalidOperationException("Only one SSL filter is permitted in a chain.");
            }

            IoSession session = parent.Session;

            session.SetAttribute(NEXT_FILTER, nextFilter);
            // Create a SSL handler and start handshake.
            SslHandler handler = new SslHandler(this, session);

            session.SetAttribute(SSL_HANDLER, handler);
        }
        private SslHandler GetSslSessionHandler(IoSession session)
        {
            SslHandler handler = session.GetAttribute <SslHandler>(SSL_HANDLER);

            if (handler == null)
            {
                throw new InvalidOperationException();
            }

            if (handler.SslFilter != this)
            {
                throw new ArgumentException("Not managed by this filter.");
            }

            return(handler);
        }
        /// <inheritdoc/>
        public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            SslHandler handler = GetSslSessionHandler(session);

            handler.ScheduleFilterWrite(nextFilter, writeRequest);
        }
Beispiel #10
0
        /// <inheritdoc/>
        public override void OnPostAdd(IoFilterChain parent, String name, INextFilter nextFilter)
        {
            SslHandler handler = GetSslSessionHandler(parent.Session);

            handler.Handshake(nextFilter);
        }
Beispiel #11
0
        /// <summary>
        /// Returns <code>true</code> if and only if the specified session is
        /// encrypted/decrypted over SSL/TLS currently.
        /// </summary>
        public Boolean IsSslStarted(IoSession session)
        {
            SslHandler handler = session.GetAttribute <SslHandler>(SSL_HANDLER);

            return(handler != null && handler.Authenticated);
        }
Beispiel #12
0
 public IoSessionStream(SslHandler sslHandler)
 {
     _sslHandler = sslHandler;
     _buf = IoBuffer.Allocate(16);
     _buf.AutoExpand = true;
     _buf.Limit = 0;
 }
Beispiel #13
0
 private IWriteFuture InitiateClosure(SslHandler handler, INextFilter nextFilter, IoSession session)
 {
     IWriteFuture future = DefaultWriteFuture.NewWrittenFuture(session);
     handler.Destroy();
     return future;
 }