Top Description Fields Constructors Methods
io.netty5.handler.ssl

public final Class SslContextBuilder

extends Object
Class Inheritance
Imports
io.netty5.handler.ssl.util.KeyManagerFactoryWrapper, .TrustManagerFactoryWrapper, io.netty5.util.internal.UnstableApi, javax.net.ssl.KeyManager, .KeyManagerFactory, .SSLEngine, .SSLException, .TrustManager, .TrustManagerFactory, java.io.File, .InputStream, java.security.KeyStore, .PrivateKey, .Provider, java.security.cert.X509Certificate, java.util.ArrayList, .HashMap, .List, .Map

Builder for configuring a new SslContext for creation.

Field Summary

Modifier and TypeField and Description
private ApplicationProtocolConfig
private CipherSuiteFilter
private Iterable<String>
private ClientAuth
private static final Map.Entry<K, V>[]
private boolean
private final boolean
private PrivateKey
private X509Certificate[]
private KeyManagerFactory
private String
private String
private final Map<SslContextOption<?>, Object>
private String[]
private SslProvider
private long
private long
private Provider
private boolean
private X509Certificate[]
private TrustManagerFactory

Constructor Summary

AccessConstructor and Description
private
SslContextBuilder(boolean forServer)

Method Summary

Modifier and TypeMethod and Description
public SslContextBuilder
applicationProtocolConfig(ApplicationProtocolConfig apn)

Application protocol negotiation configuration.

public SslContext
build()

Create new SslContext instance with configured settings.

public SslContextBuilder
ciphers(Iterable<String> ciphers)

The cipher suites to enable, in the order of preference.

public SslContextBuilder
ciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)

The cipher suites to enable, in the order of preference.

public SslContextBuilder
clientAuth(ClientAuth clientAuth)

Sets the client authentication mode.

public SslContextBuilder
enableOcsp(boolean enableOcsp)

Enables OCSP stapling.

public static SslContextBuilder
forClient()

Creates a builder for new client-side SslContext.

public static SslContextBuilder
forServer(File
an X.509 certificate chain file in PEM format
keyCertChainFile
,
File
a PKCS#8 private key file in PEM format
keyFile
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(InputStream
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.
keyCertChainInputStream
,
InputStream
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.
keyInputStream
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(PrivateKey
a PKCS#8 private key
key
,
X509Certificate...
the X.509 certificate chain
keyCertChain
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(PrivateKey
a PKCS#8 private key
key
,
Iterable<? extends X509Certificate>
the X.509 certificate chain
keyCertChain
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(File
an X.509 certificate chain file in PEM format
keyCertChainFile
,
File
a PKCS#8 private key file in PEM format
keyFile
,
String
the password of the keyFile, or null if it's not password-protected
keyPassword
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(InputStream
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.
keyCertChainInputStream
,
InputStream
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.
keyInputStream
,
String
the password of the keyFile, or null if it's not password-protected
keyPassword
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(PrivateKey
a PKCS#8 private key
key
,
String
the password of the keyFile, or null if it's not password-protected
keyPassword
,
X509Certificate...
the X.509 certificate chain
keyCertChain
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(PrivateKey
a PKCS#8 private key
key
,
String
the password of the keyFile, or null if it's not password-protected
keyPassword
,
Iterable<? extends X509Certificate>
the X.509 certificate chain
keyCertChain
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(KeyManagerFactory
non-null factory for server's private key
keyManagerFactory
)

Creates a builder for new server-side SslContext.

public static SslContextBuilder
forServer(KeyManager
non-null KeyManager for server's private key
keyManager
)

Creates a builder for new server-side SslContext with KeyManager.

public SslContextBuilder
keyManager(File
an X.509 certificate chain file in PEM format
keyCertChainFile
,
File
a PKCS#8 private key file in PEM format
keyFile
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(InputStream
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.
keyCertChainInputStream
,
InputStream
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.
keyInputStream
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(PrivateKey
a PKCS#8 private key
key
,
X509Certificate...
an X.509 certificate chain
keyCertChain
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(PrivateKey
a PKCS#8 private key
key
,
Iterable<? extends X509Certificate>
an X.509 certificate chain
keyCertChain
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(File
an X.509 certificate chain file in PEM format
keyCertChainFile
,
File
a PKCS#8 private key file in PEM format
keyFile
,
String
the password of the keyFile, or null if it's not password-protected
keyPassword
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(InputStream
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.
keyCertChainInputStream
,
InputStream
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.
keyInputStream
,
String
the password of the keyInputStream, or null if it's not password-protected
keyPassword
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(PrivateKey
a PKCS#8 private key file
key
,
String
the password of the key, or null if it's not password-protected
keyPassword
,
X509Certificate...
an X.509 certificate chain
keyCertChain
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(PrivateKey
a PKCS#8 private key file
key
,
String
the password of the key, or null if it's not password-protected
keyPassword
,
Iterable<? extends X509Certificate>
an X.509 certificate chain
keyCertChain
)

Identifying certificate for this host.

public SslContextBuilder
keyManager(KeyManagerFactory keyManagerFactory)

Identifying manager for this host.

public SslContextBuilder
keyManager(KeyManager keyManager)

A single key manager managing the identity information of this host.

public SslContextBuilder
keyStoreType(String keyStoreType)

Sets the KeyStore type that should be used.

public <T> SslContextBuilder
option(SslContextOption<T> option, T value)

Configure a SslContextOption.

public SslContextBuilder
protocols(String...
The protocols to enable, or null to enable the default protocols.
protocols
)

The TLS protocol versions to enable.

public SslContextBuilder
protocols(Iterable<String>
The protocols to enable, or null to enable the default protocols.
protocols
)

The TLS protocol versions to enable.

public SslContextBuilder
sessionCacheSize(long sessionCacheSize)

Set the size of the cache used for storing SSL session objects.

public SslContextBuilder
sessionTimeout(long sessionTimeout)

Set the timeout for the cached SSL session objects, in seconds.

public SslContextBuilder
sslContextProvider(Provider sslContextProvider)

The SSLContext Provider to use.

public SslContextBuilder
sslProvider(SslProvider provider)

The SslContext implementation to use.

public SslContextBuilder
startTls(boolean startTls)

true if the first write request shouldn't be encrypted.

private static <T> T[]
toArray(Iterable<? extends T> iterable, T[] prototype)

public SslContextBuilder
trustManager(File trustCertCollectionFile)

Trusted certificates for verifying the remote endpoint's certificate.

public SslContextBuilder
trustManager(InputStream trustCertCollectionInputStream)

Trusted certificates for verifying the remote endpoint's certificate.

public SslContextBuilder
trustManager(X509Certificate... trustCertCollection)

Trusted certificates for verifying the remote endpoint's certificate, null uses the system default.

public SslContextBuilder
trustManager(Iterable<? extends X509Certificate> trustCertCollection)

Trusted certificates for verifying the remote endpoint's certificate, null uses the system default.

public SslContextBuilder
trustManager(TrustManagerFactory trustManagerFactory)

Trusted manager for verifying the remote endpoint's certificate.

public SslContextBuilder
trustManager(TrustManager trustManager)

A single trusted manager for verifying the remote endpoint's certificate.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

apnback to summary
private ApplicationProtocolConfig apn
cipherFilterback to summary
private CipherSuiteFilter cipherFilter
ciphersback to summary
private Iterable<String> ciphers
clientAuthback to summary
private ClientAuth clientAuth
EMPTY_ENTRIESback to summary
private static final Map.Entry<K, V>[] EMPTY_ENTRIES
Annotations
@SuppressWarnings:rawtypes
enableOcspback to summary
private boolean enableOcsp
forServerback to summary
private final boolean forServer
keyback to summary
private PrivateKey key
keyCertChainback to summary
private X509Certificate[] keyCertChain
keyManagerFactoryback to summary
private KeyManagerFactory keyManagerFactory
keyPasswordback to summary
private String keyPassword
keyStoreTypeback to summary
private String keyStoreType
optionsback to summary
private final Map<SslContextOption<?>, Object> options
protocolsback to summary
private String[] protocols
providerback to summary
private SslProvider provider
sessionCacheSizeback to summary
private long sessionCacheSize
sessionTimeoutback to summary
private long sessionTimeout
sslContextProviderback to summary
private Provider sslContextProvider
startTlsback to summary
private boolean startTls
trustCertCollectionback to summary
private X509Certificate[] trustCertCollection
trustManagerFactoryback to summary
private TrustManagerFactory trustManagerFactory

Constructor Detail

SslContextBuilderback to summary
private SslContextBuilder(boolean forServer)

Method Detail

applicationProtocolConfigback to summary
public SslContextBuilder applicationProtocolConfig(ApplicationProtocolConfig apn)

Application protocol negotiation configuration. null disables support.

buildback to summary
public SslContext build() throws SSLException

Create new 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.

ciphersback to summary
public SslContextBuilder ciphers(Iterable<String> ciphers)

The cipher suites to enable, in the order of preference. null to use default cipher suites.

ciphersback to summary
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. If ciphers is null, then the default cipher suites will be used.

clientAuthback to summary
public SslContextBuilder clientAuth(ClientAuth clientAuth)

Sets the client authentication mode.

enableOcspback to summary
public SslContextBuilder enableOcsp(boolean enableOcsp)

Enables OCSP stapling. Please note that not all SslProvider implementations support OCSP stapling and an exception will be thrown upon build().

Annotations
@UnstableApi
See Also
OpenSsl#isOcspSupported()
forClientback to summary
public static SslContextBuilder forClient()

Creates a builder for new client-side SslContext.

forServerback to summary
public static SslContextBuilder forServer(File keyCertChainFile, File keyFile)

Creates a builder for new server-side SslContext.

Parameters
keyCertChainFile:File

an X.509 certificate chain file in PEM format

keyFile:File

a PKCS#8 private key file in PEM format

See Also
keyManager(File, File)
forServerback to summary
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream)

Creates a builder for new server-side SslContext.

Parameters
keyCertChainInputStream:InputStream

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:InputStream

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.

See Also
keyManager(InputStream, InputStream)
forServerback to summary
public static SslContextBuilder forServer(PrivateKey key, X509Certificate... keyCertChain)

Creates a builder for new server-side SslContext.

Parameters
key:PrivateKey

a PKCS#8 private key

keyCertChain:X509Certificate[]

the X.509 certificate chain

See Also
keyManager(PrivateKey, X509Certificate[])
forServerback to summary
public static SslContextBuilder forServer(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)

Creates a builder for new server-side SslContext.

Parameters
key:PrivateKey

a PKCS#8 private key

keyCertChain:Iterable<? extends X509Certificate>

the X.509 certificate chain

See Also
keyManager(PrivateKey, X509Certificate[])
forServerback to summary
public static SslContextBuilder forServer(File keyCertChainFile, File keyFile, String keyPassword)

Creates a builder for new server-side SslContext.

Parameters
keyCertChainFile:File

an X.509 certificate chain file in PEM format

keyFile:File

a PKCS#8 private key file in PEM format

keyPassword:String

the password of the keyFile, or null if it's not password-protected

See Also
keyManager(File, File, String)
forServerback to summary
public static SslContextBuilder forServer(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)

Creates a builder for new server-side SslContext.

Parameters
keyCertChainInputStream:InputStream

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:InputStream

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:String

the password of the keyFile, or null if it's not password-protected

See Also
keyManager(InputStream, InputStream, String)
forServerback to summary
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)

Creates a builder for new server-side SslContext.

Parameters
key:PrivateKey

a PKCS#8 private key

keyPassword:String

the password of the keyFile, or null if it's not password-protected

keyCertChain:X509Certificate[]

the X.509 certificate chain

See Also
keyManager(File, File, String)
forServerback to summary
public static SslContextBuilder forServer(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)

Creates a builder for new server-side SslContext.

Parameters
key:PrivateKey

a PKCS#8 private key

keyPassword:String

the password of the keyFile, or null if it's not password-protected

keyCertChain:Iterable<? extends X509Certificate>

the X.509 certificate chain

See Also
keyManager(File, File, String)
forServerback to summary
public static SslContextBuilder forServer(KeyManagerFactory keyManagerFactory)

Creates a builder for new server-side SslContext. If you use SslProvider#OPENSSL or SslProvider#OPENSSL_REFCNT consider using OpenSslX509KeyManagerFactory or OpenSslCachingX509KeyManagerFactory.

Parameters
keyManagerFactory:KeyManagerFactory

non-null factory for server's private key

See Also
keyManager(KeyManagerFactory)
forServerback to summary
public static SslContextBuilder forServer(KeyManager keyManager)

Creates a builder for new server-side SslContext with KeyManager.

Parameters
keyManager:KeyManager

non-null KeyManager for server's private key

keyManagerback to summary
public SslContextBuilder keyManager(File keyCertChainFile, File keyFile)

Identifying certificate for this host. keyCertChainFile and keyFile may be null for client contexts, which disables mutual authentication.

Parameters
keyCertChainFile:File

an X.509 certificate chain file in PEM format

keyFile:File

a PKCS#8 private key file in PEM format

keyManagerback to summary
public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream)

Identifying certificate for this host. keyCertChainInputStream and keyInputStream may be null for client contexts, which disables mutual authentication.

Parameters
keyCertChainInputStream:InputStream

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:InputStream

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.

keyManagerback to summary
public SslContextBuilder keyManager(PrivateKey key, X509Certificate... keyCertChain)

Identifying certificate for this host. keyCertChain and key may be null for client contexts, which disables mutual authentication.

Parameters
key:PrivateKey

a PKCS#8 private key

keyCertChain:X509Certificate[]

an X.509 certificate chain

keyManagerback to summary
public SslContextBuilder keyManager(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)

Identifying certificate for this host. keyCertChain and key may be null for client contexts, which disables mutual authentication.

Parameters
key:PrivateKey

a PKCS#8 private key

keyCertChain:Iterable<? extends X509Certificate>

an X.509 certificate chain

keyManagerback to summary
public SslContextBuilder keyManager(File keyCertChainFile, File keyFile, String keyPassword)

Identifying certificate for this host. keyCertChainFile and keyFile may be null for client contexts, which disables mutual authentication.

Parameters
keyCertChainFile:File

an X.509 certificate chain file in PEM format

keyFile:File

a PKCS#8 private key file in PEM format

keyPassword:String

the password of the keyFile, or null if it's not password-protected

keyManagerback to summary
public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)

Identifying certificate for this host. keyCertChainInputStream and keyInputStream may be null for client contexts, which disables mutual authentication.

Parameters
keyCertChainInputStream:InputStream

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:InputStream

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:String

the password of the keyInputStream, or null if it's not password-protected

keyManagerback to summary
public SslContextBuilder keyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)

Identifying certificate for this host. keyCertChain and key may be null for client contexts, which disables mutual authentication.

Parameters
key:PrivateKey

a PKCS#8 private key file

keyPassword:String

the password of the key, or null if it's not password-protected

keyCertChain:X509Certificate[]

an X.509 certificate chain

keyManagerback to summary
public SslContextBuilder keyManager(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)

Identifying certificate for this host. keyCertChain and key may be null for client contexts, which disables mutual authentication.

Parameters
key:PrivateKey

a PKCS#8 private key file

keyPassword:String

the password of the key, or null if it's not password-protected

keyCertChain:Iterable<? extends X509Certificate>

an X.509 certificate chain

keyManagerback to summary
public SslContextBuilder keyManager(KeyManagerFactory keyManagerFactory)

Identifying manager for this host. 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.

keyManagerback to summary
public SslContextBuilder keyManager(KeyManager keyManager)

A single key manager managing the identity information of this host. This is helpful when custom implementation of 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.

keyStoreTypeback to summary
public SslContextBuilder keyStoreType(String keyStoreType)

Sets the KeyStore type that should be used. null uses the default one.

optionback to summary
public <T> SslContextBuilder option(SslContextOption<T> option, T value)

Configure a SslContextOption.

protocolsback to summary
public SslContextBuilder protocols(String... protocols)

The TLS protocol versions to enable.

Parameters
protocols:String[]

The protocols to enable, or null to enable the default protocols.

See Also
SSLEngine#setEnabledCipherSuites(String[])
protocolsback to summary
public SslContextBuilder protocols(Iterable<String> protocols)

The TLS protocol versions to enable.

Parameters
protocols:Iterable<String>

The protocols to enable, or null to enable the default protocols.

See Also
SSLEngine#setEnabledCipherSuites(String[])
sessionCacheSizeback to summary
public SslContextBuilder sessionCacheSize(long sessionCacheSize)

Set the size of the cache used for storing SSL session objects. 0 to use the default value.

sessionTimeoutback to summary
public SslContextBuilder sessionTimeout(long sessionTimeout)

Set the timeout for the cached SSL session objects, in seconds. 0 to use the default value.

sslContextProviderback to summary
public SslContextBuilder sslContextProvider(Provider sslContextProvider)

The SSLContext Provider to use. null uses the default one. This is only used with SslProvider#JDK.

sslProviderback to summary
public SslContextBuilder sslProvider(SslProvider provider)

The SslContext implementation to use. null uses the default one.

startTlsback to summary
public SslContextBuilder startTls(boolean startTls)

true if the first write request shouldn't be encrypted.

toArrayback to summary
private static <T> T[] toArray(Iterable<? extends T> iterable, T[] prototype)
trustManagerback to summary
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.

trustManagerback to summary
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 calling InputStream#close() after build() has been called.

trustManagerback to summary
public SslContextBuilder trustManager(X509Certificate... trustCertCollection)

Trusted certificates for verifying the remote endpoint's certificate, null uses the system default.

trustManagerback to summary
public SslContextBuilder trustManager(Iterable<? extends X509Certificate> trustCertCollection)

Trusted certificates for verifying the remote endpoint's certificate, null uses the system default.

trustManagerback to summary
public SslContextBuilder trustManager(TrustManagerFactory trustManagerFactory)

Trusted manager for verifying the remote endpoint's certificate. null uses the system default.

trustManagerback to summary
public SslContextBuilder trustManager(TrustManager trustManager)

A single trusted manager for verifying the remote endpoint's certificate. This is helpful when custom implementation of 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.