Package org.apache.mina.filter.ssl
Class SslHandler
- java.lang.Object
-
- org.apache.mina.filter.ssl.SslHandler
-
class SslHandler extends java.lang.ObjectNo qualifier
-
-
Field Summary
Fields Modifier and Type Field Description private IoBufferappBufferApplication cleartext data to be read by applicationprivate IoBufferemptyBufferEmpty buffer used during initial handshake and close operationsprivate java.util.Queue<IoFilterEvent>filterWriteEventQueueprivate booleanfirstSSLNegociationA flag set to true when the first SSL handshake has been completed This is used to avoid sending a notification to the application handler when we switch to a SECURE or UNSECURE session.private booleanhandshakeCompleteA flag set to true when a SSL Handshake has been completedprivate javax.net.ssl.SSLEngineResult.HandshakeStatushandshakeStatusprivate IoBufferinNetBufferEncrypted data from the netprivate static org.slf4j.LoggerLOGGERA logger for this classprivate java.util.Queue<IoFilterEvent>messageReceivedEventQueueA queue used to stack all the incoming data until the SSL session is establishedprivate IoBufferoutNetBufferEncrypted data to be written to the netprivate java.util.Queue<IoFilterEvent>preHandshakeEventQueueprivate IoSessionsessionThe current sessionprivate javax.net.ssl.SSLEnginesslEngineprivate SslFiltersslFilterThe SSL Filter which has created this handlerprivate booleanwritingEncryptedDataA flag used to indicate to the SslFilter that the buffer it will write is already encrypted (this will be the case for data being produced during the handshake).
-
Constructor Summary
Constructors Constructor Description SslHandler(SslFilter sslFilter, IoSession session)Create a new SSL Handler, and initialize it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckStatus(javax.net.ssl.SSLEngineResult res)(package private) booleancloseOutbound()Start SSL shutdown process.(package private) static IoBuffercopy(java.nio.ByteBuffer src)Creates a new MINA buffer that is a deep copy of the remaining bytes in the given buffer (between index buf.position() and buf.limit())private voidcreateOutNetBuffer(int expectedRemaining)(package private) voiddestroy()Release allocated buffers.private javax.net.ssl.SSLEngineResult.HandshakeStatusdoTasks()Do all the outstanding handshake tasks in the current Thread.(package private) voidencrypt(java.nio.ByteBuffer src)Encrypt provided buffer.(package private) IoBufferfetchAppBuffer()Get decrypted application data.(package private) IoBufferfetchOutNetBuffer()Get encrypted data to be sent.(package private) voidflushFilterWrite()(package private) voidflushMessageReceived()(package private) voidflushPreHandshakeEvents()(package private) IoSessiongetSession()(package private) SslFiltergetSslFilter()(package private) voidhandshake(IoFilter.NextFilter nextFilter)Perform any handshaking processing.(package private) voidinit()Initialize the SSL handshake.(package private) booleanisHandshakeComplete()Check if handshake is completed.(package private) booleanisInboundDone()(package private) booleanisOutboundDone()(package private) booleanisWritingEncryptedData()Check if we are writing encrypted data.(package private) voidmessageReceived(IoFilter.NextFilter nextFilter, java.nio.ByteBuffer buf)Call when data are read from net.(package private) booleanneedToCompleteHandshake()Check if there is any need to complete handshake.(package private) booleannotHandshaking()Check if handshake is on going.(package private) voidrelease()Free the allocated buffersprivate voidrenegotiateIfNeeded(IoFilter.NextFilter nextFilter, javax.net.ssl.SSLEngineResult res)(package private) voidscheduleFilterWrite(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)(package private) voidscheduleMessageReceived(IoFilter.NextFilter nextFilter, java.lang.Object message)Push the newly received data into a queue, waiting for the SSL session to be fully established(package private) voidschedulePreHandshakeWriteRequest(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)java.lang.StringtoString()private javax.net.ssl.SSLEngineResultunwrap()Decrypt the incoming buffer and move the decrypted data to an application buffer.private javax.net.ssl.SSLEngineResult.StatusunwrapHandshake(IoFilter.NextFilter nextFilter)(package private) WriteFuturewriteNetBuffer(IoFilter.NextFilter nextFilter)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
A logger for this class
-
sslFilter
private final SslFilter sslFilter
The SSL Filter which has created this handler
-
session
private final IoSession session
The current session
-
preHandshakeEventQueue
private final java.util.Queue<IoFilterEvent> preHandshakeEventQueue
-
filterWriteEventQueue
private final java.util.Queue<IoFilterEvent> filterWriteEventQueue
-
messageReceivedEventQueue
private final java.util.Queue<IoFilterEvent> messageReceivedEventQueue
A queue used to stack all the incoming data until the SSL session is established
-
sslEngine
private javax.net.ssl.SSLEngine sslEngine
-
inNetBuffer
private IoBuffer inNetBuffer
Encrypted data from the net
-
outNetBuffer
private IoBuffer outNetBuffer
Encrypted data to be written to the net
-
appBuffer
private IoBuffer appBuffer
Application cleartext data to be read by application
-
emptyBuffer
private final IoBuffer emptyBuffer
Empty buffer used during initial handshake and close operations
-
handshakeStatus
private javax.net.ssl.SSLEngineResult.HandshakeStatus handshakeStatus
-
firstSSLNegociation
private boolean firstSSLNegociation
A flag set to true when the first SSL handshake has been completed This is used to avoid sending a notification to the application handler when we switch to a SECURE or UNSECURE session.
-
handshakeComplete
private boolean handshakeComplete
A flag set to true when a SSL Handshake has been completed
-
writingEncryptedData
private boolean writingEncryptedData
A flag used to indicate to the SslFilter that the buffer it will write is already encrypted (this will be the case for data being produced during the handshake).
-
-
Method Detail
-
init
void init() throws javax.net.ssl.SSLException
Initialize the SSL handshake.- Throws:
javax.net.ssl.SSLException- If the underlying SSLEngine handshake initialization failed
-
destroy
void destroy()
Release allocated buffers.
-
getSslFilter
SslFilter getSslFilter()
- Returns:
- The SSL filter which has created this handler
-
getSession
IoSession getSession()
-
isWritingEncryptedData
boolean isWritingEncryptedData()
Check if we are writing encrypted data.
-
isHandshakeComplete
boolean isHandshakeComplete()
Check if handshake is completed.
-
notHandshaking
boolean notHandshaking()
Check if handshake is on going.
-
isInboundDone
boolean isInboundDone()
-
isOutboundDone
boolean isOutboundDone()
-
needToCompleteHandshake
boolean needToCompleteHandshake()
Check if there is any need to complete handshake.
-
schedulePreHandshakeWriteRequest
void schedulePreHandshakeWriteRequest(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
-
flushPreHandshakeEvents
void flushPreHandshakeEvents() throws javax.net.ssl.SSLException- Throws:
javax.net.ssl.SSLException
-
scheduleFilterWrite
void scheduleFilterWrite(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
-
flushFilterWrite
void flushFilterWrite()
-
scheduleMessageReceived
void scheduleMessageReceived(IoFilter.NextFilter nextFilter, java.lang.Object message)
Push the newly received data into a queue, waiting for the SSL session to be fully established- Parameters:
nextFilter- The next filter to callmessage- The incoming data
-
flushMessageReceived
void flushMessageReceived()
-
messageReceived
void messageReceived(IoFilter.NextFilter nextFilter, java.nio.ByteBuffer buf) throws javax.net.ssl.SSLException
Call when data are read from net. It will perform the initial hanshake or decrypt the data if SSL has been initialiaed.- Parameters:
buf- buffer to decryptnextFilter- Next filter in chain- Throws:
javax.net.ssl.SSLException- on errors
-
fetchAppBuffer
IoBuffer fetchAppBuffer()
Get decrypted application data.- Returns:
- buffer with data
-
fetchOutNetBuffer
IoBuffer fetchOutNetBuffer()
Get encrypted data to be sent.- Returns:
- buffer with data
-
encrypt
void encrypt(java.nio.ByteBuffer src) throws javax.net.ssl.SSLExceptionEncrypt provided buffer. Encrypted data returned by getOutNetBuffer().- Parameters:
src- data to encrypt- Throws:
javax.net.ssl.SSLException- on errors
-
closeOutbound
boolean closeOutbound() throws javax.net.ssl.SSLExceptionStart SSL shutdown process.- Returns:
trueif shutdown process is started.falseif shutdown process is already finished.- Throws:
javax.net.ssl.SSLException- on errors
-
checkStatus
private void checkStatus(javax.net.ssl.SSLEngineResult res) throws javax.net.ssl.SSLException- Parameters:
res-- Throws:
javax.net.ssl.SSLException
-
handshake
void handshake(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
Perform any handshaking processing.- Throws:
javax.net.ssl.SSLException
-
createOutNetBuffer
private void createOutNetBuffer(int expectedRemaining)
-
writeNetBuffer
WriteFuture writeNetBuffer(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
unwrapHandshake
private javax.net.ssl.SSLEngineResult.Status unwrapHandshake(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
renegotiateIfNeeded
private void renegotiateIfNeeded(IoFilter.NextFilter nextFilter, javax.net.ssl.SSLEngineResult res) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
unwrap
private javax.net.ssl.SSLEngineResult unwrap() throws javax.net.ssl.SSLExceptionDecrypt the incoming buffer and move the decrypted data to an application buffer.- Throws:
javax.net.ssl.SSLException
-
doTasks
private javax.net.ssl.SSLEngineResult.HandshakeStatus doTasks()
Do all the outstanding handshake tasks in the current Thread.
-
copy
static IoBuffer copy(java.nio.ByteBuffer src)
Creates a new MINA 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
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
release
void release()
Free the allocated buffers
-
-