Package org.apache.mina.filter.support
Class SSLHandler
- java.lang.Object
-
- org.apache.mina.filter.support.SSLHandler
-
public class SSLHandler extends java.lang.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 Summary
Constructors Constructor Description SSLHandler(SSLFilter parent, javax.net.ssl.SSLContext sslc, org.apache.mina.common.IoSession session)
Constuctor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
closeOutbound()
Start SSL shutdown process.static org.apache.mina.common.ByteBuffer
copy(java.nio.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(java.nio.ByteBuffer src)
Encrypt provided buffer.void
flushPreHandshakeEvents()
void
flushScheduledEvents()
java.nio.ByteBuffer
getAppBuffer()
Get decrypted application data.java.nio.ByteBuffer
getOutNetBuffer()
Get encrypted data to be sent.SSLFilter
getParent()
org.apache.mina.common.IoSession
getSession()
void
handshake(org.apache.mina.common.IoFilter.NextFilter nextFilter)
Perform any handshaking processing.void
init()
boolean
isHandshakeComplete()
Check if handshake is completed.boolean
isInboundDone()
boolean
isOutboundDone()
boolean
isWritingEncryptedData()
Check we are writing encrypted data.void
messageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, java.nio.ByteBuffer buf)
Call when data read from net.boolean
needToCompleteHandshake()
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, java.lang.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 Detail
-
SSLHandler
public SSLHandler(SSLFilter parent, javax.net.ssl.SSLContext sslc, org.apache.mina.common.IoSession session) throws javax.net.ssl.SSLException
Constuctor.- Parameters:
sslc
-- Throws:
javax.net.ssl.SSLException
-
-
Method Detail
-
init
public void init() throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.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 javax.net.ssl.SSLException
- Throws:
javax.net.ssl.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, java.lang.Object message)
-
flushScheduledEvents
public void flushScheduledEvents()
-
messageReceived
public void messageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, java.nio.ByteBuffer buf) throws javax.net.ssl.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:
javax.net.ssl.SSLException
- on errors
-
getAppBuffer
public java.nio.ByteBuffer getAppBuffer()
Get decrypted application data.- Returns:
- buffer with data
-
getOutNetBuffer
public java.nio.ByteBuffer getOutNetBuffer()
Get encrypted data to be sent.- Returns:
- buffer with data
-
encrypt
public void encrypt(java.nio.ByteBuffer src) throws javax.net.ssl.SSLException
Encrypt provided buffer. Encytpted data reurned by getOutNetBuffer().- Parameters:
src
- data to encrypt- Throws:
javax.net.ssl.SSLException
- on errors
-
closeOutbound
public boolean closeOutbound() throws javax.net.ssl.SSLException
Start SSL shutdown process.- Returns:
- true if shutdown process is started. false if shutdown process is already finished.
- Throws:
javax.net.ssl.SSLException
- on errors
-
handshake
public void handshake(org.apache.mina.common.IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
Perform any handshaking processing.- Throws:
javax.net.ssl.SSLException
-
writeNetBuffer
public org.apache.mina.common.WriteFuture writeNetBuffer(org.apache.mina.common.IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
copy
public static org.apache.mina.common.ByteBuffer copy(java.nio.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
-
-