public final class SslUtilsSSL utilities.
Static Methods
getDefaultKeyManagerFactory()
public static KeyManagerFactory getDefaultKeyManagerFactory()Returns the default key manager factory.
| Returns | |
|---|---|
| Type | Description |
KeyManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getDefaultKeyManagerFactory(Provider provider)
public static KeyManagerFactory getDefaultKeyManagerFactory(Provider provider)Returns the default key manager factory using the specified provider.
| Parameter | |
|---|---|
| Name | Description |
provider |
Providerthe security provider, or |
| Returns | |
|---|---|
| Type | Description |
KeyManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getDefaultTrustManagerFactory()
public static TrustManagerFactory getDefaultTrustManagerFactory()Returns the default trust manager factory.
| Returns | |
|---|---|
| Type | Description |
TrustManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getDefaultTrustManagerFactory(Provider provider)
public static TrustManagerFactory getDefaultTrustManagerFactory(Provider provider)Returns the default trust manager factory using the specified provider.
Aligning the trust manager factory's provider with the SSLContext's provider is necessary to prevent handshake failures. For example, if Conscrypt is used for the SSLContext but the default SunJSSE TrustManager is used, TLS 1.3 handshakes will fail with "Unknown authType: GENERIC" because SunJSSE does not recognize Conscrypt's "GENERIC" authentication type string.
| Parameter | |
|---|---|
| Name | Description |
provider |
Providerthe security provider, or |
| Returns | |
|---|---|
| Type | Description |
TrustManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getPkixKeyManagerFactory()
public static KeyManagerFactory getPkixKeyManagerFactory()Returns the PKIX key manager factory.
| Returns | |
|---|---|
| Type | Description |
KeyManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getPkixTrustManagerFactory()
public static TrustManagerFactory getPkixTrustManagerFactory()Returns the PKIX trust manager factory.
| Returns | |
|---|---|
| Type | Description |
TrustManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getPkixTrustManagerFactory(Provider provider)
public static TrustManagerFactory getPkixTrustManagerFactory(Provider provider)Returns the PKIX trust manager factory using the specified provider.
Aligning the trust manager factory's provider with the SSLContext's provider is necessary to prevent handshake failures. For example, if Conscrypt is used for the SSLContext but the default SunJSSE TrustManager is used, TLS 1.3 handshakes will fail with "Unknown authType: GENERIC" because SunJSSE does not recognize Conscrypt's "GENERIC" authentication type string.
| Parameter | |
|---|---|
| Name | Description |
provider |
Providerthe security provider, or |
| Returns | |
|---|---|
| Type | Description |
TrustManagerFactory |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getSslContext()
public static SSLContext getSslContext()Returns the SSL context for "SSL" algorithm.
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getTlsSslContext()
public static SSLContext getTlsSslContext()Returns the SSL context for "TLS" algorithm.
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
getTlsSslContext(Provider provider)
public static SSLContext getTlsSslContext(Provider provider)Returns the SSL context for "TLS" algorithm using the specified provider.
If a custom provider (e.g., Conscrypt) is configured, the context must be loaded from it to enable the provider's specific TLS parameters and curve groups (such as PQC).
| Parameter | |
|---|---|
| Name | Description |
provider |
Providerthe security provider, or |
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
NoSuchAlgorithmException |
|
initSslContext(SSLContext sslContext, KeyStore trustStore, TrustManagerFactory trustManagerFactory)
public static SSLContext initSslContext(SSLContext sslContext, KeyStore trustStore, TrustManagerFactory trustManagerFactory)Initializes the SSL context to the trust managers supplied by the trust manager factory for the given trust store.
| Parameters | |
|---|---|
| Name | Description |
sslContext |
SSLContextSSL context (for example SSLContext#getInstance) |
trustStore |
KeyStorekey store for certificates to trust (for example SecurityUtils#getJavaKeyStore()) |
trustManagerFactory |
TrustManagerFactorytrust manager factory (for example #getPkixTrustManagerFactory()) |
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
initSslContext(SSLContext sslContext, KeyStore trustStore, TrustManagerFactory trustManagerFactory, KeyStore mtlsKeyStore, String mtlsKeyStorePassword, KeyManagerFactory keyManagerFactory)
public static SSLContext initSslContext(SSLContext sslContext, KeyStore trustStore, TrustManagerFactory trustManagerFactory, KeyStore mtlsKeyStore, String mtlsKeyStorePassword, KeyManagerFactory keyManagerFactory)Beta
Initializes the SSL context to the trust managers supplied by the trust manager factory for the
given trust store, and to the key managers supplied by the key manager factory for the given
key store.
| Parameters | |
|---|---|
| Name | Description |
sslContext |
SSLContextSSL context (for example SSLContext#getInstance) |
trustStore |
KeyStorekey store for certificates to trust (for example SecurityUtils#getJavaKeyStore()) |
trustManagerFactory |
TrustManagerFactorytrust manager factory (for example #getPkixTrustManagerFactory()) |
mtlsKeyStore |
KeyStorekey store for client certificate and key to establish mutual TLS |
mtlsKeyStorePassword |
Stringpassword for mtlsKeyStore parameter |
keyManagerFactory |
KeyManagerFactorykey manager factory (for example #getDefaultKeyManagerFactory()) |
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
trustAllHostnameVerifier()
public static HostnameVerifier trustAllHostnameVerifier()Beta
Returns a verifier that trusts all host names.
Be careful! Disabling host name verification is dangerous and should only be done in testing environments.
| Returns | |
|---|---|
| Type | Description |
HostnameVerifier |
|
trustAllSSLContext()
public static SSLContext trustAllSSLContext()Beta
Returns an SSL context in which all X.509 certificates are trusted.
Be careful! Disabling SSL certificate validation is dangerous and should only be done in testing environments.
| Returns | |
|---|---|
| Type | Description |
SSLContext |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|