Class SSLHandler

java.lang.Object
org.apache.mina.filter.support.SSLHandler

public class SSLHandler extends Object
A helper class using the SSLEngine API to decrypt/encrypt data.

Each connection has a SSLEngine that is used through the lifetime of the connection. We allocate byte buffers for use as the outbound and inbound network buffers. These buffers handle all of the intermediary data for the SSL connection. To make things easy, we'll require outNetBuffer be completely flushed before trying to wrap any more data.

  • Constructor Details

  • Method Details

    • init

      public void init() throws SSLException
      Throws:
      SSLException
    • destroy

      public void destroy()
      Release allocated ByteBuffers.
    • getParent

      public SSLFilter getParent()
    • getSession

      public org.apache.mina.common.IoSession getSession()
    • isWritingEncryptedData

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

      public boolean isHandshakeComplete()
      Check if handshake is completed.
    • isInboundDone

      public boolean isInboundDone()
    • isOutboundDone

      public boolean isOutboundDone()
    • needToCompleteHandshake

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

      public void schedulePreHandshakeWriteRequest(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoFilter.WriteRequest writeRequest)
    • flushPreHandshakeEvents

      public void flushPreHandshakeEvents() throws SSLException
      Throws:
      SSLException
    • scheduleFilterWrite

      public void scheduleFilterWrite(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoFilter.WriteRequest writeRequest)
    • scheduleMessageReceived

      public void scheduleMessageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, Object message)
    • flushScheduledEvents

      public void flushScheduledEvents()
    • messageReceived

      public void messageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, ByteBuffer buf) throws SSLException
      Call when data read from net. Will perform inial hanshake or decrypt provided Buffer. Decrytpted data reurned by getAppBuffer(), if any.
      Parameters:
      buf - buffer to decrypt
      Throws:
      SSLException - on errors
    • getAppBuffer

      public ByteBuffer getAppBuffer()
      Get decrypted application data.
      Returns:
      buffer with data
    • getOutNetBuffer

      public ByteBuffer getOutNetBuffer()
      Get encrypted data to be sent.
      Returns:
      buffer with data
    • encrypt

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

      public 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
    • handshake

      public void handshake(org.apache.mina.common.IoFilter.NextFilter nextFilter) throws SSLException
      Perform any handshaking processing.
      Throws:
      SSLException
    • writeNetBuffer

      public org.apache.mina.common.WriteFuture writeNetBuffer(org.apache.mina.common.IoFilter.NextFilter nextFilter) throws SSLException
      Throws:
      SSLException
    • copy

      public static org.apache.mina.common.ByteBuffer copy(ByteBuffer src)
      Creates a new Mina byte 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