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.
closeOutbound
public boolean closeOutbound()
throws SSLException
Start SSL shutdown process.
- true if shutdown process is started.
false if shutdown process is already finished.
copy
public static 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())
- the new buffer, ready to read from
destroy
public void destroy()
Release allocated ByteBuffers.
encrypt
public void encrypt(ByteBuffer src)
throws SSLException
Encrypt provided buffer. Encytpted data reurned by getOutNetBuffer().
flushPreHandshakeEvents
public void flushPreHandshakeEvents()
throws SSLException
flushScheduledEvents
public void flushScheduledEvents()
getAppBuffer
public ByteBuffer getAppBuffer()
Get decrypted application data.
getOutNetBuffer
public ByteBuffer getOutNetBuffer()
Get encrypted data to be sent.
handshake
public void handshake(IoFilter.NextFilter nextFilter)
throws SSLException
Perform any handshaking processing.
init
public void init()
throws SSLException
isHandshakeComplete
public boolean isHandshakeComplete()
Check if handshake is completed.
isInboundDone
public boolean isInboundDone()
isOutboundDone
public boolean isOutboundDone()
isWritingEncryptedData
public boolean isWritingEncryptedData()
Check we are writing encrypted data.
messageReceived
public void messageReceived(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.
needToCompleteHandshake
public boolean needToCompleteHandshake()
Check if there is any need to complete handshake.
scheduleMessageReceived
public void scheduleMessageReceived(IoFilter.NextFilter nextFilter,
Object message)