Channel. Please refer
to the "SecureChat" example in the distribution or the web
site for the detailed usage.
Beside using the handshake ChannelFuture to get notified about the completion of the handshake it's
also possible to detect it by implement the
ChannelInboundHandler#userEventTriggered(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.
Each call to SSL_write will introduce about ~100 bytes of overhead. |
| private class | SslHandler.
|
| 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 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 ByteBuffer[] | singleBuffer
Used if |
| private final SslHandler. | |
| 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 ByteBuf | allocate(ChannelHandlerContext ctx, int capacity)
Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies
in |
| private ByteBuf | 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 | |
| private static boolean | |
| public void | bind(ChannelHandlerContext
the ctx, SocketAddress ChannelHandlerContext for which the bind operation is madethe localAddress, ChannelPromise SocketAddress to which it should boundthe promise)ChannelPromise to notify once the operation completesImplements io. |
| public void | channelActive(final ChannelHandlerContext ctx)
Overrides io. Implements io. |
| public void | channelInactive(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandlerContext#fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| public void | channelReadComplete(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandlerContext#fireChannelReadComplete() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| private void | |
| private void | |
| public ChannelFuture | |
| public ChannelFuture | |
| public void | close(final ChannelHandlerContext
the ctx, final ChannelPromise ChannelHandlerContext for which the close operation is madethe promise)ChannelPromise to notify once the operation completesImplements io. |
| public ChannelFuture | closeOutbound()
Sends an SSL |
| public ChannelFuture | closeOutbound(final ChannelPromise promise)
Sends an SSL |
| private void | |
| private void | closeOutboundAndChannel(final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect)
|
| public void | connect(ChannelHandlerContext
the ctx, SocketAddress ChannelHandlerContext for which the connect operation is madethe remoteAddress, SocketAddress SocketAddress to which it should connectthe localAddress, ChannelPromise SocketAddress which is used as source on connectthe promise)ChannelPromise to notify once the operation completesImplements io. |
| protected void | decode(ChannelHandlerContext
the ctx, ByteBuf ChannelHandlerContext which this ByteToMessageDecoder belongs tothe in, List<Object> ByteBuf from which to read datathe out)List to which decoded messages should be addedImplements abstract io. ByteBuf to an other.
|
| private void | |
| private void | |
| public void | deregister(ChannelHandlerContext
the ctx, ChannelPromise ChannelHandlerContext for which the close operation is madethe promise)ChannelPromise to notify once the operation completesImplements io. EventLoop.
|
| public void | disconnect(final ChannelHandlerContext
the ctx, final ChannelPromise ChannelHandlerContext for which the disconnect operation is madethe promise)ChannelPromise to notify once the operation completesImplements io. |
| public SSLEngine | |
| public void | exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Overrides io. Implements io. Throwable was thrown.
|
| private void | |
| private void | |
| private void | |
| private void | |
| public void | flush(ChannelHandlerContext
the ctx)ChannelHandlerContext for which the flush operation is madeImplements 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 | handlerAdded(final ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandler was added to the actual context and it's ready to handle events.
|
| 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(ByteBuf
The buffer)ByteBuf 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 void | read(ChannelHandlerContext ctx)
Implements io. ChannelHandlerContext#read().
|
| 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 | safeClose(final ChannelHandlerContext ctx, final ChannelFuture flushFuture, final ChannelPromise promise)
|
| 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 static ByteBuffer | |
| private int | |
| private int | unwrapNonAppData(ChannelHandlerContext ctx)
Calls |
| private void | |
| private SSLEngineResult | |
| private void | |
| private SSLEngineResult | |
| private boolean | wrapNonAppData(final ChannelHandlerContext ctx, boolean inUnwrap)
This method will not call
|
| public void | write(final ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg, ChannelPromise the promise)ChannelPromise to notify once the operation completesImplements io. |