Package io.netty.handler.ssl
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 ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final SniHandler.Selection
protected final AsyncMapping
<String, SslContext> private SniHandler.Selection
Fields inherited from class io.netty.handler.ssl.AbstractSniHandler
handshakeTimeoutMillis
Fields inherited from class io.netty.handler.ssl.SslClientHelloHandler
MAX_CLIENT_HELLO_LENGTH
Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
-
Constructor Summary
ConstructorsConstructorDescriptionSniHandler
(AsyncMapping<? super String, ? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
SniHandler
(AsyncMapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
SniHandler
(AsyncMapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
SniHandler
(DomainNameMapping<? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
SniHandler
(Mapping<? super String, ? extends SslContext> mapping) Creates a SNI detection handler with configuredSslContext
maintained byMapping
SniHandler
(Mapping<? super String, ? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContext
maintained byMapping
SniHandler
(Mapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContext
maintained 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 SslHandler
newSslHandler
(SslContext context, ByteBufAllocator allocator) protected final void
onLookupComplete
(ChannelHandlerContext ctx, String hostname, Future<SslContext> future) Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)
Future
.protected void
replaceHandler
(ChannelHandlerContext ctx, String hostname, SslContext sslContext) The default implementation of this method will simply replacethis
SniHandler
instance with aSslHandler
.Methods inherited from class io.netty.handler.ssl.AbstractSniHandler
channelActive, handlerAdded, lookup, onLookupComplete
Methods inherited from class io.netty.handler.ssl.SslClientHelloHandler
bind, close, connect, decode, deregister, disconnect, flush, handlerRemoved0, read, write
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Field Details
-
EMPTY_SELECTION
-
mapping
-
selection
-
-
Constructor Details
-
SniHandler
Creates a SNI detection handler with configuredSslContext
maintained 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 configuredSslContext
maintained byMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
maxClientHelloLength
- the maximum length of the client hello messagehandshakeTimeoutMillis
- the handshake timeout in milliseconds
-
SniHandler
Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
-
SniHandler
Creates a SNI detection handler with configuredSslContext
maintained 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 configuredSslContext
maintained byAsyncMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
maxClientHelloLength
- 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 configuredSslContext
maintained byMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
handshakeTimeoutMillis
- the handshake timeout in milliseconds
-
SniHandler
public SniHandler(AsyncMapping<? super String, ? extends SslContext> mapping, long handshakeTimeoutMillis) Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
handshakeTimeoutMillis
- 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:
lookup
in classAbstractSniHandler<SslContext>
- Throws:
Exception
- See Also:
-
onLookupComplete
protected final void onLookupComplete(ChannelHandlerContext ctx, String hostname, Future<SslContext> future) throws Exception Description copied from class:AbstractSniHandler
Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)
Future
.- Specified by:
onLookupComplete
in 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 replacethis
SniHandler
instance 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 newSslHandler
using the givenSslContext
andByteBufAllocator
. Users may override this method to implement custom behavior.
-