class SslHandler
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private IoBuffer |
appBuffer
Application cleartext data to be read by application
|
private IoBuffer |
emptyBuffer
Empty buffer used during initial handshake and close operations
|
private java.util.Queue<IoFilterEvent> |
filterWriteEventQueue |
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.
|
private boolean |
handshakeComplete
A flag set to true when a SSL Handshake has been completed
|
private javax.net.ssl.SSLEngineResult.HandshakeStatus |
handshakeStatus |
private IoBuffer |
inNetBuffer
Encrypted data from the net
|
private static org.slf4j.Logger |
LOGGER
A logger for this class
|
private java.util.Queue<IoFilterEvent> |
messageReceivedEventQueue
A queue used to stack all the incoming data until the SSL session is established
|
private IoBuffer |
outNetBuffer
Encrypted data to be written to the net
|
private java.util.Queue<IoFilterEvent> |
preHandshakeEventQueue |
private IoSession |
session
The current session
|
private javax.net.ssl.SSLEngine |
sslEngine |
private SslFilter |
sslFilter
The SSL Filter which has created this handler
|
private java.util.concurrent.locks.Lock |
sslLock |
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).
|
| Constructor and Description |
|---|
SslHandler(SslFilter sslFilter,
IoSession session)
Create a new SSL Handler, and initialize it.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
checkStatus(javax.net.ssl.SSLEngineResult res) |
(package private) boolean |
closeOutbound()
Start SSL shutdown process.
|
(package private) 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())
|
private void |
createOutNetBuffer(int expectedRemaining) |
(package private) void |
destroy()
Release allocated buffers.
|
private javax.net.ssl.SSLEngineResult.HandshakeStatus |
doTasks()
Do all the outstanding handshake tasks in the current Thread.
|
(package private) void |
encrypt(java.nio.ByteBuffer src)
Encrypt provided buffer.
|
(package private) IoBuffer |
fetchAppBuffer()
Get decrypted application data.
|
(package private) IoBuffer |
fetchOutNetBuffer()
Get encrypted data to be sent.
|
(package private) void |
flushPreHandshakeEvents() |
(package private) void |
flushScheduledEvents() |
(package private) IoSession |
getSession() |
(package private) SslFilter |
getSslFilter() |
(package private) void |
handshake(IoFilter.NextFilter nextFilter)
Perform any handshaking processing.
|
(package private) void |
init()
Initialize the SSL handshake.
|
(package private) boolean |
isHandshakeComplete()
Check if handshake is completed.
|
(package private) boolean |
isInboundDone() |
(package private) boolean |
isOutboundDone() |
(package private) boolean |
isWritingEncryptedData()
Check if we are writing encrypted data.
|
(package private) void |
messageReceived(IoFilter.NextFilter nextFilter,
java.nio.ByteBuffer buf)
Call when data are read from net.
|
(package private) boolean |
needToCompleteHandshake()
Check if there is any need to complete handshake.
|
(package private) void |
release()
Free the allocated buffers
|
private void |
renegotiateIfNeeded(IoFilter.NextFilter nextFilter,
javax.net.ssl.SSLEngineResult res) |
(package private) void |
scheduleFilterWrite(IoFilter.NextFilter nextFilter,
WriteRequest writeRequest) |
(package private) 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
|
(package private) void |
schedulePreHandshakeWriteRequest(IoFilter.NextFilter nextFilter,
WriteRequest writeRequest) |
java.lang.String |
toString() |
private javax.net.ssl.SSLEngineResult |
unwrap()
Decrypt the incoming buffer and move the decrypted data to an
application buffer.
|
private javax.net.ssl.SSLEngineResult.Status |
unwrapHandshake(IoFilter.NextFilter nextFilter) |
(package private) WriteFuture |
writeNetBuffer(IoFilter.NextFilter nextFilter) |
private static final org.slf4j.Logger LOGGER
private final SslFilter sslFilter
private final IoSession session
private final java.util.Queue<IoFilterEvent> preHandshakeEventQueue
private final java.util.Queue<IoFilterEvent> filterWriteEventQueue
private final java.util.Queue<IoFilterEvent> messageReceivedEventQueue
private javax.net.ssl.SSLEngine sslEngine
private IoBuffer inNetBuffer
private IoBuffer outNetBuffer
private IoBuffer appBuffer
private final IoBuffer emptyBuffer
private javax.net.ssl.SSLEngineResult.HandshakeStatus handshakeStatus
private boolean firstSSLNegociation
private boolean handshakeComplete
private boolean writingEncryptedData
private java.util.concurrent.locks.Lock sslLock
void init() throws javax.net.ssl.SSLException
javax.net.ssl.SSLException - If the underlying SSLEngine handshake initialization failedvoid destroy()
SslFilter getSslFilter()
IoSession getSession()
boolean isWritingEncryptedData()
boolean isHandshakeComplete()
boolean isInboundDone()
boolean isOutboundDone()
boolean needToCompleteHandshake()
void schedulePreHandshakeWriteRequest(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
void flushPreHandshakeEvents()
throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionvoid scheduleFilterWrite(IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
void scheduleMessageReceived(IoFilter.NextFilter nextFilter, java.lang.Object message)
nextFilter - The next filter to callmessage - The incoming datavoid flushScheduledEvents()
void messageReceived(IoFilter.NextFilter nextFilter, java.nio.ByteBuffer buf) throws javax.net.ssl.SSLException
buf - buffer to decryptnextFilter - Next filter in chainjavax.net.ssl.SSLException - on errorsIoBuffer fetchAppBuffer()
IoBuffer fetchOutNetBuffer()
void encrypt(java.nio.ByteBuffer src)
throws javax.net.ssl.SSLException
src - data to encryptjavax.net.ssl.SSLException - on errorsboolean closeOutbound()
throws javax.net.ssl.SSLException
javax.net.ssl.SSLException - on errorsprivate void checkStatus(javax.net.ssl.SSLEngineResult res)
throws javax.net.ssl.SSLException
res - javax.net.ssl.SSLExceptionvoid handshake(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionprivate void createOutNetBuffer(int expectedRemaining)
WriteFuture writeNetBuffer(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionprivate javax.net.ssl.SSLEngineResult.Status unwrapHandshake(IoFilter.NextFilter nextFilter) throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionprivate void renegotiateIfNeeded(IoFilter.NextFilter nextFilter, javax.net.ssl.SSLEngineResult res) throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionprivate javax.net.ssl.SSLEngineResult unwrap()
throws javax.net.ssl.SSLException
javax.net.ssl.SSLExceptionprivate javax.net.ssl.SSLEngineResult.HandshakeStatus doTasks()
static IoBuffer copy(java.nio.ByteBuffer src)
src - the buffer to copypublic java.lang.String toString()
toString in class java.lang.Objectvoid release()