- 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 SslContextBuilderapplicationProtocolConfig(ApplicationProtocolConfig apn)Application protocol negotiation configuration.SslContextbuild()Create newSslContextinstance with configured settings.SslContextBuilderciphers(Iterable<String> ciphers)The cipher suites to enable, in the order of preference.SslContextBuilderciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)The cipher suites to enable, in the order of preference.SslContextBuilderclientAuth(ClientAuth clientAuth)Sets the client authentication mode.SslContextBuilderenableOcsp(boolean enableOcsp)Enables OCSP stapling.static SslContextBuilderforClient()Creates a builder for new client-sideSslContext.static SslContextBuilderforServer(File keyCertChainFile, File keyFile)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(File keyCertChainFile, File keyFile, String keyPassword)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(InputStream keyCertChainInputStream, InputStream keyInputStream)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(PrivateKey key, X509Certificate... keyCertChain)Creates a builder for new server-sideSslContext.static SslContextBuilderforServer(KeyManager keyManager)Creates a builder for new server-sideSslContextwithKeyManager.static SslContextBuilderforServer(KeyManagerFactory keyManagerFactory)Creates a builder for new server-sideSslContext.SslContextBuilderkeyManager(File keyCertChainFile, File keyFile)Identifying certificate for this host.SslContextBuilderkeyManager(File keyCertChainFile, File keyFile, String keyPassword)Identifying certificate for this host.SslContextBuilderkeyManager(InputStream keyCertChainInputStream, InputStream keyInputStream)Identifying certificate for this host.SslContextBuilderkeyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)Identifying certificate for this host.SslContextBuilderkeyManager(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)Identifying certificate for this host.SslContextBuilderkeyManager(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Identifying certificate for this host.SslContextBuilderkeyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)Identifying certificate for this host.SslContextBuilderkeyManager(PrivateKey key, X509Certificate... keyCertChain)Identifying certificate for this host.SslContextBuilderkeyManager(KeyManager keyManager)A single key manager managing the identity information of this host.SslContextBuilderkeyManager(KeyManagerFactory keyManagerFactory)Identifying manager for this host.SslContextBuilderkeyStoreType(String keyStoreType)Sets theKeyStoretype that should be used.<T> SslContextBuilderoption(SslContextOption<T> option, T value)Configure aSslContextOption.SslContextBuilderprotocols(Iterable<String> protocols)The TLS protocol versions to enable.SslContextBuilderprotocols(String... protocols)The TLS protocol versions to enable.SslContextBuildersessionCacheSize(long sessionCacheSize)Set the size of the cache used for storing SSL session objects.SslContextBuildersessionTimeout(long sessionTimeout)Set the timeout for the cached SSL session objects, in seconds.SslContextBuildersslContextProvider(Provider sslContextProvider)The SSLContextProviderto use.SslContextBuildersslProvider(SslProvider provider)TheSslContextimplementation to use.SslContextBuilderstartTls(boolean startTls)trueif the first write request shouldn't be encrypted.SslContextBuildertrustManager(File trustCertCollectionFile)Trusted certificates for verifying the remote endpoint's certificate.SslContextBuildertrustManager(InputStream trustCertCollectionInputStream)Trusted certificates for verifying the remote endpoint's certificate.SslContextBuildertrustManager(Iterable<? extends X509Certificate> trustCertCollection)Trusted certificates for verifying the remote endpoint's certificate,nulluses the system default.SslContextBuildertrustManager(X509Certificate... trustCertCollection)Trusted certificates for verifying the remote endpoint's certificate,nulluses the system default.SslContextBuildertrustManager(TrustManager trustManager)A single trusted manager for verifying the remote endpoint's certificate.SslContextBuildertrustManager(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, ornullif 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, ornullif 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, ornullif 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, ornullif 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.OPENSSLorSslProvider.OPENSSL_REFCNTconsider usingOpenSslX509KeyManagerFactoryorOpenSslCachingX509KeyManagerFactory.- Parameters:
keyManagerFactory- non-nullfactory for server's private key- See Also:
keyManager(KeyManagerFactory)
-
forServer
public static SslContextBuilder forServer(KeyManager keyManager)
Creates a builder for new server-sideSslContextwithKeyManager.- Parameters:
keyManager- non-nullKeyManager for server's private key
-
option
public <T> SslContextBuilder option(SslContextOption<T> option, T value)
Configure aSslContextOption.
-
sslProvider
public SslContextBuilder sslProvider(SslProvider provider)
TheSslContextimplementation to use.nulluses the default one.
-
keyStoreType
public SslContextBuilder keyStoreType(String keyStoreType)
Sets theKeyStoretype that should be used.nulluses 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.nulluses 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.nulluses 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,nulluses the system default.
-
trustManager
public SslContextBuilder trustManager(Iterable<? extends X509Certificate> trustCertCollection)
Trusted certificates for verifying the remote endpoint's certificate,nulluses the system default.
-
trustManager
public SslContextBuilder trustManager(TrustManagerFactory trustManagerFactory)
Trusted manager for verifying the remote endpoint's certificate.nulluses 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 ofTrustManageris needed. Internally, a simple wrapper ofTrustManagerFactorythat only produces this specifiedTrustManagerwill 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.keyCertChainFileandkeyFilemay benullfor 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.keyCertChainInputStreamandkeyInputStreammay benullfor 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.keyCertChainandkeymay benullfor 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.keyCertChainandkeymay benullfor 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.keyCertChainFileandkeyFilemay benullfor 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, ornullif it's not password-protected
-
keyManager
public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Identifying certificate for this host.keyCertChainInputStreamandkeyInputStreammay benullfor 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, ornullif it's not password-protected
-
keyManager
public SslContextBuilder keyManager(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Identifying certificate for this host.keyCertChainandkeymay benullfor client contexts, which disables mutual authentication.- Parameters:
key- a PKCS#8 private key filekeyPassword- the password of thekey, ornullif 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.keyCertChainandkeymay benullfor client contexts, which disables mutual authentication.- Parameters:
key- a PKCS#8 private key filekeyPassword- the password of thekey, ornullif it's not password-protectedkeyCertChain- an X.509 certificate chain
-
keyManager
public SslContextBuilder keyManager(KeyManagerFactory keyManagerFactory)
Identifying manager for this host.keyManagerFactorymay benullfor client contexts, which disables mutual authentication. Using aKeyManagerFactoryis only supported forSslProvider.JDKorSslProvider.OPENSSL/SslProvider.OPENSSL_REFCNTif the used openssl version is 1.0.1+. You can check if your openssl version supports using aKeyManagerFactoryby callingOpenSsl.supportsKeyManagerFactory(). If this is not the case you must usekeyManager(File, File)orkeyManager(File, File, String). If you useSslProvider.OPENSSLorSslProvider.OPENSSL_REFCNTconsider usingOpenSslX509KeyManagerFactoryorOpenSslCachingX509KeyManagerFactory.
-
keyManager
public SslContextBuilder keyManager(KeyManager keyManager)
A single key manager managing the identity information of this host. This is helpful when custom implementation ofKeyManageris needed. Internally, a wrapper ofKeyManagerFactorythat only produces this specifiedKeyManagerwill 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.nullto use default cipher suites.
-
ciphers
public SslContextBuilder ciphers(Iterable<String> ciphers, CipherSuiteFilter cipherFilter)
The cipher suites to enable, in the order of preference.cipherFilterwill be applied to the ciphers before use. Ifciphersisnull, then the default cipher suites will be used.
-
applicationProtocolConfig
public SslContextBuilder applicationProtocolConfig(ApplicationProtocolConfig apn)
Application protocol negotiation configuration.nulldisables support.
-
sessionCacheSize
public SslContextBuilder sessionCacheSize(long sessionCacheSize)
Set the size of the cache used for storing SSL session objects.0to use the default value.
-
sessionTimeout
public SslContextBuilder sessionTimeout(long sessionTimeout)
Set the timeout for the cached SSL session objects, in seconds.0to 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, ornullto 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, ornullto enable the default protocols.- See Also:
SSLEngine.setEnabledCipherSuites(String[])
-
startTls
public SslContextBuilder startTls(boolean startTls)
trueif the first write request shouldn't be encrypted.
-
enableOcsp
@UnstableApi public SslContextBuilder enableOcsp(boolean enableOcsp)
Enables OCSP stapling. Please note that not allSslProviderimplementations support OCSP stapling and an exception will be thrown uponbuild().- See Also:
OpenSsl.isOcspSupported()
-
build
public SslContext build() throws SSLException
Create newSslContextinstance with configured settings.If
sslProvider(SslProvider)is set toSslProvider.OPENSSL_REFCNTthen the caller is responsible for releasing this object, or else native memory may leak.- Throws:
SSLException
-
-