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.Sharable -
Field Summary
FieldsFields inherited from class AbstractSniHandler
handshakeTimeoutMillisFields inherited from class SslClientHelloHandler
MAX_CLIENT_HELLO_LENGTHFields inherited from class ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_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, onLookupCompleteMethods inherited from class SslClientHelloHandler
bind, close, connect, decode, deregister, disconnect, flush, handlerRemoved0, read, writeMethods inherited from class ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredMethods inherited from class ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
handlerRemoved
-
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.
-