Package io.netty.handler.ssl
Class SniHandler
- java.lang.Object
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
public class SniHandler extends AbstractSniHandler<SslContext>
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 io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncMapping<java.lang.String,SslContext>mapping-
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
Constructors Constructor Description SniHandler(AsyncMapping<? super java.lang.String,? extends SslContext> mapping)Creates a SNI detection handler with configuredSslContextmaintained byAsyncMappingSniHandler(AsyncMapping<? super java.lang.String,? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis)Creates a SNI detection handler with configuredSslContextmaintained byAsyncMappingSniHandler(AsyncMapping<? super java.lang.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 java.lang.String,? extends SslContext> mapping)Creates a SNI detection handler with configuredSslContextmaintained byMappingSniHandler(Mapping<? super java.lang.String,? extends SslContext> mapping, int maxClientHelloLength, long handshakeTimeoutMillis)Creates a SNI detection handler with configuredSslContextmaintained byMappingSniHandler(Mapping<? super java.lang.String,? extends SslContext> mapping, long handshakeTimeoutMillis)Creates a SNI detection handler with configuredSslContextmaintained byMapping
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringhostname()protected Future<SslContext>lookup(ChannelHandlerContext ctx, java.lang.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 voidonLookupComplete(ChannelHandlerContext ctx, java.lang.String hostname, Future<SslContext> future)Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)Future.protected voidreplaceHandler(ChannelHandlerContext ctx, java.lang.String hostname, SslContext sslContext)The default implementation of this method will simply replacethisSniHandlerinstance with aSslHandler.SslContextsslContext()-
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 Detail
-
mapping
protected final AsyncMapping<java.lang.String,SslContext> mapping
-
-
Constructor Detail
-
SniHandler
public SniHandler(Mapping<? super java.lang.String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContextmaintained byMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(Mapping<? super java.lang.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
public SniHandler(DomainNameMapping<? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContextmaintained byDomainNameMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(AsyncMapping<? super java.lang.String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContextmaintained byAsyncMapping- Parameters:
mapping- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(AsyncMapping<? super java.lang.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 java.lang.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 java.lang.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 Detail
-
hostname
public java.lang.String hostname()
- Returns:
- the selected hostname
-
sslContext
public SslContext sslContext()
- Returns:
- the selected
SslContext
-
lookup
protected Future<SslContext> lookup(ChannelHandlerContext ctx, java.lang.String hostname) throws java.lang.Exception
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:
java.lang.Exception- See Also:
AsyncMapping.map(Object, Promise)
-
onLookupComplete
protected final void onLookupComplete(ChannelHandlerContext ctx, java.lang.String hostname, Future<SslContext> future) throws java.lang.Exception
Description copied from class:AbstractSniHandlerCalled upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)Future.- Specified by:
onLookupCompletein classAbstractSniHandler<SslContext>- Throws:
java.lang.Exception- See Also:
AbstractSniHandler.lookup(ChannelHandlerContext, String)
-
replaceHandler
protected void replaceHandler(ChannelHandlerContext ctx, java.lang.String hostname, SslContext sslContext) throws java.lang.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:
java.lang.Exception
-
newSslHandler
protected SslHandler newSslHandler(SslContext context, ByteBufAllocator allocator)
Returns a newSslHandlerusing the givenSslContextandByteBufAllocator. Users may override this method to implement custom behavior.
-
-