Channel. Please refer
to the "SecureChat" example in the distribution or the web
site for the detailed usage.
Beside using the handshake Future to get notified about the completion of the handshake it's
also possible to detect it by implement the
ChannelHandler#channelInboundEvent(ChannelHandlerContext, Object)
method and check for a SslHandshakeCompletionEvent.
The handshake will be automatically issued for you once the Channel is active and
SSLEngine#getUseClientMode() returns true.
So no need to bother with it by your self.
To close the SSL session, the closeOutbound() method should be
called to send the close_notify message to the remote peer. One
exception is when you close the Channel - SslHandler
intercepts the close request and send the close_notify message
before the channel closure automatically. Once the SSL session is closed,
it is not reusable, and consequently you should create a new
SslHandler with a new SSLEngine as explained in the
following section.
To restart the SSL session, you must remove the existing closed
SslHandler from the ChannelPipeline, insert a new
SslHandler with a new SSLEngine into the pipeline,
and start the handshake process as described in the first section.
StartTLS is the communication pattern that secures the wire in the middle of the plaintext connection. Please note that it is different from SSL · TLS, that secures the wire from the beginning of the connection. Typically, StartTLS is composed of three steps:
SslHandler instance with startTls flag set
to true,SslHandler to the ChannelPipeline, andSslHandler before sending
the StartTLS response. Otherwise the client can send begin SSL handshake
before SslHandler is inserted to the ChannelPipeline, causing
data corruption.
The client-side implementation is much simpler.
SslHandler instance with startTls flag set
to false,SslHandler to the ChannelPipeline, andBecause of a known issue with the current implementation of the SslEngine that comes with Java it may be possible that you see blocked IO-Threads while a full GC is done.
So if you are affected you can workaround this problem by adjust the cache settings like shown below:
SslContext context = ...;
context.getServerSessionContext().setSessionCacheSize(someSaneSize);
context.getServerSessionContext().setSessionTime(someSameTimeout);
What values to use here depends on the nature of your application and should be set based on monitoring and debugging of it. For more details see #832 in our issue tracker.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class | |
| private static enum | |
| private class | SslHandler.SslHandlerCoalescingBufferQueue
Each call to SSL_write will introduce about ~100 bytes of overhead. |
| private class | SslHandler.SslTasksRunner
|
| Modifier and Type | Field and Description |
|---|---|
| private volatile long | |
| private volatile long | |
| private volatile ChannelHandlerContext | |
| private final Executor | |
| private final SSLEngine | |
| private final SslHandler. | |
| private final EngineWrapper | engineWrapper
Used for converting |
| private Promise | |
| private volatile long | |
| private static final Pattern | |
| private static final Pattern | |
| private final boolean | |
| private static final InternalLogger | |
| private static final int | MAX_PLAINTEXT_LENGTH
2^14 which is the maximum sized plaintext chunk allowed by the TLS RFC. |
| private int | |
| private SslHandler. | |
| private final Promise | |
| private final SslHandler. | |
| private final SslHandler. | |
| private final boolean | |
| private short | |
| private static final int | |
| private static final int | STATE_FIRE_CHANNEL_READ
This flag is used to determine if we need to call |
| private static final int | |
| private static final int | |
| private static final int | STATE_NEEDS_FLUSH
Set by wrap*() methods when something is produced. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv volatile int |
| Access | Constructor and Description |
|---|---|
| public | SslHandler(SSLEngine
the engine)SSLEngine this handler will useCreates a new instance which runs all delegated tasks directly on the |
| public | SslHandler(SSLEngine
the engine, boolean SSLEngine this handler will usetrue if the first write request shouldn't be
encrypted by the SSLEngineCreates a new instance which runs all delegated tasks directly on the |
| public | SslHandler(SSLEngine
the engine, Executor SSLEngine this handler will usethe delegatedTaskExecutor)Executor that will be used to execute tasks that are returned by
SSLEngine#getDelegatedTask().Creates a new instance. |
| public | SslHandler(SSLEngine
the engine, boolean SSLEngine this handler will usetrue if the first write request shouldn't be
encrypted by the SSLEnginethe delegatedTaskExecutor)Executor that will be used to execute tasks that are returned by
SSLEngine#getDelegatedTask().Creates a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| private Buffer | allocate(ChannelHandlerContext ctx, int capacity)
Allocate buffer of the right direct/not-direct type that the SSLEngine prefers. |
| private Buffer | allocateOutNetBuf(ChannelHandlerContext ctx, int pendingBytes, int numComponents)
Allocates an outbound network buffer for |
| public String | Returns: the protocol name ornull if application-level protocol has not been negotiatedReturns the name of the current application-level protocol. |
| private void | |
| public void | channelActive(final ChannelHandlerContext ctx)
Overrides default io. |
| public void | channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Overrides default io. Throwable was thrown when handling inbound events.
|
| public void | channelInactive(ChannelHandlerContext ctx)
Overrides io. Overrides default io. Channel of the ChannelHandlerContext was registered is now inactive and reached its
end of lifetime.
|
| public void | channelReadComplete(ChannelHandlerContext ctx)
Overrides io. Overrides default io. channelRead(ChannelHandlerContext, Object).
|
| private void | |
| private void | |
| public Future | close(final ChannelHandlerContext
the ctx)ChannelHandlerContext for which the close operation is madeOverrides default io. |
| public Future | closeOutbound()
Sends an SSL |
| private void | |
| private Future | |
| protected void | decode(ChannelHandlerContext
the ctx, Buffer ChannelHandlerContext which this ByteToMessageDecoder belongs tothe in)Buffer from which to read dataImplements abstract io. Buffer to another.
|
| private void | |
| private void | |
| public Future | disconnect(final ChannelHandlerContext
the ctx)ChannelHandlerContext for which the disconnect operation is madeOverrides default io. |
| public SSLEngine | |
| private static void | |
| private void | |
| private void | |
| private void | |
| public void | flush(ChannelHandlerContext
the ctx)ChannelHandlerContext for which the flush operation is madeOverrides default io. |
| private void | |
| private void | |
| private void | |
| public final long | getCloseNotifyFlushTimeoutMillis()
Gets the timeout for flushing the close_notify that was triggered by closing the
|
| public final long | getCloseNotifyReadTimeoutMillis()
Gets the timeout (in ms) for receiving the response for the close_notify that was triggered by closing the
|
| public long | |
| public long | |
| private SslHandler. | |
| public void | handlerAdded0(final ChannelHandlerContext ctx)
Overrides io. |
| public void | handlerRemoved0(ChannelHandlerContext ctx)
Overrides io. ByteToMessageDecoder was removed from the actual context and it doesn't
handle events anymore.
|
| private void | |
| private void | handshake(boolean
Set to flushAtEnd)true if the outbound buffer should be flushed (written to the network) at the
end. Set to false if the handshake will be flushed later, e.g. as part of TCP Fast Open
connect.Performs TLS (re)negotiation. |
| public Future | Returns: theFuture for the initial TLS handshake if renegotiate() was not invoked.
The Future for the most recent TLS renegotiation otherwise.Returns a |
| private boolean | ignoreException(Throwable t)
Checks if the given |
| private static boolean | |
| public static boolean | isEncrypted(Buffer
The buffer)Buffer to read from. Be aware that it must have at least 5 bytes to read,
otherwise it will throw an IllegalArgumentException.Returns |
| private boolean | |
| private static IllegalStateException | |
| private void | |
| public long | pendingOutboundBytes(ChannelHandlerContext
the ctx)ChannelHandlerContext for which the operation is made.Overrides default io. ChannelHandler.
|
| public void | read(ChannelHandlerContext
the ctx, ReadBufferAllocator ChannelHandlerContext for which the read operation is madeThe readBufferAllocator)ReadBufferAllocator that should be used to allocate a Buffer
if needed (for reading the data).Overrides default io. EventLoop.
|
| private void | |
| private void | |
| public Future | |
| public Future | |
| private void | |
| private boolean | runDelegatedTasks(boolean inUnwrap)
Will either run the delegated task directly calling |
| private void | |
| public final void | setCloseNotifyFlushTimeout(long closeNotifyFlushTimeout, TimeUnit unit)
Sets the timeout for flushing the close_notify that was triggered by closing the
|
| public final void | setCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis)
|
| public final void | setCloseNotifyReadTimeout(long closeNotifyReadTimeout, TimeUnit unit)
Sets the timeout for receiving the response for the close_notify that was triggered by closing the
|
| public final void | setCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis)
|
| public void | setCloseNotifyTimeout(long closeNotifyTimeout, TimeUnit unit)
Deprecated
use
setCloseNotifyFlushTimeout(long, TimeUnit)
|
| public void | setCloseNotifyTimeoutMillis(long closeNotifyFlushTimeoutMillis)
Deprecated
use
setCloseNotifyFlushTimeoutMillis(long)
|
| private void | setHandshakeFailure(ChannelHandlerContext ctx, Throwable cause)
Notify all the handshake futures about the failure during the handshake. |
| private void | setHandshakeFailure(ChannelHandlerContext ctx, Throwable cause, boolean closeInbound, boolean notify, boolean alwaysFlushAndClose)
Notify all the handshake futures about the failure during the handshake. |
| private void | |
| private boolean | Returns: true if handshakePromise was set successfully and a SslHandshakeCompletionEvent
was fired. false otherwise.Notify all the handshake futures about the successfully handshake |
| private boolean | |
| public void | |
| public void | |
| private void | |
| private void | |
| public final void | setWrapDataSize(int
the number of bytes which will be passed to each
wrapDataSize)SSLEngine#wrap(ByteBuffer[], int, int, ByteBuffer) call.Sets the number of bytes to pass to each |
| public Future | |
| private void | |
| private int | |
| private int | unwrapNonAppData(ChannelHandlerContext ctx)
Calls |
| private void | |
| private SSLEngineResult | |
| private void | |
| private boolean | wrapNonAppData(final ChannelHandlerContext ctx, boolean inUnwrap)
This method will not call
|
| public Future | write(final ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |