Class SslHandler

java.lang.Object
org.apache.mina.filter.ssl.SslHandler
Direct Known Subclasses:
SSLHandlerG0, SSLHandlerG1

public abstract class SslHandler extends Object
Default interface for SSL exposed to the SslFilter
  • Field Details

    • MIN_ENCODER_BUFFER_PACKETS

      protected static final int MIN_ENCODER_BUFFER_PACKETS
      Minimum size of encoder buffer in packets
      See Also:
    • MAX_ENCODER_BUFFER_PACKETS

      protected static final int MAX_ENCODER_BUFFER_PACKETS
      Maximum size of encoder buffer in packets
      See Also:
    • ZERO

      protected static final IoBuffer ZERO
      Zero length buffer used to prime the ssl engine
    • LOGGER

      protected static final org.slf4j.Logger LOGGER
      Static logger
    • mEncodeQueue

      protected final Deque<WriteRequest> mEncodeQueue
      Write Requests which are enqueued prior to the completion of the handshaking
    • mAckQueue

      protected final Deque<WriteRequest> mAckQueue
      Requests which have been sent to the socket and waiting acknowledgment
    • mEngine

      protected final SSLEngine mEngine
      SSL Engine
    • mExecutor

      protected final Executor mExecutor
      Task executor
    • mSession

      protected final IoSession mSession
      Socket session
    • mDecodeBuffer

      protected IoBuffer mDecodeBuffer
      Progressive decoder buffer
    • mPendingError

      protected SSLException mPendingError
      Captured error state
  • Constructor Details

    • SslHandler

      public SslHandler(SSLEngine p, Executor e, IoSession s)
      Instantiates a new handler
      Parameters:
      p - engine
      e - executor
      s - session
  • Method Details

    • isOpen

      public abstract boolean isOpen()
      Returns:
      true if the encryption session is open
    • isConnected

      public abstract boolean isConnected()
      Returns:
      true if the encryption session is connected and secure
    • open

      public abstract void open(IoFilter.NextFilter next) throws SSLException
      Opens the encryption session, this may include sending the initial handshake message
      Parameters:
      next - The next filter
      Throws:
      SSLException - The thrown exception
    • receive

      public abstract void receive(IoFilter.NextFilter next, IoBuffer message) throws SSLException
      Decodes encrypted messages and passes the results to the next filter.
      Parameters:
      next - The next filter
      message - the received message
      Throws:
      SSLException - The thrown exception
    • ack

      public abstract void ack(IoFilter.NextFilter next, WriteRequest request) throws SSLException
      Acknowledge that a WriteRequest has been successfully written to the IoSession

      This functionality is used to enforce flow control by allowing only a specific number of pending write operations at any moment of time. When one WriteRequest is acknowledged, another can be encoded and written.

      Parameters:
      next - The next filter
      request - The request to ack
      Throws:
      SSLException - The thrown exception
    • write

      public abstract void write(IoFilter.NextFilter next, WriteRequest request) throws SSLException, WriteRejectedException
      Encrypts and writes the specified WriteRequest to the IoSession or enqueues it to be processed later.

      The encryption session may be currently handshaking preventing application messages from being written.

      Parameters:
      next - The next filter
      request - The request to write
      Throws:
      SSLException - The thrown exception
      WriteRejectedException - when the session is closing
    • close

      public abstract void close(IoFilter.NextFilter next, boolean linger) throws SSLException
      Closes the encryption session and writes any required messages
      Parameters:
      next - The next filter
      linger - if true, write any queued messages before closing
      Throws:
      SSLException - The thrown exception
    • write_handshake_loop

      protected abstract boolean write_handshake_loop(IoFilter.NextFilter next, IoBuffer source, IoBuffer dest) throws SSLException
      Attempts to generate a handshake message and write the data to the IoSession.

      If FAST_HANDSHAKE is enabled, this method will recursively loop in order to combine multiple messages into one buffer.

      Parameters:
      next -
      source -
      dest -
      Returns:
      true if a message was generated and written
      Throws:
      SSLException
    • toString

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

      protected IoBuffer resume_decode_buffer(IoBuffer source)
      Combines the received data with any previously received data
      Parameters:
      source - received data
      Returns:
      buffer to decode
    • suspend_decode_buffer

      protected void suspend_decode_buffer(IoBuffer source)
      Stores data for later use if any is remaining
      Parameters:
      source - the buffer previously returned by resume_decode_buffer(IoBuffer)
    • allocate_encode_buffer

      protected IoBuffer allocate_encode_buffer(int estimate)
      Allocates the default encoder buffer for the given source size
      Parameters:
      estimate - The estimated remaining size
      Returns:
      buffer The allocated buffer
    • allocate_app_buffer

      protected IoBuffer allocate_app_buffer(int estimate)
      Allocates the default decoder buffer for the given source size
      Parameters:
      estimate - The estimated remaining size
      Returns:
      buffer The allocated buffer
    • throw_pending_error

      protected void throw_pending_error(IoFilter.NextFilter next) throws SSLException
      Process the pending error and loop to send the associated alert if we have some.
      Parameters:
      next - The next filter in the chain
      Throws:
      SSLException - The rethrown pending error
    • write_handshake

      protected boolean write_handshake(IoFilter.NextFilter next) throws SSLException
      Attempts to generate a handshake message and write the data to the IoSession
      Parameters:
      next -
      Returns:
      true if a message was generated and written
      Throws:
      SSLException