- java.lang.Object
-
- io.netty5.handler.ssl.SslContextBuilder
-
public final class SslContextBuilder extends Object
Builder for configuring a new SslContext for creation.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SslContextBuilder
applicationProtocolConfig(ApplicationProtocolConfig apn)
Application protocol negotiation configuration.SslContext
build()
Create newSslContext
instance with configured settings.SslContextBuilder
ciphers(Iterable<String> ciphers)
The cipher suites to enable, in the order of preference.SslContextBuilder
ciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)
The cipher suites to enable, in the order of preference.SslContextBuilder
clientAuth(ClientAuth clientAuth)
Sets the client authentication mode.SslContextBuilder
enableOcsp(boolean enableOcsp)
Enables OCSP stapling.static SslContextBuilder
forClient()
Creates a builder for new client-sideSslContext
.static SslContextBuilder
forServer(File keyCertChainFile, File keyFile)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(File keyCertChainFile, File keyFile, String keyPassword)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(InputStream keyCertChainInputStream, InputStream keyInputStream)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(PrivateKey key, X509Certificate... keyCertChain)
Creates a builder for new server-sideSslContext
.static SslContextBuilder
forServer(KeyManager keyManager)
Creates a builder for new server-sideSslContext
withKeyManager
.static SslContextBuilder
forServer(KeyManagerFactory keyManagerFactory)
Creates a builder for new server-sideSslContext
.SslContextBuilder
keyManager(File keyCertChainFile, File keyFile)
Identifying certificate for this host.SslContextBuilder
keyManager(File keyCertChainFile, File keyFile, String keyPassword)
Identifying certificate for this host.SslContextBuilder
keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream)
Identifying certificate for this host.SslContextBuilder
keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Identifying certificate for this host.SslContextBuilder
keyManager(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Identifying certificate for this host.SslContextBuilder
keyManager(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Identifying certificate for this host.SslContextBuilder
keyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Identifying certificate for this host.SslContextBuilder
keyManager(PrivateKey key, X509Certificate... keyCertChain)
Identifying certificate for this host.SslContextBuilder
keyManager(KeyManager keyManager)
A single key manager managing the identity information of this host.SslContextBuilder
keyManager(KeyManagerFactory keyManagerFactory)
Identifying manager for this host.SslContextBuilder
keyStoreType(String keyStoreType)
Sets theKeyStore
type that should be used.<T> SslContextBuilder
option(SslContextOption<T> option, T value)
Configure aSslContextOption
.SslContextBuilder
protocols(Iterable<String> protocols)
The TLS protocol versions to enable.SslContextBuilder
protocols(String... protocols)
The TLS protocol versions to enable.SslContextBuilder
sessionCacheSize(long sessionCacheSize)
Set the size of the cache used for storing SSL session objects.SslContextBuilder
sessionTimeout(long sessionTimeout)
Set the timeout for the cached SSL session objects, in seconds.SslContextBuilder
sslContextProvider(Provider sslContextProvider)
The SSLContextProvider
to use.SslContextBuilder
sslProvider(SslProvider provider)
TheSslContext
implementation to use.SslContextBuilder
startTls(boolean startTls)
true
if the first write request shouldn't be encrypted.SslContextBuilder
trustManager(File trustCertCollectionFile)
Trusted certificates for verifying the remote endpoint's certificate.SslContextBuilder
trustManager(InputStream trustCertCollectionInputStream)
Trusted certificates for verifying the remote endpoint's certificate.SslContextBuilder
trustManager(Iterable<? extends X509Certificate> trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,null
uses the system default.SslContextBuilder
trustManager(X509Certificate... trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,null
uses the system default.SslContextBuilder
trustManager(TrustManager trustManager)
A single trusted manager for verifying the remote endpoint's certificate.SslContextBuilder
trustManager(TrustManagerFactory trustManagerFactory)
Trusted manager for verifying the remote endpoint's certificate.
-
-
-
Method Detail
-
forClient
public static SslContextBuilder forClient()
Creates a builder for new client-sideSslContext
.
-
forServer
public static SslContextBuilder forServer(File keyCertChainFile, File keyFile)
Creates a builder for new server-sideSslContext
.- Parameters:
keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM format- See Also:
keyManager(File, File)
-
forServer
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream)
Creates a builder for new server-sideSslContext
.- Parameters:
keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.- See Also:
keyManager(InputStream, InputStream)
-
forServer
public static SslContextBuilder forServer(PrivateKey key, X509Certificate... keyCertChain)
Creates a builder for new server-sideSslContext
.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chain- See Also:
keyManager(PrivateKey, X509Certificate[])
-
forServer
public static SslContextBuilder forServer(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-sideSslContext
.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chain- See Also:
keyManager(PrivateKey, X509Certificate[])
-
forServer
public static SslContextBuilder forServer(File keyCertChainFile, File keyFile, String keyPassword)
Creates a builder for new server-sideSslContext
.- Parameters:
keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
, ornull
if it's not password-protected- See Also:
keyManager(File, File, String)
-
forServer
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Creates a builder for new server-sideSslContext
.- Parameters:
keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyPassword
- the password of thekeyFile
, ornull
if it's not password-protected- See Also:
keyManager(InputStream, InputStream, String)
-
forServer
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Creates a builder for new server-sideSslContext
.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyPassword
- the password of thekeyFile
, ornull
if it's not password-protected- See Also:
keyManager(File, File, String)
-
forServer
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-sideSslContext
.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyPassword
- the password of thekeyFile
, ornull
if it's not password-protected- See Also:
keyManager(File, File, String)
-
forServer
public static SslContextBuilder forServer(KeyManagerFactory keyManagerFactory)
Creates a builder for new server-sideSslContext
. If you useSslProvider.OPENSSL
orSslProvider.OPENSSL_REFCNT
consider usingOpenSslX509KeyManagerFactory
orOpenSslCachingX509KeyManagerFactory
.- Parameters:
keyManagerFactory
- non-null
factory for server's private key- See Also:
keyManager(KeyManagerFactory)
-
forServer
public static SslContextBuilder forServer(KeyManager keyManager)
Creates a builder for new server-sideSslContext
withKeyManager
.- Parameters:
keyManager
- non-null
KeyManager for server's private key
-
option
public <T> SslContextBuilder option(SslContextOption<T> option, T value)
Configure aSslContextOption
.
-
sslProvider
public SslContextBuilder sslProvider(SslProvider provider)
TheSslContext
implementation to use.null
uses the default one.
-
keyStoreType
public SslContextBuilder keyStoreType(String keyStoreType)
Sets theKeyStore
type that should be used.null
uses the default one.
-
sslContextProvider
public SslContextBuilder sslContextProvider(Provider sslContextProvider)
-
trustManager
public SslContextBuilder trustManager(File trustCertCollectionFile)
Trusted certificates for verifying the remote endpoint's certificate. The file should contain an X.509 certificate collection in PEM format.null
uses the system default.
-
trustManager
public SslContextBuilder trustManager(InputStream trustCertCollectionInputStream)
Trusted certificates for verifying the remote endpoint's certificate. The input stream should contain an X.509 certificate collection in PEM format.null
uses the system default. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.
-
trustManager
public SslContextBuilder trustManager(X509Certificate... trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,null
uses the system default.
-
trustManager
public SslContextBuilder trustManager(Iterable<? extends X509Certificate> trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,null
uses the system default.
-
trustManager
public SslContextBuilder trustManager(TrustManagerFactory trustManagerFactory)
Trusted manager for verifying the remote endpoint's certificate.null
uses the system default.
-
trustManager
public SslContextBuilder trustManager(TrustManager trustManager)
A single trusted manager for verifying the remote endpoint's certificate. This is helpful when custom implementation ofTrustManager
is needed. Internally, a simple wrapper ofTrustManagerFactory
that only produces this specifiedTrustManager
will be created, thus all the requirements specified intrustManager(TrustManagerFactory trustManagerFactory)
also apply here.
-
keyManager
public SslContextBuilder keyManager(File keyCertChainFile, File keyFile)
Identifying certificate for this host.keyCertChainFile
andkeyFile
may benull
for client contexts, which disables mutual authentication.- Parameters:
keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM format
-
keyManager
public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream)
Identifying certificate for this host.keyCertChainInputStream
andkeyInputStream
may benull
for client contexts, which disables mutual authentication.- Parameters:
keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.
-
keyManager
public SslContextBuilder keyManager(PrivateKey key, X509Certificate... keyCertChain)
Identifying certificate for this host.keyCertChain
andkey
may benull
for client contexts, which disables mutual authentication.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- an X.509 certificate chain
-
keyManager
public SslContextBuilder keyManager(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Identifying certificate for this host.keyCertChain
andkey
may benull
for client contexts, which disables mutual authentication.- Parameters:
key
- a PKCS#8 private keykeyCertChain
- an X.509 certificate chain
-
keyManager
public SslContextBuilder keyManager(File keyCertChainFile, File keyFile, String keyPassword)
Identifying certificate for this host.keyCertChainFile
andkeyFile
may benull
for client contexts, which disables mutual authentication.- Parameters:
keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of thekeyFile
, ornull
if it's not password-protected
-
keyManager
public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Identifying certificate for this host.keyCertChainInputStream
andkeyInputStream
may benull
for client contexts, which disables mutual authentication.- Parameters:
keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is responsible for callingInputStream.close()
afterbuild()
has been called.keyPassword
- the password of thekeyInputStream
, ornull
if it's not password-protected
-
keyManager
public SslContextBuilder keyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Identifying certificate for this host.keyCertChain
andkey
may benull
for client contexts, which disables mutual authentication.- Parameters:
key
- a PKCS#8 private key filekeyPassword
- the password of thekey
, ornull
if it's not password-protectedkeyCertChain
- an X.509 certificate chain
-
keyManager
public SslContextBuilder keyManager(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Identifying certificate for this host.keyCertChain
andkey
may benull
for client contexts, which disables mutual authentication.- Parameters:
key
- a PKCS#8 private key filekeyPassword
- the password of thekey
, ornull
if it's not password-protectedkeyCertChain
- an X.509 certificate chain
-
keyManager
public SslContextBuilder keyManager(KeyManagerFactory keyManagerFactory)
Identifying manager for this host.keyManagerFactory
may benull
for client contexts, which disables mutual authentication. Using aKeyManagerFactory
is only supported forSslProvider.JDK
orSslProvider.OPENSSL
/SslProvider.OPENSSL_REFCNT
if the used openssl version is 1.0.1+. You can check if your openssl version supports using aKeyManagerFactory
by callingOpenSsl.supportsKeyManagerFactory()
. If this is not the case you must usekeyManager(File, File)
orkeyManager(File, File, String)
. If you useSslProvider.OPENSSL
orSslProvider.OPENSSL_REFCNT
consider usingOpenSslX509KeyManagerFactory
orOpenSslCachingX509KeyManagerFactory
.
-
keyManager
public SslContextBuilder keyManager(KeyManager keyManager)
A single key manager managing the identity information of this host. This is helpful when custom implementation ofKeyManager
is needed. Internally, a wrapper ofKeyManagerFactory
that only produces this specifiedKeyManager
will be created, thus all the requirements specified inkeyManager(KeyManagerFactory keyManagerFactory)
also apply here.
-
ciphers
public SslContextBuilder ciphers(Iterable<String> ciphers)
The cipher suites to enable, in the order of preference.null
to use default cipher suites.
-
ciphers
public SslContextBuilder ciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)
The cipher suites to enable, in the order of preference.cipherFilter
will be applied to the ciphers before use. Ifciphers
isnull
, then the default cipher suites will be used.
-
applicationProtocolConfig
public SslContextBuilder applicationProtocolConfig(ApplicationProtocolConfig apn)
Application protocol negotiation configuration.null
disables support.
-
sessionCacheSize
public SslContextBuilder sessionCacheSize(long sessionCacheSize)
Set the size of the cache used for storing SSL session objects.0
to use the default value.
-
sessionTimeout
public SslContextBuilder sessionTimeout(long sessionTimeout)
Set the timeout for the cached SSL session objects, in seconds.0
to use the default value.
-
clientAuth
public SslContextBuilder clientAuth(ClientAuth clientAuth)
Sets the client authentication mode.
-
protocols
public SslContextBuilder protocols(String... protocols)
The TLS protocol versions to enable.- Parameters:
protocols
- The protocols to enable, ornull
to enable the default protocols.- See Also:
SSLEngine.setEnabledCipherSuites(String[])
-
protocols
public SslContextBuilder protocols(Iterable<String> protocols)
The TLS protocol versions to enable.- Parameters:
protocols
- The protocols to enable, ornull
to enable the default protocols.- See Also:
SSLEngine.setEnabledCipherSuites(String[])
-
startTls
public SslContextBuilder startTls(boolean startTls)
true
if the first write request shouldn't be encrypted.
-
enableOcsp
@UnstableApi public SslContextBuilder enableOcsp(boolean enableOcsp)
Enables OCSP stapling. Please note that not allSslProvider
implementations support OCSP stapling and an exception will be thrown uponbuild()
.- See Also:
OpenSsl.isOcspSupported()
-
build
public SslContext build() throws SSLException
Create newSslContext
instance with configured settings.If
sslProvider(SslProvider)
is set toSslProvider.OPENSSL_REFCNT
then the caller is responsible for releasing this object, or else native memory may leak.- Throws:
SSLException
-
-