Package org.apache.mina.filter.support
Class SSLHandler
java.lang.Object
org.apache.mina.filter.support.SSLHandler
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 Summary
ConstructorsConstructorDescriptionSSLHandler
(SSLFilter parent, SSLContext sslc, org.apache.mina.common.IoSession session) Constuctor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Start SSL shutdown process.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())void
destroy()
Release allocated ByteBuffers.void
encrypt
(ByteBuffer src) Encrypt provided buffer.void
void
Get decrypted application data.Get encrypted data to be sent.org.apache.mina.common.IoSession
void
handshake
(org.apache.mina.common.IoFilter.NextFilter nextFilter) Perform any handshaking processing.void
init()
boolean
Check if handshake is completed.boolean
boolean
boolean
Check we are writing encrypted data.void
messageReceived
(org.apache.mina.common.IoFilter.NextFilter nextFilter, ByteBuffer buf) Call when data read from net.boolean
Check if there is any need to complete handshake.void
scheduleFilterWrite
(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoFilter.WriteRequest writeRequest) void
scheduleMessageReceived
(org.apache.mina.common.IoFilter.NextFilter nextFilter, Object message) void
schedulePreHandshakeWriteRequest
(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoFilter.WriteRequest writeRequest) org.apache.mina.common.WriteFuture
writeNetBuffer
(org.apache.mina.common.IoFilter.NextFilter nextFilter)
-
Constructor Details
-
SSLHandler
public SSLHandler(SSLFilter parent, SSLContext sslc, org.apache.mina.common.IoSession session) throws SSLException Constuctor.- Parameters:
sslc
-- Throws:
SSLException
-
-
Method Details
-
init
- Throws:
SSLException
-
destroy
public void destroy()Release allocated ByteBuffers. -
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
- 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
Get decrypted application data.- Returns:
- buffer with data
-
getOutNetBuffer
Get encrypted data to be sent.- Returns:
- buffer with data
-
encrypt
Encrypt provided buffer. Encytpted data reurned by getOutNetBuffer().- Parameters:
src
- data to encrypt- Throws:
SSLException
- on errors
-
closeOutbound
Start SSL shutdown process.- Returns:
- true if shutdown process is started. false if shutdown process is already finished.
- Throws:
SSLException
- on errors
-
handshake
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
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
-