Class SslHandler

java.lang.Object
org.apache.mina.filter.ssl.SslHandler

class SslHandler extends Object
No qualifier
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      A logger for this class
    • sslFilter

      private final SslFilter sslFilter
      The SSL Filter which has created this handler
    • session

      private final IoSession session
      The current session
    • preHandshakeEventQueue

      private final Queue<IoFilterEvent> preHandshakeEventQueue
    • filterWriteEventQueue

      private final Queue<IoFilterEvent> filterWriteEventQueue
    • messageReceivedEventQueue

      private final Queue<IoFilterEvent> messageReceivedEventQueue
      A queue used to stack all the incoming data until the SSL session is established
    • sslEngine

      private SSLEngine sslEngine
    • inNetBuffer

      private IoBuffer inNetBuffer
      Encrypted data from the net
    • outNetBuffer

      private IoBuffer outNetBuffer
      Encrypted data to be written to the net
    • appBuffer

      private IoBuffer appBuffer
      Application cleartext data to be read by application
    • emptyBuffer

      private final IoBuffer emptyBuffer
      Empty buffer used during initial handshake and close operations
    • handshakeStatus

      private SSLEngineResult.HandshakeStatus handshakeStatus
    • firstSSLNegociation

      private boolean firstSSLNegociation
      A flag set to true when the first SSL handshake has been completed This is used to avoid sending a notification to the application handler when we switch to a SECURE or UNSECURE session.
    • handshakeComplete

      private boolean handshakeComplete
      A flag set to true when a SSL Handshake has been completed
    • writingEncryptedData

      private boolean writingEncryptedData
      A flag used to indicate to the SslFilter that the buffer it will write is already encrypted (this will be the case for data being produced during the handshake).
  • Constructor Details

    • SslHandler

      SslHandler(SslFilter sslFilter, IoSession session)
      Create a new SSL Handler, and initialize it.
      Parameters:
      sslContext -
      Throws:
      SSLException
  • Method Details

    • init

      void init() throws SSLException
      Initialize the SSL handshake.
      Throws:
      SSLException - If the underlying SSLEngine handshake initialization failed
    • destroy

      void destroy()
      Release allocated buffers.
    • getSslFilter

      SslFilter getSslFilter()
      Returns:
      The SSL filter which has created this handler
    • getSession

      IoSession getSession()
    • isWritingEncryptedData

      boolean isWritingEncryptedData()
      Check if we are writing encrypted data.
    • isHandshakeComplete

      boolean isHandshakeComplete()
      Check if handshake is completed.
    • notHandshaking

      boolean notHandshaking()
      Check if handshake is on going.
    • isInboundDone

      boolean isInboundDone()
    • isOutboundDone

      boolean isOutboundDone()
    • needToCompleteHandshake

      boolean needToCompleteHandshake()
      Check if there is any need to complete handshake.
    • schedulePreHandshakeWriteRequest

      void schedulePreHandshakeWriteRequest(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
    • flushPreHandshakeEvents

      void flushPreHandshakeEvents() throws SSLException
      Throws:
      SSLException
    • scheduleFilterWrite

      void scheduleFilterWrite(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
    • flushFilterWrite

      void flushFilterWrite()
    • scheduleMessageReceived

      void scheduleMessageReceived(IoFilter.NextFilter nextFilter, Object message)
      Push the newly received data into a queue, waiting for the SSL session to be fully established
      Parameters:
      nextFilter - The next filter to call
      message - The incoming data
    • flushMessageReceived

      void flushMessageReceived()
    • messageReceived

      void messageReceived(IoFilter.NextFilter nextFilter, ByteBuffer buf) throws SSLException
      Call when data are read from net. It will perform the initial hanshake or decrypt the data if SSL has been initialiaed.
      Parameters:
      nextFilter - Next filter in chain
      buf - buffer to decrypt
      Throws:
      SSLException - on errors
    • fetchAppBuffer

      IoBuffer fetchAppBuffer()
      Get decrypted application data.
      Returns:
      buffer with data
    • fetchOutNetBuffer

      IoBuffer fetchOutNetBuffer()
      Get encrypted data to be sent.
      Returns:
      buffer with data
    • encrypt

      void encrypt(ByteBuffer src) throws SSLException
      Encrypt provided buffer. Encrypted data returned by getOutNetBuffer().
      Parameters:
      src - data to encrypt
      Throws:
      SSLException - on errors
    • closeOutbound

      boolean closeOutbound() throws SSLException
      Start SSL shutdown process.
      Returns:
      true if shutdown process is started. false if shutdown process is already finished.
      Throws:
      SSLException - on errors
    • checkStatus

      private void checkStatus(SSLEngineResult res) throws SSLException
      Parameters:
      res -
      Throws:
      SSLException
    • handshake

      void handshake(IoFilter.NextFilter nextFilter) throws SSLException
      Perform any handshaking processing.
      Throws:
      SSLException
    • createOutNetBuffer

      private void createOutNetBuffer(int expectedRemaining)
    • writeNetBuffer

      WriteFuture writeNetBuffer(IoFilter.NextFilter nextFilter) throws SSLException
      Throws:
      SSLException
    • unwrapHandshake

      private SSLEngineResult.Status unwrapHandshake(IoFilter.NextFilter nextFilter) throws SSLException
      Throws:
      SSLException
    • renegotiateIfNeeded

      private void renegotiateIfNeeded(IoFilter.NextFilter nextFilter, SSLEngineResult res) throws SSLException
      Throws:
      SSLException
    • unwrap

      private SSLEngineResult unwrap() throws SSLException
      Decrypt the incoming buffer and move the decrypted data to an application buffer.
      Throws:
      SSLException
    • doTasks

      Do all the outstanding handshake tasks in the current Thread.
    • copy

      static IoBuffer copy(ByteBuffer src)
      Creates a new MINA buffer that is a deep copy of the remaining bytes in the given buffer (between index buf.position() and buf.limit())
      Parameters:
      src - the buffer to copy
      Returns:
      the new buffer, ready to read from
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • release

      void release()
      Free the allocated buffers