Class SslHandler
java.lang.Object
org.apache.mina.filter.ssl.SslHandler
No qualifier
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IoBufferApplication cleartext data to be read by applicationprivate final IoBufferEmpty buffer used during initial handshake and close operationsprivate final Queue<IoFilterEvent> private booleanA 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 booleanA flag set to true when a SSL Handshake has been completedprivate SSLEngineResult.HandshakeStatusprivate IoBufferEncrypted data from the netprivate static final org.slf4j.LoggerA logger for this classprivate final Queue<IoFilterEvent> A queue used to stack all the incoming data until the SSL session is establishedprivate IoBufferEncrypted data to be written to the netprivate final Queue<IoFilterEvent> private final IoSessionThe current sessionprivate SSLEngineprivate final SslFilterThe SSL Filter which has created this handlerprivate booleanA 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
ConstructorsConstructorDescriptionSslHandler(SslFilter sslFilter, IoSession session) Create a new SSL Handler, and initialize it. -
Method Summary
Modifier and TypeMethodDescriptionprivate void(package private) booleanStart SSL shutdown process.(package private) static IoBuffercopy(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 SSLEngineResult.HandshakeStatusdoTasks()Do all the outstanding handshake tasks in the current Thread.(package private) voidencrypt(ByteBuffer src) Encrypt provided buffer.(package private) IoBufferGet decrypted application data.(package private) IoBufferGet encrypted data to be sent.(package private) void(package private) void(package private) void(package private) IoSession(package private) SslFilter(package private) voidhandshake(IoFilter.NextFilter nextFilter) Perform any handshaking processing.(package private) voidinit()Initialize the SSL handshake.(package private) booleanCheck if handshake is completed.(package private) boolean(package private) boolean(package private) booleanCheck if we are writing encrypted data.(package private) voidmessageReceived(IoFilter.NextFilter nextFilter, ByteBuffer buf) Call when data are read from net.(package private) booleanCheck if there is any need to complete handshake.(package private) booleanCheck if handshake is on going.(package private) voidrelease()Free the allocated buffersprivate voidrenegotiateIfNeeded(IoFilter.NextFilter nextFilter, SSLEngineResult res) (package private) voidscheduleFilterWrite(IoFilter.NextFilter nextFilter, WriteRequest writeRequest) (package private) voidscheduleMessageReceived(IoFilter.NextFilter nextFilter, 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) toString()private SSLEngineResultunwrap()Decrypt the incoming buffer and move the decrypted data to an application buffer.private SSLEngineResult.StatusunwrapHandshake(IoFilter.NextFilter nextFilter) (package private) WriteFuturewriteNetBuffer(IoFilter.NextFilter nextFilter)
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGERA logger for this class -
sslFilter
The SSL Filter which has created this handler -
session
The current session -
preHandshakeEventQueue
-
filterWriteEventQueue
-
messageReceivedEventQueue
A queue used to stack all the incoming data until the SSL session is established -
sslEngine
-
inNetBuffer
Encrypted data from the net -
outNetBuffer
Encrypted data to be written to the net -
appBuffer
Application cleartext data to be read by application -
emptyBuffer
Empty buffer used during initial handshake and close operations -
handshakeStatus
-
firstSSLNegociation
private boolean firstSSLNegociationA 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 handshakeCompleteA flag set to true when a SSL Handshake has been completed -
writingEncryptedData
private boolean writingEncryptedDataA 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 Details
-
SslHandler
Create a new SSL Handler, and initialize it.- Parameters:
sslContext-- Throws:
SSLException
-
-
Method Details
-
init
Initialize the SSL handshake.- Throws:
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
-
flushPreHandshakeEvents
- Throws:
SSLException
-
scheduleFilterWrite
-
flushFilterWrite
void flushFilterWrite() -
scheduleMessageReceived
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
Call when data are read from net. It will perform the initial hanshake or decrypt the data if SSL has been initialiaed.- Parameters:
nextFilter- Next filter in chainbuf- buffer to decrypt- Throws:
SSLException- on errors
-
fetchAppBuffer
-
fetchOutNetBuffer
-
encrypt
Encrypt provided buffer. Encrypted data returned by getOutNetBuffer().- Parameters:
src- data to encrypt- Throws:
SSLException- on errors
-
closeOutbound
Start SSL shutdown process.- Returns:
trueif shutdown process is started.falseif shutdown process is already finished.- Throws:
SSLException- on errors
-
checkStatus
- Parameters:
res-- Throws:
SSLException
-
handshake
Perform any handshaking processing.- Throws:
SSLException
-
createOutNetBuffer
private void createOutNetBuffer(int expectedRemaining) -
writeNetBuffer
- Throws:
SSLException
-
unwrapHandshake
- Throws:
SSLException
-
renegotiateIfNeeded
private void renegotiateIfNeeded(IoFilter.NextFilter nextFilter, SSLEngineResult res) throws SSLException - Throws:
SSLException
-
unwrap
Decrypt the incoming buffer and move the decrypted data to an application buffer.- Throws:
SSLException
-
doTasks
Do all the outstanding handshake tasks in the current Thread. -
copy
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
-
release
void release()Free the allocated buffers
-