public final class SslContextBuilder extends Object
Modifier and Type | Method and Description |
---|---|
SslContextBuilder |
applicationProtocolConfig(ApplicationProtocolConfig apn)
Application protocol negotiation configuration.
|
SslContext |
build()
Create new
SslContext 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.
|
SslContextBuilder |
endpointIdentificationAlgorithm(String algorithm)
Specify the endpoint identification algorithm (aka. hostname verification algorithm) that clients will use as
part of authenticating servers.
|
static SslContextBuilder |
forClient()
Creates a builder for new client-side
SslContext . |
static SslContextBuilder |
forServer(File keyCertChainFile,
File keyFile)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(File keyCertChainFile,
File keyFile,
String keyPassword)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(InputStream keyCertChainInputStream,
InputStream keyInputStream)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(InputStream keyCertChainInputStream,
InputStream keyInputStream,
String keyPassword)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(KeyManager keyManager)
Creates a builder for new server-side
SslContext with KeyManager . |
static SslContextBuilder |
forServer(KeyManagerFactory keyManagerFactory)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(PrivateKey key,
Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(PrivateKey key,
String keyPassword,
Iterable<? extends X509Certificate> keyCertChain)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(PrivateKey key,
String keyPassword,
X509Certificate... keyCertChain)
Creates a builder for new server-side
SslContext . |
static SslContextBuilder |
forServer(PrivateKey key,
X509Certificate... keyCertChain)
Creates a builder for new server-side
SslContext . |
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(KeyManager keyManager)
A single key manager managing the identity information of this host.
|
SslContextBuilder |
keyManager(KeyManagerFactory keyManagerFactory)
Identifying manager 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 |
keyStoreType(String keyStoreType)
Sets the
KeyStore type that should be used. |
<T> SslContextBuilder |
option(SslContextOption<T> option,
T value)
Configure a
SslContextOption . |
SslContextBuilder |
protocols(Iterable<String> protocols)
The TLS protocol versions to enable.
|
SslContextBuilder |
protocols(String... protocols)
The TLS protocol versions to enable.
|
SslContextBuilder |
secureRandom(SecureRandom secureRandom)
Specify a non-default source of randomness for the
JdkSslContext
In general, the best practice is to leave this unspecified, or to assign a new random source using the
default new SecureRandom() constructor. |
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 SSLContext
Provider to use. |
SslContextBuilder |
sslProvider(SslProvider provider)
The
SslContext 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(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.
|
SslContextBuilder |
trustManager(X509Certificate... trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,
null uses the system default. |
public static SslContextBuilder forClient()
SslContext
.public static SslContextBuilder forServer(File keyCertChainFile, File keyFile)
SslContext
.keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyManager(File, File)
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream)
SslContext
.keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyManager(InputStream, InputStream)
public static SslContextBuilder forServer(PrivateKey key, X509Certificate... keyCertChain)
SslContext
.key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyManager(PrivateKey, X509Certificate[])
public static SslContextBuilder forServer(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
SslContext
.key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyManager(PrivateKey, X509Certificate[])
public static SslContextBuilder forServer(File keyCertChainFile, File keyFile, String keyPassword)
SslContext
.keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of the keyFile
, or null
if it's not
password-protectedkeyManager(File, File, String)
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
SslContext
.keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyPassword
- the password of the keyFile
, or null
if it's not
password-protectedkeyManager(InputStream, InputStream, String)
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
SslContext
.key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyPassword
- the password of the keyFile
, or null
if it's not
password-protectedkeyManager(File, File, String)
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
SslContext
.key
- a PKCS#8 private keykeyCertChain
- the X.509 certificate chainkeyPassword
- the password of the keyFile
, or null
if it's not
password-protectedkeyManager(File, File, String)
public static SslContextBuilder forServer(KeyManagerFactory keyManagerFactory)
SslContext
.
If you use SslProvider.OPENSSL
or SslProvider.OPENSSL_REFCNT
consider using
OpenSslX509KeyManagerFactory
or OpenSslCachingX509KeyManagerFactory
.keyManagerFactory
- non-null
factory for server's private keykeyManager(KeyManagerFactory)
public static SslContextBuilder forServer(KeyManager keyManager)
SslContext
with KeyManager
.keyManager
- non-null
KeyManager for server's private keypublic <T> SslContextBuilder option(SslContextOption<T> option, T value)
SslContextOption
.public SslContextBuilder sslProvider(SslProvider provider)
SslContext
implementation to use. null
uses the default one.public SslContextBuilder keyStoreType(String keyStoreType)
KeyStore
type that should be used. null
uses the default one.public SslContextBuilder sslContextProvider(Provider sslContextProvider)
public SslContextBuilder trustManager(File trustCertCollectionFile)
null
uses the system default.public SslContextBuilder trustManager(InputStream trustCertCollectionInputStream)
null
uses the system default.
The caller is responsible for calling InputStream.close()
after build()
has been called.public SslContextBuilder trustManager(X509Certificate... trustCertCollection)
null
uses the system default.public SslContextBuilder trustManager(Iterable<? extends X509Certificate> trustCertCollection)
null
uses the system default.public SslContextBuilder trustManager(TrustManagerFactory trustManagerFactory)
null
uses the system default.public SslContextBuilder trustManager(TrustManager trustManager)
TrustManager
is needed.
Internally, a simple wrapper of TrustManagerFactory
that only produces this
specified TrustManager
will be created, thus all the requirements specified in
trustManager(TrustManagerFactory trustManagerFactory)
also apply here.public SslContextBuilder keyManager(File keyCertChainFile, File keyFile)
keyCertChainFile
and keyFile
may
be null
for client contexts, which disables mutual authentication.keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatpublic SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream)
keyCertChainInputStream
and keyInputStream
may
be null
for client contexts, which disables mutual authentication.keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.public SslContextBuilder keyManager(PrivateKey key, X509Certificate... keyCertChain)
keyCertChain
and key
may
be null
for client contexts, which disables mutual authentication.key
- a PKCS#8 private keykeyCertChain
- an X.509 certificate chainpublic SslContextBuilder keyManager(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
keyCertChain
and key
may
be null
for client contexts, which disables mutual authentication.key
- a PKCS#8 private keykeyCertChain
- an X.509 certificate chainpublic SslContextBuilder keyManager(File keyCertChainFile, File keyFile, String keyPassword)
keyCertChainFile
and keyFile
may
be null
for client contexts, which disables mutual authentication.keyCertChainFile
- an X.509 certificate chain file in PEM formatkeyFile
- a PKCS#8 private key file in PEM formatkeyPassword
- the password of the keyFile
, or null
if it's not
password-protectedpublic SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
keyCertChainInputStream
and keyInputStream
may
be null
for client contexts, which disables mutual authentication.keyCertChainInputStream
- an input stream for an X.509 certificate chain in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyInputStream
- an input stream for a PKCS#8 private key in PEM format. The caller is
responsible for calling InputStream.close()
after build()
has been called.keyPassword
- the password of the keyInputStream
, or null
if it's not
password-protectedpublic SslContextBuilder keyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
keyCertChain
and key
may
be null
for client contexts, which disables mutual authentication.key
- a PKCS#8 private key filekeyPassword
- the password of the key
, or null
if it's not
password-protectedkeyCertChain
- an X.509 certificate chainpublic SslContextBuilder keyManager(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
keyCertChain
and key
may
be null
for client contexts, which disables mutual authentication.key
- a PKCS#8 private key filekeyPassword
- the password of the key
, or null
if it's not
password-protectedkeyCertChain
- an X.509 certificate chainpublic SslContextBuilder keyManager(KeyManagerFactory keyManagerFactory)
keyManagerFactory
may be null
for
client contexts, which disables mutual authentication. Using a KeyManagerFactory
is only supported for SslProvider.JDK
or SslProvider.OPENSSL
/ SslProvider.OPENSSL_REFCNT
if the used openssl version is 1.0.1+. You can check if your openssl version supports using a
KeyManagerFactory
by calling OpenSsl.supportsKeyManagerFactory()
. If this is not the case
you must use keyManager(File, File)
or keyManager(File, File, String)
.
If you use SslProvider.OPENSSL
or SslProvider.OPENSSL_REFCNT
consider using
OpenSslX509KeyManagerFactory
or OpenSslCachingX509KeyManagerFactory
.public SslContextBuilder keyManager(KeyManager keyManager)
KeyManager
is needed.
Internally, a wrapper of KeyManagerFactory
that only produces this specified
KeyManager
will be created, thus all the requirements specified in
keyManager(KeyManagerFactory keyManagerFactory)
also apply here.public SslContextBuilder ciphers(Iterable<String> ciphers)
null
to use default
cipher suites.public SslContextBuilder ciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)
cipherFilter
will be
applied to the ciphers before use. If ciphers
is null
, then the default
cipher suites will be used.public SslContextBuilder applicationProtocolConfig(ApplicationProtocolConfig apn)
null
disables support.public SslContextBuilder sessionCacheSize(long sessionCacheSize)
0
to use the
default value.public SslContextBuilder sessionTimeout(long sessionTimeout)
0
to use the
default value.public SslContextBuilder clientAuth(ClientAuth clientAuth)
public SslContextBuilder protocols(String... protocols)
protocols
- The protocols to enable, or null
to enable the default protocols.SSLEngine.setEnabledCipherSuites(String[])
public SslContextBuilder protocols(Iterable<String> protocols)
protocols
- The protocols to enable, or null
to enable the default protocols.SSLEngine.setEnabledCipherSuites(String[])
public SslContextBuilder startTls(boolean startTls)
true
if the first write request shouldn't be encrypted.@UnstableApi public SslContextBuilder enableOcsp(boolean enableOcsp)
SslProvider
implementations support OCSP
stapling and an exception will be thrown upon build()
.OpenSsl.isOcspSupported()
public SslContextBuilder secureRandom(SecureRandom secureRandom)
JdkSslContext
In general, the best practice is to leave this unspecified, or to assign a new random source using the
default new SecureRandom()
constructor.
Only assign this something when you have a good reason to.
secureRandom
- the source of randomness for JdkSslContext
public SslContextBuilder endpointIdentificationAlgorithm(String algorithm)
See Java Security Standard Names for a list of supported algorithms.
algorithm
- either "HTTPS"
, "LDAPS"
, or null
(disables hostname verification).SSLParameters.setEndpointIdentificationAlgorithm(String)
public SslContext build() throws SSLException
SslContext
instance with configured settings.
If sslProvider(SslProvider)
is set to SslProvider.OPENSSL_REFCNT
then the caller is
responsible for releasing this object, or else native memory may leak.
SSLException
Copyright © 2008–2024 The Netty Project. All rights reserved.