Package org.jboss.netty.handler.ssl
Class SslContext
java.lang.Object
org.jboss.netty.handler.ssl.SslContext
- Direct Known Subclasses:
JdkSslContext
,OpenSslServerContext
A secure socket protocol implementation which acts as a factory for
SSLEngine
and SslHandler
.
Internally, it is implemented via JDK's SSLContext
or OpenSSL's SSL_CTX
.
Making your server support SSL/TLS
// In yourChannelPipelineFactory
:ChannelPipeline
p =Channels.pipeline()
;SslContext
sslCtx =SslContext.newServerContext(...)
; p.addLast("ssl",sslCtx.newEngine()
); ...
Making your client support SSL/TLS
// In yourChannelPipelineFactory
:ChannelPipeline
p =Channels.pipeline()
;SslContext
sslCtx =SslContext.newClientContext(...)
; p.addLast("ssl",sslCtx.newEngine(host, port)
); ...
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal SslBufferPool
Returns the list of enabled cipher suites, in the order of preference.static SslProvider
Returns the default client-side implementation provider currently in use.static SslProvider
Returns the default server-side implementation provider currently in use.abstract boolean
isClient()
Returns thetrue
if and only if this context is for client-side.final boolean
isServer()
Returnstrue
if and only if this context is for server-side.(package private) SslBufferPool
static SslContext
Creates a new client-sideSslContext
.static SslContext
newClientContext
(File certChainFile) Creates a new client-sideSslContext
.static SslContext
newClientContext
(File certChainFile, TrustManagerFactory trustManagerFactory) Creates a new client-sideSslContext
.static SslContext
newClientContext
(TrustManagerFactory trustManagerFactory) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslBufferPool bufPool, File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslProvider provider) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslProvider provider, File certChainFile) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslProvider provider, File certChainFile, TrustManagerFactory trustManagerFactory) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslProvider provider, TrustManagerFactory trustManagerFactory) Creates a new client-sideSslContext
.static SslContext
newClientContext
(SslProvider provider, SslBufferPool bufPool, File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) Creates a new client-sideSslContext
.abstract SSLEngine
Creates a newSSLEngine
.abstract SSLEngine
Creates a newSSLEngine
using advisory peer information.final SslHandler
Creates a newSslHandler
.final SslHandler
newHandler
(String peerHost, int peerPort) Creates a newSslHandler
with advisory peer information.private SslHandler
newHandler
(SSLEngine engine) static SslContext
newServerContext
(File certChainFile, File keyFile) Creates a new server-sideSslContext
.static SslContext
newServerContext
(File certChainFile, File keyFile, String keyPassword) Creates a new server-sideSslContext
.static SslContext
newServerContext
(SslBufferPool bufPool, File certChainFile, File keyFile, String keyPassword, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) Creates a new server-sideSslContext
.static SslContext
newServerContext
(SslProvider provider, File certChainFile, File keyFile) Creates a new server-sideSslContext
.static SslContext
newServerContext
(SslProvider provider, File certChainFile, File keyFile, String keyPassword) Creates a new server-sideSslContext
.static SslContext
newServerContext
(SslProvider provider, SslBufferPool bufPool, File certChainFile, File keyFile, String keyPassword, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) Creates a new server-sideSslContext
.Returns the list of application layer protocols for the TLS NPN/ALPN extension, in the order of preference.abstract long
Returns the size of the cache used for storing SSL session objects.abstract long
Returns the timeout for the cached SSL session objects, in seconds.
-
Field Details
-
bufferPool
-
-
Constructor Details
-
SslContext
SslContext(SslBufferPool bufferPool)
-
-
Method Details
-
defaultServerProvider
Returns the default server-side implementation provider currently in use.- Returns:
SslProvider.OPENSSL
if OpenSSL is available.SslProvider.JDK
otherwise.
-
defaultClientProvider
Returns the default client-side implementation provider currently in use.- Returns:
SslProvider.JDK
, because it is the only implementation at the moment
-
newServerContext
Creates a new server-sideSslContext
.- Parameters:
certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM format- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newServerContext
public static SslContext newServerContext(File certChainFile, File keyFile, String keyPassword) throws SSLException Creates a new server-sideSslContext
.- Parameters:
certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
.null
if it's not password-protected.- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newServerContext
public static SslContext newServerContext(SslBufferPool bufPool, File certChainFile, File keyFile, String keyPassword, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) throws SSLException Creates a new server-sideSslContext
.- Parameters:
bufPool
- the buffer pool which will be used by the returnedSslContext
.null
to use the default buffer pool.certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
.null
if it's not password-protected.ciphers
- the cipher suites to enable, in the order of preference.null
to use the default cipher suites.nextProtocols
- the application layer protocols to accept, in the order of preference.null
to disable TLS NPN/ALPN extension.sessionCacheSize
- the size of the cache used for storing SSL session objects.0
to use the default value.sessionTimeout
- the timeout for the cached SSL session objects, in seconds.0
to use the default value.- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newServerContext
public static SslContext newServerContext(SslProvider provider, File certChainFile, File keyFile) throws SSLException Creates a new server-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM format- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newServerContext
public static SslContext newServerContext(SslProvider provider, File certChainFile, File keyFile, String keyPassword) throws SSLException Creates a new server-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
.null
if it's not password-protected.- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newServerContext
public static SslContext newServerContext(SslProvider provider, SslBufferPool bufPool, File certChainFile, File keyFile, String keyPassword, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) throws SSLException Creates a new server-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.bufPool
- the buffer pool which will be used by the returnedSslContext
.null
to use the default buffer pool.certChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
.null
if it's not password-protected.ciphers
- the cipher suites to enable, in the order of preference.null
to use the default cipher suites.nextProtocols
- the application layer protocols to accept, in the order of preference.null
to disable TLS NPN/ALPN extension.sessionCacheSize
- the size of the cache used for storing SSL session objects.0
to use the default value.sessionTimeout
- the timeout for the cached SSL session objects, in seconds.0
to use the default value.- Returns:
- a new server-side
SslContext
- Throws:
SSLException
-
newClientContext
Creates a new client-sideSslContext
.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
Creates a new client-sideSslContext
.- Parameters:
certChainFile
- an X.509 certificate chain file in PEM format- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(TrustManagerFactory trustManagerFactory) throws SSLException Creates a new client-sideSslContext
.- Parameters:
trustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(File certChainFile, TrustManagerFactory trustManagerFactory) throws SSLException Creates a new client-sideSslContext
.- Parameters:
certChainFile
- an X.509 certificate chain file in PEM format.null
to use the system defaulttrustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(SslBufferPool bufPool, File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) throws SSLException Creates a new client-sideSslContext
.- Parameters:
bufPool
- the buffer pool which will be used by the returnedSslContext
.null
to use the default buffer pool.certChainFile
- an X.509 certificate chain file in PEM format.null
to use the system defaulttrustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.ciphers
- the cipher suites to enable, in the order of preference.null
to use the default cipher suites.nextProtocols
- the application layer protocols to accept, in the order of preference.null
to disable TLS NPN/ALPN extension.sessionCacheSize
- the size of the cache used for storing SSL session objects.0
to use the default value.sessionTimeout
- the timeout for the cached SSL session objects, in seconds.0
to use the default value.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
Creates a new client-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(SslProvider provider, File certChainFile) throws SSLException Creates a new client-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.certChainFile
- an X.509 certificate chain file in PEM format.null
to use the system default- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(SslProvider provider, TrustManagerFactory trustManagerFactory) throws SSLException Creates a new client-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.trustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(SslProvider provider, File certChainFile, TrustManagerFactory trustManagerFactory) throws SSLException Creates a new client-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.certChainFile
- an X.509 certificate chain file in PEM format.null
to use the system defaulttrustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newClientContext
public static SslContext newClientContext(SslProvider provider, SslBufferPool bufPool, File certChainFile, TrustManagerFactory trustManagerFactory, Iterable<String> ciphers, Iterable<String> nextProtocols, long sessionCacheSize, long sessionTimeout) throws SSLException Creates a new client-sideSslContext
.- Parameters:
provider
- theSslContext
implementation to use.null
to use the current default one.bufPool
- the buffer pool which will be used by the returnedSslContext
.null
to use the default buffer pool.certChainFile
- an X.509 certificate chain file in PEM format.null
to use the system defaulttrustManagerFactory
- theTrustManagerFactory
that provides theTrustManager
s that verifies the certificates sent from servers.null
to use the default.ciphers
- the cipher suites to enable, in the order of preference.null
to use the default cipher suites.nextProtocols
- the application layer protocols to accept, in the order of preference.null
to disable TLS NPN/ALPN extension.sessionCacheSize
- the size of the cache used for storing SSL session objects.0
to use the default value.sessionTimeout
- the timeout for the cached SSL session objects, in seconds.0
to use the default value.- Returns:
- a new client-side
SslContext
- Throws:
SSLException
-
newBufferPool
SslBufferPool newBufferPool() -
isServer
public final boolean isServer()Returnstrue
if and only if this context is for server-side. -
bufferPool
-
isClient
public abstract boolean isClient()Returns thetrue
if and only if this context is for client-side. -
cipherSuites
Returns the list of enabled cipher suites, in the order of preference. -
sessionCacheSize
public abstract long sessionCacheSize()Returns the size of the cache used for storing SSL session objects. -
sessionTimeout
public abstract long sessionTimeout()Returns the timeout for the cached SSL session objects, in seconds. -
nextProtocols
Returns the list of application layer protocols for the TLS NPN/ALPN extension, in the order of preference.- Returns:
- the list of application layer protocols.
null
if NPN/ALPN extension has been disabled.
-
newEngine
Creates a newSSLEngine
.- Returns:
- a new
SSLEngine
-
newEngine
Creates a newSSLEngine
using advisory peer information.- Parameters:
peerHost
- the non-authoritative name of the hostpeerPort
- the non-authoritative port- Returns:
- a new
SSLEngine
-
newHandler
Creates a newSslHandler
.- Returns:
- a new
SslHandler
-
newHandler
Creates a newSslHandler
with advisory peer information.- Parameters:
peerHost
- the non-authoritative name of the hostpeerPort
- the non-authoritative port- Returns:
- a new
SslHandler
-
newHandler
-