Class SslHandler
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
Channel. Please refer
to the "SecureChat" example in the distribution or the web
site for the detailed usage.
Beginning the handshake
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.
Handshake
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.
Closing the session
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.
Restarting the session
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.
Implementing StartTLS
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:
- Client sends a StartTLS request to server.
- Server sends a StartTLS response to client.
- Client begins SSL handshake.
- create a new
SslHandlerinstance withstartTlsflag set totrue, - insert the
SslHandlerto theChannelPipeline, and - write a StartTLS response.
SslHandler 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.
- Write a StartTLS request,
- wait for the StartTLS response,
- create a new
SslHandlerinstance withstartTlsflag set tofalse, - insert the
SslHandlerto theChannelPipeline, and - Initiate SSL handshake.
Known issues
Because 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classprivate final classprivate static enumprivate final classRunnablethat will be scheduled on thedelegatedTaskExecutorand will take care of resume work on theEventExecutoronce the task was executed.Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.CumulatorNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate longprivate ChannelHandlerContextprivate final Executorprivate final SSLEngineprivate final SslHandler.SslEngineTypeprivate longprivate static final Patternprivate static final Patternprivate final booleanprivate static final InternalLoggerprivate static final int2^14 which is the maximum sized plaintext chunk allowed by the TLS RFC.private intprivate SslHandlerCoalescingBufferQueueprivate final ResumptionControllerprivate final ByteBuffer[]Used ifSSLEngine.wrap(ByteBuffer[], ByteBuffer)andSSLEngine.unwrap(ByteBuffer, ByteBuffer[])should be called with aByteBufthat is only backed by oneByteBufferto reduce the object creation.private final SslHandler.LazyChannelPromiseprivate final SslHandler.SslTasksRunnerprivate final SslHandler.SslTasksRunnerprivate final booleanprivate shortprivate static final intprivate static final intThis flag is used to determine if we need to callChannelHandlerContext.read()to consume more data whenChannelConfig.isAutoRead()isfalse.private static final intprivate static final intprivate static final intSet by wrap*() methods when something is produced.private static final intprivate static final intprivate static final intprivate static final intprivate static final int(package private) intFields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR -
Constructor Summary
ConstructorsConstructorDescriptionSslHandler(SSLEngine engine) Creates a new instance which runs all delegated tasks directly on theEventExecutor.SslHandler(SSLEngine engine, boolean startTls) Creates a new instance which runs all delegated tasks directly on theEventExecutor.SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor) Creates a new instance.SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor, ResumptionController resumptionController) SslHandler(SSLEngine engine, Executor delegatedTaskExecutor) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddCloseListener(ChannelFuture future, ChannelPromise promise) private ByteBufallocate(ChannelHandlerContext ctx, int capacity) Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies inOpenSslEngine.private ByteBufallocateOutNetBuf(ChannelHandlerContext ctx, int pendingBytes, int numComponents) Allocates an outbound network buffer forSSLEngine.wrap(ByteBuffer, ByteBuffer)which can encrypt the specified amount of pending bytes.Returns the name of the current application-level protocol.private voidvoidbind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) Called once a bind operation is made.voidIssues an initial TLS handshake once connected when used in client-modevoidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.private voidprivate voidclearState(int bit) close()Deprecated.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) Called once a close operation is made.close(ChannelPromise promise) Deprecated.Sends an SSLclose_notifymessage to the specified channel and destroys the underlyingSSLEngine.closeOutbound(ChannelPromise promise) Sends an SSLclose_notifymessage to the specified channel and destroys the underlyingSSLEngine.private voidcloseOutbound0(ChannelPromise promise) private voidcloseOutboundAndChannel(ChannelHandlerContext ctx, ChannelPromise promise, boolean disconnect) voidconnect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Called once a connect operation is made.protected voiddecode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) Decode the from oneByteBufto an other.private voidprivate voidvoidderegister(ChannelHandlerContext ctx, ChannelPromise promise) Called once a deregister operation is made from the current registeredEventLoop.voiddisconnect(ChannelHandlerContext ctx, ChannelPromise promise) Called once a disconnect operation is made.engine()Returns theSSLEnginewhich is used by this handler.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.private voidexecuteChannelRead(ChannelHandlerContext ctx, ByteBuf decodedOut) private voidexecuteDelegatedTask(boolean inUnwrap) private voidprivate voidvoidCalled once a flush operation is made.private voidflush(ChannelHandlerContext ctx, ChannelPromise promise) private voidprivate voidfinal longGets the timeout for flushing the close_notify that was triggered by closing theChannel.final longGets the timeout (in ms) for receiving the response for the close_notify that was triggered by closing theChannel.longDeprecated.longprivate SslHandler.SslTasksRunnergetTaskRunner(boolean inUnwrap) voidDo nothing by default, sub-classes may override this method.voidGets called after theByteToMessageDecoderwas removed from the actual context and it doesn't handle events anymore.private voidhandleUnwrapThrowable(ChannelHandlerContext ctx, Throwable cause) private voidhandshake(boolean flushAtEnd) Performs TLS (re)negotiation.Returns aFuturethat will get notified once the current TLS handshake completes.private booleanChecks if the givenThrowablecan be ignore and just "swallowed" When an ssl connection is closed a close_notify message is sent.private static booleaninEventLoop(Executor executor) static booleanisEncrypted(ByteBuf buffer) Deprecated.static booleanisEncrypted(ByteBuf buffer, boolean probeSSLv2) Returnstrueif the givenByteBufis encrypted.private booleanisStateSet(int bit) private static IllegalStateExceptionprivate voidnotifyClosePromise(Throwable cause) voidInterceptsChannelHandlerContext.read().private voidprivate voidreleaseAndFailAll(ChannelHandlerContext ctx, Throwable cause) Performs TLS renegotiation.renegotiate(Promise<Channel> promise) Performs TLS renegotiation.private voidrenegotiateOnEventLoop(Promise<Channel> newHandshakePromise) private booleanrunDelegatedTasks(boolean inUnwrap) Will either run the delegated task directly callingRunnable.run()and returntrueor will offload the delegated task usingExecutor.execute(Runnable)and returnfalse.private voidsafeClose(ChannelHandlerContext ctx, ChannelFuture flushFuture, ChannelPromise promise) final voidsetCloseNotifyFlushTimeout(long closeNotifyFlushTimeout, TimeUnit unit) Sets the timeout for flushing the close_notify that was triggered by closing theChannel.final voidsetCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis) final voidsetCloseNotifyReadTimeout(long closeNotifyReadTimeout, TimeUnit unit) Sets the timeout for receiving the response for the close_notify that was triggered by closing theChannel.final voidsetCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis) voidsetCloseNotifyTimeout(long closeNotifyTimeout, TimeUnit unit) Deprecated.voidsetCloseNotifyTimeoutMillis(long closeNotifyFlushTimeoutMillis) Deprecated.private voidsetHandshakeFailure(ChannelHandlerContext ctx, Throwable cause) Notify all the handshake futures about the failure during the handshake.private voidsetHandshakeFailure(ChannelHandlerContext ctx, Throwable cause, boolean closeInbound, boolean notify, boolean alwaysFlushAndClose) Notify all the handshake futures about the failure during the handshake.private voidprivate booleanNotify all the handshake futures about the successfully handshakeprivate booleanvoidsetHandshakeTimeout(long handshakeTimeout, TimeUnit unit) voidsetHandshakeTimeoutMillis(long handshakeTimeoutMillis) private voidprivate voidsetState(int bit) final voidsetWrapDataSize(int wrapDataSize) Sets the number of bytes to pass to eachSSLEngine.wrap(ByteBuffer[], int, int, ByteBuffer)call.private voidstartHandshakeProcessing(boolean flushAtEnd) private static ByteBuffertoByteBuffer(ByteBuf out, int index, int len) private intunwrap(ChannelHandlerContext ctx, ByteBuf packet, int length) Unwraps inbound SSL records.private intCallsSSLEngine.unwrap(ByteBuffer, ByteBuffer)with an empty buffer to handle handshakes, etc.private SSLEngineResultwrap(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out) private voidwrap(ChannelHandlerContext ctx, boolean inUnwrap) private voidprivate SSLEngineResultwrapMultiple(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out) private booleanwrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) Called once a write operation is made.Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered, channelWritabilityChangedMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Field Details
-
logger
-
IGNORABLE_CLASS_IN_STACK
-
IGNORABLE_ERROR_MESSAGE
-
STATE_SENT_FIRST_MESSAGE
private static final int STATE_SENT_FIRST_MESSAGE- See Also:
-
STATE_FLUSHED_BEFORE_HANDSHAKE
private static final int STATE_FLUSHED_BEFORE_HANDSHAKE- See Also:
-
STATE_READ_DURING_HANDSHAKE
private static final int STATE_READ_DURING_HANDSHAKE- See Also:
-
STATE_HANDSHAKE_STARTED
private static final int STATE_HANDSHAKE_STARTED- See Also:
-
STATE_NEEDS_FLUSH
private static final int STATE_NEEDS_FLUSHSet by wrap*() methods when something is produced.channelReadComplete(ChannelHandlerContext)will check this flag, clear it, and call ctx.flush().- See Also:
-
STATE_OUTBOUND_CLOSED
private static final int STATE_OUTBOUND_CLOSED- See Also:
-
STATE_CLOSE_NOTIFY
private static final int STATE_CLOSE_NOTIFY- See Also:
-
STATE_PROCESS_TASK
private static final int STATE_PROCESS_TASK- See Also:
-
STATE_FIRE_CHANNEL_READ
private static final int STATE_FIRE_CHANNEL_READThis flag is used to determine if we need to callChannelHandlerContext.read()to consume more data whenChannelConfig.isAutoRead()isfalse.- See Also:
-
STATE_UNWRAP_REENTRY
private static final int STATE_UNWRAP_REENTRY- See Also:
-
MAX_PLAINTEXT_LENGTH
private static final int MAX_PLAINTEXT_LENGTH2^14 which is the maximum sized plaintext chunk allowed by the TLS RFC.- See Also:
-
ctx
-
engine
-
engineType
-
delegatedTaskExecutor
-
jdkCompatibilityMode
private final boolean jdkCompatibilityMode -
singleBuffer
Used ifSSLEngine.wrap(ByteBuffer[], ByteBuffer)andSSLEngine.unwrap(ByteBuffer, ByteBuffer[])should be called with aByteBufthat is only backed by oneByteBufferto reduce the object creation. -
startTls
private final boolean startTls -
resumptionController
-
sslTaskRunnerForUnwrap
-
sslTaskRunner
-
pendingUnencryptedWrites
-
handshakePromise
-
sslClosePromise
-
packetLength
private int packetLength -
state
private short state -
handshakeTimeoutMillis
private volatile long handshakeTimeoutMillis -
closeNotifyFlushTimeoutMillis
private volatile long closeNotifyFlushTimeoutMillis -
closeNotifyReadTimeoutMillis
private volatile long closeNotifyReadTimeoutMillis -
wrapDataSize
volatile int wrapDataSize
-
-
Constructor Details
-
SslHandler
Creates a new instance which runs all delegated tasks directly on theEventExecutor.- Parameters:
engine- theSSLEnginethis handler will use
-
SslHandler
Creates a new instance which runs all delegated tasks directly on theEventExecutor. -
SslHandler
Creates a new instance.- Parameters:
engine- theSSLEnginethis handler will usedelegatedTaskExecutor- theExecutorthat will be used to execute tasks that are returned bySSLEngine.getDelegatedTask().
-
SslHandler
Creates a new instance.- Parameters:
engine- theSSLEnginethis handler will usestartTls-trueif the first write request shouldn't be encrypted by theSSLEnginedelegatedTaskExecutor- theExecutorthat will be used to execute tasks that are returned bySSLEngine.getDelegatedTask().
-
SslHandler
SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor, ResumptionController resumptionController)
-
-
Method Details
-
getHandshakeTimeoutMillis
public long getHandshakeTimeoutMillis() -
setHandshakeTimeout
-
setHandshakeTimeoutMillis
public void setHandshakeTimeoutMillis(long handshakeTimeoutMillis) -
setWrapDataSize
Sets the number of bytes to pass to eachSSLEngine.wrap(ByteBuffer[], int, int, ByteBuffer)call.This value will partition data which is passed to write
write(ChannelHandlerContext, Object, ChannelPromise). The partitioning will work as follows:- If
wrapDataSize <= 0then we will write each data chunk as is. - If
wrapDataSize > data sizethen we will attempt to aggregate multiple data chunks together. - If
wrapDataSize > data sizeElse ifwrapDataSize <= data sizethen we will divide the data into chunks ofwrapDataSizewhen writing.
If the
SSLEnginedoesn't support a gather wrap operation (e.g.SslProvider.OPENSSL) then aggregating data before wrapping can help reduce the ratio between TLS overhead vs data payload which will lead to better goodput. Writing fixed chunks of data can also help target the underlying transport's (e.g. TCP) frame size. Under lossy/congested network conditions this may help the peer get full TLS packets earlier and be able to do work sooner, as opposed to waiting for the all the pieces of the TLS packet to arrive.- Parameters:
wrapDataSize- the number of bytes which will be passed to eachSSLEngine.wrap(ByteBuffer[], int, int, ByteBuffer)call.
- If
-
getCloseNotifyTimeoutMillis
Deprecated. -
setCloseNotifyTimeout
Deprecated. -
setCloseNotifyTimeoutMillis
Deprecated. -
getCloseNotifyFlushTimeoutMillis
public final long getCloseNotifyFlushTimeoutMillis() -
setCloseNotifyFlushTimeout
-
setCloseNotifyFlushTimeoutMillis
public final void setCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis) -
getCloseNotifyReadTimeoutMillis
public final long getCloseNotifyReadTimeoutMillis() -
setCloseNotifyReadTimeout
-
setCloseNotifyReadTimeoutMillis
public final void setCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis) -
engine
Returns theSSLEnginewhich is used by this handler. -
applicationProtocol
Returns the name of the current application-level protocol.- Returns:
- the protocol name or
nullif application-level protocol has not been negotiated
-
handshakeFuture
Returns aFuturethat will get notified once the current TLS handshake completes.- Returns:
- the
Futurefor the initial TLS handshake ifrenegotiate()was not invoked. TheFuturefor the most recent TLS renegotiation otherwise.
-
close
Deprecated.UsecloseOutbound() -
close
Deprecated. -
closeOutbound
Sends an SSLclose_notifymessage to the specified channel and destroys the underlyingSSLEngine. This will not close the underlyingChannel. If you want to also close theChanneluseChannelOutboundInvoker.close()orChannelOutboundInvoker.close() -
closeOutbound
Sends an SSLclose_notifymessage to the specified channel and destroys the underlyingSSLEngine. This will not close the underlyingChannel. If you want to also close theChanneluseChannelOutboundInvoker.close()orChannelOutboundInvoker.close() -
closeOutbound0
-
sslCloseFuture
Return theFuturethat will get notified if the inbound of theSSLEngineis closed. This method will return the sameFutureall the time.- See Also:
-
handlerRemoved0
Description copied from class:ByteToMessageDecoderGets called after theByteToMessageDecoderwas removed from the actual context and it doesn't handle events anymore.- Overrides:
handlerRemoved0in classByteToMessageDecoder- Throws:
Exception
-
bind
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception Description copied from interface:ChannelOutboundHandlerCalled once a bind operation is made.- Specified by:
bindin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the bind operation is madelocalAddress- theSocketAddressto which it should boundpromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
connect
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception Description copied from interface:ChannelOutboundHandlerCalled once a connect operation is made.- Specified by:
connectin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the connect operation is maderemoteAddress- theSocketAddressto which it should connectlocalAddress- theSocketAddresswhich is used as source on connectpromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
deregister
Description copied from interface:ChannelOutboundHandlerCalled once a deregister operation is made from the current registeredEventLoop.- Specified by:
deregisterin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
disconnect
Description copied from interface:ChannelOutboundHandlerCalled once a disconnect operation is made.- Specified by:
disconnectin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the disconnect operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
close
Description copied from interface:ChannelOutboundHandlerCalled once a close operation is made.- Specified by:
closein interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
read
Description copied from interface:ChannelOutboundHandlerInterceptsChannelHandlerContext.read().- Specified by:
readin interfaceChannelOutboundHandler- Throws:
Exception
-
newPendingWritesNullException
-
write
Description copied from interface:ChannelOutboundHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called- Specified by:
writein interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to writepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
flush
Description copied from interface:ChannelOutboundHandlerCalled once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Specified by:
flushin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the flush operation is made- Throws:
Exception- thrown if an error occurs
-
wrapAndFlush
- Throws:
SSLException
-
wrap
- Throws:
SSLException
-
wrapNonAppData
This method will not callsetHandshakeFailure(ChannelHandlerContext, Throwable, boolean, boolean, boolean)orsetHandshakeFailure(ChannelHandlerContext, Throwable).- Returns:
trueif this method ends onSSLEngineResult.HandshakeStatus.NOT_HANDSHAKING.- Throws:
SSLException
-
wrapMultiple
private SSLEngineResult wrapMultiple(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out) throws SSLException - Throws:
SSLException
-
wrap
private SSLEngineResult wrap(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out) throws SSLException - Throws:
SSLException
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelInactivein interfaceChannelInboundHandler- Overrides:
channelInactivein classByteToMessageDecoder- Throws:
Exception
-
exceptionCaught
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaughtin interfaceChannelHandler- Specified by:
exceptionCaughtin interfaceChannelInboundHandler- Overrides:
exceptionCaughtin classChannelInboundHandlerAdapter- Throws:
Exception
-
ignoreException
Checks if the givenThrowablecan be ignore and just "swallowed" When an ssl connection is closed a close_notify message is sent. After that the peer also sends close_notify however, it's not mandatory to receive the close_notify. The party who sent the initial close_notify can close the connection immediately then the peer will get connection reset error. -
isEncrypted
Deprecated.Returnstrueif the givenByteBufis encrypted. Be aware that this method will not increase the readerIndex of the givenByteBuf.- Parameters:
buffer- TheByteBufto read from. Be aware that it must have at least 5 bytes to read, otherwise it will throw anIllegalArgumentException.- Returns:
- encrypted
trueif theByteBufis encrypted,falseotherwise. - Throws:
IllegalArgumentException- Is thrown if the givenByteBufhas not at least 5 bytes to read.
-
isEncrypted
Returnstrueif the givenByteBufis encrypted. Be aware that this method will not increase the readerIndex of the givenByteBuf.- Parameters:
buffer- TheByteBufto read from. Be aware that it must have at least 5 bytes to read, otherwise it will throw anIllegalArgumentException.probeSSLv2-trueif the inputbuffermight be SSLv2. Iftrueis used this methods might produce false-positives in some cases so it's strongly suggested to usefalse.- Returns:
- encrypted
trueif theByteBufis encrypted,falseotherwise. - Throws:
IllegalArgumentException- Is thrown if the givenByteBufhas not at least 5 bytes to read.
-
decodeJdkCompatible
private void decodeJdkCompatible(ChannelHandlerContext ctx, ByteBuf in) throws NotSslRecordException - Throws:
NotSslRecordException
-
decodeNonJdkCompatible
-
handleUnwrapThrowable
-
decode
Description copied from class:ByteToMessageDecoderDecode the from oneByteBufto an other. This method will be called till either the inputByteBufhas nothing to read when return from this method or till nothing was read from the inputByteBuf.- Specified by:
decodein classByteToMessageDecoder- Parameters:
ctx- theChannelHandlerContextwhich thisByteToMessageDecoderbelongs toin- theByteBuffrom which to read dataout- theListto which decoded messages should be added- Throws:
SSLException
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadCompletein interfaceChannelInboundHandler- Overrides:
channelReadCompletein classByteToMessageDecoder- Throws:
Exception
-
channelReadComplete0
-
readIfNeeded
-
flushIfNeeded
-
unwrapNonAppData
CallsSSLEngine.unwrap(ByteBuffer, ByteBuffer)with an empty buffer to handle handshakes, etc.- Throws:
SSLException
-
unwrap
Unwraps inbound SSL records.- Throws:
SSLException
-
setHandshakeSuccessUnwrapMarkReentry
- Throws:
SSLException
-
executeNotifyClosePromise
-
executeChannelRead
-
toByteBuffer
-
inEventLoop
-
runDelegatedTasks
private boolean runDelegatedTasks(boolean inUnwrap) Will either run the delegated task directly callingRunnable.run()and returntrueor will offload the delegated task usingExecutor.execute(Runnable)and returnfalse. If the task is offloaded it will take care to resume its work on theEventExecutoronce there are no more tasks to process. -
getTaskRunner
-
executeDelegatedTask
private void executeDelegatedTask(boolean inUnwrap) -
executeDelegatedTask
-
setHandshakeSuccess
Notify all the handshake futures about the successfully handshake- Returns:
trueifhandshakePromisewas set successfully and aSslHandshakeCompletionEventwas fired.falseotherwise.- Throws:
SSLException
-
setHandshakeFailure
Notify all the handshake futures about the failure during the handshake. -
setHandshakeFailure
private void setHandshakeFailure(ChannelHandlerContext ctx, Throwable cause, boolean closeInbound, boolean notify, boolean alwaysFlushAndClose) Notify all the handshake futures about the failure during the handshake. -
setHandshakeFailureTransportFailure
-
releaseAndFailAll
-
notifyClosePromise
-
closeOutboundAndChannel
private void closeOutboundAndChannel(ChannelHandlerContext ctx, ChannelPromise promise, boolean disconnect) throws Exception - Throws:
Exception
-
flush
- Throws:
Exception
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-
startHandshakeProcessing
private void startHandshakeProcessing(boolean flushAtEnd) -
renegotiate
Performs TLS renegotiation. -
renegotiate
Performs TLS renegotiation. -
renegotiateOnEventLoop
-
handshake
private void handshake(boolean flushAtEnd) Performs TLS (re)negotiation.- Parameters:
flushAtEnd- Set totrueif the outbound buffer should be flushed (written to the network) at the end. Set tofalseif the handshake will be flushed later, e.g. as part of TCP Fast Open connect.
-
applyHandshakeTimeout
private void applyHandshakeTimeout() -
forceFlush
-
setOpensslEngineSocketFd
-
channelActive
Issues an initial TLS handshake once connected when used in client-mode- Specified by:
channelActivein interfaceChannelInboundHandler- Overrides:
channelActivein classChannelInboundHandlerAdapter- Throws:
Exception
-
safeClose
private void safeClose(ChannelHandlerContext ctx, ChannelFuture flushFuture, ChannelPromise promise) -
addCloseListener
-
allocate
Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies inOpenSslEngine. -
allocateOutNetBuf
Allocates an outbound network buffer forSSLEngine.wrap(ByteBuffer, ByteBuffer)which can encrypt the specified amount of pending bytes. -
isStateSet
private boolean isStateSet(int bit) -
setState
private void setState(int bit) -
clearState
private void clearState(int bit)
-
getCloseNotifyFlushTimeoutMillis()