Package org.apache.mina.filter.ssl
Class SSLHandlerG1
- java.lang.Object
-
- org.apache.mina.filter.ssl.SslHandler
-
- org.apache.mina.filter.ssl.SSLHandlerG1
-
class SSLHandlerG1 extends SslHandler
Default implementation of SSLHandlerThe concurrency model is enforced using a simple mutex to ensure that the state of the decode buffer and closure is concurrent with the SSLEngine.
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanENABLE_ASYNC_TASKSEnable asynchronous tasks.protected static booleanENABLE_FAST_HANDSHAKEEnable aggregation of handshake messagesprotected static booleanENABLE_SOFT_CLOSUREWrites the SSL Closure messages after a close requestprotected static intMAX_QUEUED_MESSAGESMaximum number of queued messages waiting for encodingprotected static intMAX_UNACK_MESSAGESMaximum number of messages waiting acknowledgementprotected java.util.Deque<FilterEvent>mEventQueuePending filter events for dispatchingprotected booleanmHandshakeCompleteIndicates whether the first handshake was completedprotected booleanmHandshakeStartedIndicated whether the first handshake was startedprotected booleanmOutboundClosingIndicates that the outbound is closingprotected booleanmOutboundLingerIndicates that previously queued messages should be written before closingprotected javax.net.ssl.SSLExceptionmPendingErrorCaptured error stateprotected java.util.Deque<IoBuffer>mReceiveQueueDecoded buffers ready for processing downstreamprotected java.lang.ThreadmReceiveThreadHolds the decoder thread reference; used for recursion detection introduced by a delegated taskprotected java.util.Deque<EncryptedWriteRequest>mWriteQueueEncoded buffers ready for processing upstream-
Fields inherited from class org.apache.mina.filter.ssl.SslHandler
LOGGER, mAckQueue, MAX_ENCODER_BUFFER_PACKETS, mDecodeBuffer, mEncodeQueue, mEngine, mExecutor, MIN_ENCODER_BUFFER_PACKETS, mSession, ZERO
-
-
Constructor Summary
Constructors Constructor Description SSLHandlerG1(javax.net.ssl.SSLEngine sslEngine, java.util.concurrent.Executor executor, IoSession session)Instantiates a new handler
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidack(IoFilter.NextFilter next, WriteRequest request)Acknowledge that aWriteRequesthas been successfully written to theIoSessionprotected voidack_start(IoFilter.NextFilter next, WriteRequest request)voidclose(IoFilter.NextFilter next, boolean linger)Closes the encryption session and writes any required messagesprotected voidclose_start(IoFilter.NextFilter next, boolean linger)protected voidexecute_task(IoFilter.NextFilter next)Execute a SSLEngine task.protected voidfinish_handshake(IoFilter.NextFilter next)Marks the handshake as complete and emits any signalsvoidflush(IoFilter.NextFilter next)protected voidflush_start(IoFilter.NextFilter next)Flushes the encode queueprotected voidforward_events(IoFilter.NextFilter next)protected voidforward_received(IoFilter.NextFilter next)protected voidforward_writes(IoFilter.NextFilter next)booleanisConnected()booleanisOpen()voidopen(IoFilter.NextFilter next)Opens the encryption session, this may include sending the initial handshake messageprotected voidopen_start(IoFilter.NextFilter next)voidreceive(IoFilter.NextFilter next, IoBuffer message)Decodes encrypted messages and passes the results to thenextfilter.protected voidreceive_loop(IoFilter.NextFilter next, IoBuffer message)Process a received messageprotected voidreceive_start(IoFilter.NextFilter next, IoBuffer message)protected voidschedule_task(IoFilter.NextFilter next)Schedule a SSLEngine task for execution, either using an Executor, or immediately.protected voidstore_pending_error(javax.net.ssl.SSLException sslException)Store any error we've got during the handshake or message handlingprotected voidthrow_pending_error(IoFilter.NextFilter next)Process the pending error and loop to send the associated alert if we have some.voidwrite(IoFilter.NextFilter next, WriteRequest request)Encrypts and writes the specifiedWriteRequestto theIoSessionor enqueues it to be processed later.protected booleanwrite_handshake(IoFilter.NextFilter next)Attempts to generate a handshake message and write the data to the IoSessionprotected booleanwrite_handshake_loop(IoFilter.NextFilter next, IoBuffer source, IoBuffer dest)Attempts to generate a handshake message and write the data to the IoSession.protected booleanwrite_loop(IoFilter.NextFilter next, WriteRequest request)Attempts to encode the WriteRequest and write the data to the IoSessionprotected voidwrite_start(IoFilter.NextFilter next, WriteRequest request)-
Methods inherited from class org.apache.mina.filter.ssl.SslHandler
allocate_app_buffer, allocate_encode_buffer, resume_decode_buffer, suspend_decode_buffer, toString
-
-
-
-
Field Detail
-
MAX_QUEUED_MESSAGES
protected static final int MAX_QUEUED_MESSAGES
Maximum number of queued messages waiting for encoding- See Also:
- Constant Field Values
-
MAX_UNACK_MESSAGES
protected static final int MAX_UNACK_MESSAGES
Maximum number of messages waiting acknowledgement- See Also:
- Constant Field Values
-
ENABLE_SOFT_CLOSURE
protected static final boolean ENABLE_SOFT_CLOSURE
Writes the SSL Closure messages after a close request- See Also:
- Constant Field Values
-
ENABLE_FAST_HANDSHAKE
protected static final boolean ENABLE_FAST_HANDSHAKE
Enable aggregation of handshake messages- See Also:
- Constant Field Values
-
ENABLE_ASYNC_TASKS
protected static final boolean ENABLE_ASYNC_TASKS
Enable asynchronous tasks. Default to false.- See Also:
- Constant Field Values
-
mHandshakeComplete
protected boolean mHandshakeComplete
Indicates whether the first handshake was completed
-
mHandshakeStarted
protected boolean mHandshakeStarted
Indicated whether the first handshake was started
-
mOutboundClosing
protected boolean mOutboundClosing
Indicates that the outbound is closing
-
mOutboundLinger
protected boolean mOutboundLinger
Indicates that previously queued messages should be written before closing
-
mReceiveThread
protected volatile java.lang.Thread mReceiveThread
Holds the decoder thread reference; used for recursion detection introduced by a delegated task
-
mWriteQueue
protected final java.util.Deque<EncryptedWriteRequest> mWriteQueue
Encoded buffers ready for processing upstream
-
mReceiveQueue
protected final java.util.Deque<IoBuffer> mReceiveQueue
Decoded buffers ready for processing downstream
-
mEventQueue
protected final java.util.Deque<FilterEvent> mEventQueue
Pending filter events for dispatching
-
mPendingError
protected javax.net.ssl.SSLException mPendingError
Captured error state
-
-
Constructor Detail
-
SSLHandlerG1
public SSLHandlerG1(javax.net.ssl.SSLEngine sslEngine, java.util.concurrent.Executor executor, IoSession session)Instantiates a new handler- Parameters:
sslEngine- The SSLEngine instanceexecutor- The executor instance to use to process taskssession- The session to handle
-
-
Method Detail
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin classSslHandler- Returns:
trueif the encryption session is open
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin classSslHandler- Returns:
trueif the encryption session is connected and secure
-
open
public void open(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
Opens the encryption session, this may include sending the initial handshake message- Specified by:
openin classSslHandler- Parameters:
next- The next filter- Throws:
javax.net.ssl.SSLException- The thrown exception
-
open_start
protected void open_start(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
receive
public void receive(IoFilter.NextFilter next, IoBuffer message) throws javax.net.ssl.SSLException
Decodes encrypted messages and passes the results to thenextfilter.- Specified by:
receivein classSslHandler- Parameters:
next- The next filtermessage- the received message- Throws:
javax.net.ssl.SSLException- The thrown exception
-
receive_start
protected void receive_start(IoFilter.NextFilter next, IoBuffer message) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
receive_loop
protected void receive_loop(IoFilter.NextFilter next, IoBuffer message) throws javax.net.ssl.SSLException
Process a received message- Parameters:
next- The next filtermessage- The message to process- Throws:
javax.net.ssl.SSLException- If we get some error while processing the message
-
ack
public void ack(IoFilter.NextFilter next, WriteRequest request) throws javax.net.ssl.SSLException
Acknowledge that aWriteRequesthas been successfully written to theIoSessionThis functionality is used to enforce flow control by allowing only a specific number of pending write operations at any moment of time. When one
WriteRequestis acknowledged, another can be encoded and written.- Specified by:
ackin classSslHandler- Parameters:
next- The next filterrequest- The request to ack- Throws:
javax.net.ssl.SSLException- The thrown exception
-
ack_start
protected void ack_start(IoFilter.NextFilter next, WriteRequest request) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
write
public void write(IoFilter.NextFilter next, WriteRequest request) throws javax.net.ssl.SSLException, WriteRejectedException
Encrypts and writes the specifiedWriteRequestto theIoSessionor enqueues it to be processed later.The encryption session may be currently handshaking preventing application messages from being written.
- Specified by:
writein classSslHandler- Parameters:
next- The next filterrequest- The request to write- Throws:
javax.net.ssl.SSLException- The thrown exceptionWriteRejectedException- when the session is closing
-
write_start
protected void write_start(IoFilter.NextFilter next, WriteRequest request) throws javax.net.ssl.SSLException, WriteRejectedException
- Throws:
javax.net.ssl.SSLExceptionWriteRejectedException
-
write_loop
protected boolean write_loop(IoFilter.NextFilter next, WriteRequest request) throws javax.net.ssl.SSLException
Attempts to encode the WriteRequest and write the data to the IoSession- Parameters:
next-request-- Returns:
trueif the WriteRequest was fully consumed; otherwisefalse- Throws:
javax.net.ssl.SSLException
-
write_handshake
protected boolean write_handshake(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
Attempts to generate a handshake message and write the data to the IoSession- Parameters:
next-- Returns:
trueif a message was generated and written- Throws:
javax.net.ssl.SSLException
-
write_handshake_loop
protected boolean write_handshake_loop(IoFilter.NextFilter next, IoBuffer source, IoBuffer dest) throws javax.net.ssl.SSLException
Attempts to generate a handshake message and write the data to the IoSession.If FAST_HANDSHAKE is enabled, this method will recursively loop in order to combine multiple messages into one buffer.
- Parameters:
next-source-dest-- Returns:
trueif a message was generated and written- Throws:
javax.net.ssl.SSLException
-
finish_handshake
protected void finish_handshake(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
Marks the handshake as complete and emits any signals- Parameters:
next-- Throws:
javax.net.ssl.SSLException
-
flush
public void flush(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
flush_start
protected void flush_start(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
Flushes the encode queue- Parameters:
next-- Throws:
javax.net.ssl.SSLException
-
close
public void close(IoFilter.NextFilter next, boolean linger) throws javax.net.ssl.SSLException
Closes the encryption session and writes any required messages- Specified by:
closein classSslHandler- Parameters:
next- The next filterlinger- if true, write any queued messages before closing- Throws:
javax.net.ssl.SSLException- The thrown exception
-
close_start
protected void close_start(IoFilter.NextFilter next, boolean linger) throws javax.net.ssl.SSLException
- Throws:
javax.net.ssl.SSLException
-
throw_pending_error
protected void throw_pending_error(IoFilter.NextFilter next) throws javax.net.ssl.SSLException
Process the pending error and loop to send the associated alert if we have some.- Parameters:
next- The next filter in the chain- Throws:
javax.net.ssl.SSLException- The rethrown pending error
-
store_pending_error
protected void store_pending_error(javax.net.ssl.SSLException sslException)
Store any error we've got during the handshake or message handling- Parameters:
sslException- The exfeption to store
-
forward_received
protected void forward_received(IoFilter.NextFilter next)
-
forward_writes
protected void forward_writes(IoFilter.NextFilter next)
-
forward_events
protected void forward_events(IoFilter.NextFilter next)
-
schedule_task
protected void schedule_task(IoFilter.NextFilter next)
Schedule a SSLEngine task for execution, either using an Executor, or immediately.- Parameters:
next- The next filter to call
-
execute_task
protected void execute_task(IoFilter.NextFilter next)
Execute a SSLEngine task. We may have more than one. If we get any exception during the processing, an error is stored and thrown.- Parameters:
next- The next filer in the chain
-
-