Package org.apache.mina.filter.ssl
Class SSLHandlerG1
java.lang.Object
org.apache.mina.filter.ssl.SslHandler
org.apache.mina.filter.ssl.SSLHandlerG1
Default implementation of SSLHandler
The 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
FieldsModifier and TypeFieldDescriptionprotected static final booleanEnable asynchronous tasks.protected static final booleanEnable aggregation of handshake messagesprotected static final booleanWrites the SSL Closure messages after a close requestprotected static final intMaximum number of queued messages waiting for encodingprotected static final intMaximum number of messages waiting acknowledgementprotected final Deque<FilterEvent> Pending filter events for dispatchingprotected booleanIndicates whether the first handshake was completedprotected booleanIndicated whether the first handshake was startedprotected booleanIndicates that the outbound is closingprotected booleanIndicates that previously queued messages should be written before closingprotected SSLExceptionCaptured error stateDecoded buffers ready for processing downstreamprotected ThreadHolds the decoder thread reference; used for recursion detection introduced by a delegated taskprotected final Deque<EncryptedWriteRequest> Encoded buffers ready for processing upstreamFields 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
ConstructorsConstructorDescriptionSSLHandlerG1(SSLEngine sslEngine, Executor executor, IoSession session) Instantiates a new handler -
Method Summary
Modifier and TypeMethodDescriptionvoidack(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 a SSLEngine task.protected voidMarks the handshake as complete and emits any signalsvoidflush(IoFilter.NextFilter next) protected voidFlushes the encode queueprotected voidprotected voidprotected voidbooleanbooleanisOpen()voidopen(IoFilter.NextFilter next) Opens the encryption session, this may include sending the initial handshake messageprotected voidvoidreceive(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 a SSLEngine task for execution, either using an Executor, or immediately.protected voidstore_pending_error(SSLException sslException) Store any error we've got during the handshake or message handlingprotected voidProcess 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 booleanAttempts 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 Details
-
MAX_QUEUED_MESSAGES
protected static final int MAX_QUEUED_MESSAGESMaximum number of queued messages waiting for encoding- See Also:
-
MAX_UNACK_MESSAGES
protected static final int MAX_UNACK_MESSAGESMaximum number of messages waiting acknowledgement- See Also:
-
ENABLE_SOFT_CLOSURE
protected static final boolean ENABLE_SOFT_CLOSUREWrites the SSL Closure messages after a close request- See Also:
-
ENABLE_FAST_HANDSHAKE
protected static final boolean ENABLE_FAST_HANDSHAKEEnable aggregation of handshake messages- See Also:
-
ENABLE_ASYNC_TASKS
protected static final boolean ENABLE_ASYNC_TASKSEnable asynchronous tasks. Default to false.- See Also:
-
mHandshakeComplete
protected boolean mHandshakeCompleteIndicates whether the first handshake was completed -
mHandshakeStarted
protected boolean mHandshakeStartedIndicated whether the first handshake was started -
mOutboundClosing
protected boolean mOutboundClosingIndicates that the outbound is closing -
mOutboundLinger
protected boolean mOutboundLingerIndicates that previously queued messages should be written before closing -
mReceiveThread
Holds the decoder thread reference; used for recursion detection introduced by a delegated task -
mWriteQueue
Encoded buffers ready for processing upstream -
mReceiveQueue
Decoded buffers ready for processing downstream -
mEventQueue
Pending filter events for dispatching -
mPendingError
Captured error state
-
-
Constructor Details
-
SSLHandlerG1
Instantiates a new handler- Parameters:
sslEngine- The SSLEngine instanceexecutor- The executor instance to use to process taskssession- The session to handle
-
-
Method Details
-
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
Opens the encryption session, this may include sending the initial handshake message- Specified by:
openin classSslHandler- Parameters:
next- The next filter- Throws:
SSLException- The thrown exception
-
open_start
- Throws:
SSLException
-
receive
Decodes encrypted messages and passes the results to thenextfilter.- Specified by:
receivein classSslHandler- Parameters:
next- The next filtermessage- the received message- Throws:
SSLException- The thrown exception
-
receive_start
- Throws:
SSLException
-
receive_loop
Process a received message- Parameters:
next- The next filtermessage- The message to process- Throws:
SSLException- If we get some error while processing the message
-
ack
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:
SSLException- The thrown exception
-
ack_start
- Throws:
SSLException
-
write
public void write(IoFilter.NextFilter next, WriteRequest request) throws 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:
SSLException- The thrown exceptionWriteRejectedException- when the session is closing
-
write_start
protected void write_start(IoFilter.NextFilter next, WriteRequest request) throws SSLException, WriteRejectedException - Throws:
SSLExceptionWriteRejectedException
-
write_loop
Attempts to encode the WriteRequest and write the data to the IoSession- Parameters:
next-request-- Returns:
trueif the WriteRequest was fully consumed; otherwisefalse- Throws:
SSLException
-
write_handshake
Attempts to generate a handshake message and write the data to the IoSession- Parameters:
next-- Returns:
trueif a message was generated and written- Throws:
SSLException
-
write_handshake_loop
protected boolean write_handshake_loop(IoFilter.NextFilter next, IoBuffer source, IoBuffer dest) throws 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:
SSLException
-
finish_handshake
Marks the handshake as complete and emits any signals- Parameters:
next-- Throws:
SSLException
-
flush
- Throws:
SSLException
-
flush_start
Flushes the encode queue- Parameters:
next-- Throws:
SSLException
-
close
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:
SSLException- The thrown exception
-
close_start
- Throws:
SSLException
-
throw_pending_error
Process the pending error and loop to send the associated alert if we have some.- Parameters:
next- The next filter in the chain- Throws:
SSLException- The rethrown pending error
-
store_pending_error
Store any error we've got during the handshake or message handling- Parameters:
sslException- The exfeption to store
-
forward_received
-
forward_writes
-
forward_events
-
schedule_task
Schedule a SSLEngine task for execution, either using an Executor, or immediately.- Parameters:
next- The next filter to call
-
execute_task
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
-