Class SSLIOSession

    • Field Detail

      • EMPTY_BUFFER

        private static final java.nio.ByteBuffer EMPTY_BUFFER
      • sslEngine

        private final javax.net.ssl.SSLEngine sslEngine
      • handshakeCallbackRef

        private final java.util.concurrent.atomic.AtomicReference<FutureCallback<javax.net.ssl.SSLSession>> handshakeCallbackRef
      • handshakeTimeout

        private final Timeout handshakeTimeout
      • sslMode

        private final SSLMode sslMode
      • outboundClosedCount

        private final java.util.concurrent.atomic.AtomicInteger outboundClosedCount
      • internalEventHandler

        private final IOEventHandler internalEventHandler
      • appEventMask

        private int appEventMask
      • endOfStream

        private volatile boolean endOfStream
      • socketTimeout

        private volatile Timeout socketTimeout
      • tlsDetails

        private volatile TlsDetails tlsDetails
    • Constructor Detail

      • SSLIOSession

        public SSLIOSession​(NamedEndpoint targetEndpoint,
                            IOSession session,
                            SSLMode sslMode,
                            javax.net.ssl.SSLContext sslContext,
                            SSLBufferMode sslBufferMode,
                            SSLSessionInitializer initializer,
                            SSLSessionVerifier verifier,
                            Callback<SSLIOSession> sessionStartCallback,
                            Callback<SSLIOSession> sessionEndCallback,
                            Timeout connectTimeout)
        Creates new instance of SSLIOSession class.
        Parameters:
        session - I/O session to be decorated with the TLS/SSL capabilities.
        sslMode - SSL mode (client or server)
        targetEndpoint - target endpoint (applicable in client mode only). May be null.
        sslContext - SSL context to use for this I/O session.
        sslBufferMode - buffer management mode
        initializer - optional SSL session initializer. May be null.
        verifier - optional SSL session verifier. May be null.
        connectTimeout - timeout to apply for the TLS/SSL handshake. May be null.
        Since:
        5.0
      • SSLIOSession

        public SSLIOSession​(NamedEndpoint targetEndpoint,
                            IOSession session,
                            SSLMode sslMode,
                            javax.net.ssl.SSLContext sslContext,
                            SSLBufferMode sslBufferMode,
                            SSLSessionInitializer initializer,
                            SSLSessionVerifier verifier,
                            Timeout handshakeTimeout,
                            Callback<SSLIOSession> sessionStartCallback,
                            Callback<SSLIOSession> sessionEndCallback,
                            FutureCallback<javax.net.ssl.SSLSession> resultCallback)
        Creates new instance of SSLIOSession class.
        Parameters:
        session - I/O session to be decorated with the TLS/SSL capabilities.
        sslMode - SSL mode (client or server)
        targetEndpoint - target endpoint (applicable in client mode only). May be null.
        sslContext - SSL context to use for this I/O session.
        sslBufferMode - buffer management mode
        initializer - optional SSL session initializer. May be null.
        verifier - optional SSL session verifier. May be null.
        handshakeTimeout - timeout to apply for the TLS/SSL handshake. May be null.
        resultCallback - result callback. May be null.
        Since:
        5.2
    • Method Detail

      • beginHandshake

        public void beginHandshake​(IOSession protocolSession)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • initialize

        private void initialize​(IOSession protocolSession)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • convert

        private javax.net.ssl.SSLException convert​(java.lang.RuntimeException ex)
      • doWrap

        private javax.net.ssl.SSLEngineResult doWrap​(java.nio.ByteBuffer src,
                                                     java.nio.ByteBuffer dst)
                                              throws javax.net.ssl.SSLException
        Throws:
        javax.net.ssl.SSLException
      • doUnwrap

        private javax.net.ssl.SSLEngineResult doUnwrap​(java.nio.ByteBuffer src,
                                                       java.nio.ByteBuffer dst)
                                                throws javax.net.ssl.SSLException
        Throws:
        javax.net.ssl.SSLException
      • doRunTask

        private void doRunTask()
      • doHandshake

        private void doHandshake​(IOSession protocolSession)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • updateEventMask

        private void updateEventMask()
      • sendEncryptedData

        private int sendEncryptedData()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • receiveEncryptedData

        private int receiveEncryptedData()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • decryptData

        private void decryptData​(IOSession protocolSession)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • encryptData

        private void encryptData​(IOSession protocolSession)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface Identifiable
      • getLock

        public java.util.concurrent.locks.Lock getLock()
        Description copied from interface: IOSession
        Returns session lock that should be used by I/O event handlers to synchronize access to the session.
        Specified by:
        getLock in interface IOSession
      • upgrade

        public void upgrade​(IOEventHandler handler)
        Description copied from interface: IOSession
        Upgrades event handler associated with the session.
        Specified by:
        upgrade in interface IOSession
      • getTlsDetails

        public TlsDetails getTlsDetails()
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
        Description copied from interface: IOSession
        Terminates the session gracefully and closes the underlying I/O channel. This method ensures that session termination handshake, such as the one used by the SSL/TLS protocol, is correctly carried out.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface IOSession
      • close

        public void close​(CloseMode closeMode)
        Description copied from interface: ModalCloseable
        Closes this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.
        Specified by:
        close in interface ModalCloseable
        Parameters:
        closeMode - How to close the receiver.
      • hasCommands

        public boolean hasCommands()
        Description copied from interface: IOSession
        Tests if there enqueued commands pending execution.
        Specified by:
        hasCommands in interface IOSession
      • channel

        public java.nio.channels.ByteChannel channel()
        Description copied from interface: IOSession
        Returns the underlying I/O channel associated with this session.
        Specified by:
        channel in interface IOSession
        Returns:
        the I/O channel.
      • getLocalAddress

        public java.net.SocketAddress getLocalAddress()
        Description copied from interface: IOSession
        Returns local address.
        Specified by:
        getLocalAddress in interface IOSession
        Returns:
        socket address.
      • getRemoteAddress

        public java.net.SocketAddress getRemoteAddress()
        Description copied from interface: IOSession
        Returns address of the remote peer.
        Specified by:
        getRemoteAddress in interface IOSession
        Returns:
        socket address.
      • getEventMask

        public int getEventMask()
        Description copied from interface: IOSession
        Returns mask of I/O evens this session declared interest in.
        Specified by:
        getEventMask in interface IOSession
        Returns:
        I/O event mask.
      • setEventMask

        public void setEventMask​(int ops)
        Description copied from interface: IOSession
        Declares interest in I/O event notifications by setting the event mask associated with the session
        Specified by:
        setEventMask in interface IOSession
        Parameters:
        ops - new I/O event mask.
      • setEvent

        public void setEvent​(int op)
        Description copied from interface: IOSession
        Declares interest in a particular I/O event type by updating the event mask associated with the session.
        Specified by:
        setEvent in interface IOSession
        Parameters:
        op - I/O event type.
      • clearEvent

        public void clearEvent​(int op)
        Description copied from interface: IOSession
        Clears interest in a particular I/O event type by updating the event mask associated with the session.
        Specified by:
        clearEvent in interface IOSession
        Parameters:
        op - I/O event type.
      • updateReadTime

        public void updateReadTime()
        Description copied from interface: IOSession
        Updates the timestamp of the last read event
        Specified by:
        updateReadTime in interface IOSession
      • updateWriteTime

        public void updateWriteTime()
        Description copied from interface: IOSession
        Updates the timestamp of the last write event
        Specified by:
        updateWriteTime in interface IOSession
      • getLastReadTime

        public long getLastReadTime()
        Description copied from interface: IOSession
        Returns timestamp of the last read event.
        Specified by:
        getLastReadTime in interface IOSession
        Returns:
        timestamp.
      • getLastWriteTime

        public long getLastWriteTime()
        Description copied from interface: IOSession
        Returns timestamp of the last write event.
        Specified by:
        getLastWriteTime in interface IOSession
        Returns:
        timestamp.
      • formatOps

        private static void formatOps​(java.lang.StringBuilder buffer,
                                      int ops)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object