Class SniHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
Enables SNI (Server Name Indication) extension for server side SSL. For clients support SNI, the server could have multiple host name bound on a single IP. The client will send host name in the handshake data so server could decide which certificate to choose for the host name.
-
Nested Class Summary
Nested classes/interfaces inherited from class ByteToMessageDecoder
ByteToMessageDecoder.CumulatorNested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
Field Summary
FieldsFields inherited from class AbstractSniHandler
handshakeTimeoutMillisFields inherited from class SslClientHelloHandler
MAX_CLIENT_HELLO_LENGTHModifier and TypeFieldDescriptionstatic final intThe maximum length of client hello message as defined by RFC5246.Fields inherited from class ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATORModifier and TypeFieldDescriptionstatic final ByteToMessageDecoder.CumulatorCumulateByteBufs by add them to aCompositeByteBufand so do no memory copy whenever possible.static final ByteToMessageDecoder.Cumulator -
Constructor Summary
ConstructorsConstructorDescriptionSniHandler(AsyncMapping<? super String, ? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContextmaintained byAsyncMappingSniHandler(AsyncMapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byAsyncMappingSniHandler(AsyncMapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byAsyncMappingSniHandler(DomainNameMapping<? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContextmaintained byDomainNameMappingSniHandler(Mapping<? super String, ? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContextmaintained byMappingSniHandler(Mapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byMappingSniHandler(Mapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byMapping -
Method Summary
Modifier and TypeMethodDescriptionhostname()protected Future<SslContext> lookup(ChannelHandlerContext ctx, String hostname) The default implementation will simply callAsyncMapping.map(Object, Promise)but users can override this method to implement custom behavior.protected SslHandlernewSslHandler(SslContext context, ByteBufAllocator allocator) protected final voidonLookupComplete(ChannelHandlerContext ctx, String hostname, Future<SslContext> future) Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)Future.protected voidreplaceHandler(ChannelHandlerContext ctx, String hostname, SslContext sslContext) The default implementation of this method will simply replacethisSniHandlerinstance with aSslHandler.Methods inherited from class AbstractSniHandler
channelActive, handlerAdded, lookup, onLookupCompleteModifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidDo nothing by default, sub-classes may override this method.protected Future<SslContext> lookup(ChannelHandlerContext ctx, ByteBuf clientHello) Kicks off a lookup for the givenClientHelloand returns aFuturewhich in turn will notify theSslClientHelloHandler.onLookupComplete(ChannelHandlerContext, Future)on completion.protected voidonLookupComplete(ChannelHandlerContext ctx, Future<SslContext> future) Called upon completion of theSslClientHelloHandler.lookup(ChannelHandlerContext, ByteBuf)Future.Methods inherited from class SslClientHelloHandler
bind, close, connect, decode, deregister, disconnect, flush, handlerRemoved0, read, writeModifier and TypeMethodDescriptionvoidbind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) Called once a bind operation is made.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) Called once a close operation is made.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.voidderegister(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.voidCalled once a flush operation is made.protected voidGets called after theByteToMessageDecoderwas removed from the actual context and it doesn't handle events anymore.voidInterceptsChannelHandlerContext.read().voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) Called once a write operation is made.Methods inherited from class ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredModifier and TypeMethodDescriptionprotected intReturns the actual number of readable bytes in the internal cumulative buffer of this decoder.protected voidcallDecode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) Called once data should be decoded from the givenByteBuf.voidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelRead(ChannelHandlerContext ctx, Object input) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected voiddecodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) Is called one last time when theChannelHandlerContextgoes in-active.protected final voidfinal voidDo nothing by default, sub-classes may override this method.protected ByteBufReturns the internal cumulative buffer of this decoder.booleanIftruethen only one message is decoded on eachByteToMessageDecoder.channelRead(ChannelHandlerContext, Object)call.voidsetCumulator(ByteToMessageDecoder.Cumulator cumulator) Set theByteToMessageDecoder.Cumulatorto use for cumulate the receivedByteBufs.voidsetDiscardAfterReads(int discardAfterReads) Set the number of reads after whichByteBuf.discardSomeReadBytes()are called and so free up memory.voidsetSingleDecode(boolean singleDecode) If set then only one message is decoded on eachByteToMessageDecoder.channelRead(ChannelHandlerContext, Object)call.voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtModifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelUnregistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelWritabilityChanged()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableModifier and TypeMethodDescriptionprotected voidbooleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
Field Details
-
mapping
-
-
Constructor Details
-
SniHandler
Creates a SNI detection handler with configuredSslContextmaintained byMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(Mapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byMapping- Parameters:
mapping- the mapping of domain name toSslContextmaxClientHelloLength- the maximum length of the client hello messagehandshakeTimeoutMillis- the handshake timeout in milliseconds
-
SniHandler
Creates a SNI detection handler with configuredSslContextmaintained byDomainNameMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
Creates a SNI detection handler with configuredSslContextmaintained byAsyncMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(AsyncMapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byAsyncMapping- Parameters:
mapping- the mapping of domain name toSslContextmaxClientHelloLength- the maximum length of the client hello messagehandshakeTimeoutMillis- the handshake timeout in milliseconds
-
SniHandler
public SniHandler(Mapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byMapping- Parameters:
mapping- the mapping of domain name toSslContexthandshakeTimeoutMillis- the handshake timeout in milliseconds
-
SniHandler
public SniHandler(AsyncMapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContextmaintained byAsyncMapping- Parameters:
mapping- the mapping of domain name toSslContexthandshakeTimeoutMillis- the handshake timeout in milliseconds
-
-
Method Details
-
hostname
- Returns:
- the selected hostname
-
sslContext
- Returns:
- the selected
SslContext
-
lookup
The default implementation will simply callAsyncMapping.map(Object, Promise)but users can override this method to implement custom behavior.- Specified by:
lookupin classAbstractSniHandler<SslContext>- Throws:
Exception- See Also:
-
onLookupComplete
protected final void onLookupComplete(ChannelHandlerContext ctx, String hostname, Future<SslContext> future) throws Exception Description copied from class:AbstractSniHandlerCalled upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)Future.- Specified by:
onLookupCompletein classAbstractSniHandler<SslContext>- Throws:
Exception- See Also:
-
replaceHandler
protected void replaceHandler(ChannelHandlerContext ctx, String hostname, SslContext sslContext) throws Exception The default implementation of this method will simply replacethisSniHandlerinstance with aSslHandler. Users may override this method to implement custom behavior. Please be aware that this method may get called after a client has already disconnected and custom implementations must take it into consideration when overriding this method. It's also possible for the hostname argument to benull.- Throws:
Exception
-
newSslHandler
Returns a newSslHandlerusing the givenSslContextandByteBufAllocator. Users may override this method to implement custom behavior.
-