Class SslUtils


  • public final class SslUtils
    extends java.lang.Object
    SSL utilities.
    Since:
    1.13
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SslUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.net.ssl.KeyManagerFactory getDefaultKeyManagerFactory()
      Returns the default key manager factory.
      static javax.net.ssl.TrustManagerFactory getDefaultTrustManagerFactory()
      Returns the default trust manager factory.
      static javax.net.ssl.KeyManagerFactory getPkixKeyManagerFactory()
      Returns the PKIX key manager factory.
      static javax.net.ssl.TrustManagerFactory getPkixTrustManagerFactory()
      Returns the PKIX trust manager factory.
      static javax.net.ssl.SSLContext getSslContext()
      Returns the SSL context for "SSL" algorithm.
      static javax.net.ssl.SSLContext getTlsSslContext()
      Returns the SSL context for "TLS" algorithm.
      static javax.net.ssl.SSLContext initSslContext​(javax.net.ssl.SSLContext sslContext, java.security.KeyStore trustStore, javax.net.ssl.TrustManagerFactory trustManagerFactory)
      Initializes the SSL context to the trust managers supplied by the trust manager factory for the given trust store.
      static javax.net.ssl.SSLContext initSslContext​(javax.net.ssl.SSLContext sslContext, java.security.KeyStore trustStore, javax.net.ssl.TrustManagerFactory trustManagerFactory, java.security.KeyStore mtlsKeyStore, java.lang.String mtlsKeyStorePassword, javax.net.ssl.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.
      static javax.net.ssl.HostnameVerifier trustAllHostnameVerifier()
      Beta
      Returns a verifier that trusts all host names.
      static javax.net.ssl.SSLContext trustAllSSLContext()
      Beta
      Returns an SSL context in which all X.509 certificates are trusted.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SslUtils

        private SslUtils()
    • Method Detail

      • getSslContext

        public static javax.net.ssl.SSLContext getSslContext()
                                                      throws java.security.NoSuchAlgorithmException
        Returns the SSL context for "SSL" algorithm.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • getTlsSslContext

        public static javax.net.ssl.SSLContext getTlsSslContext()
                                                         throws java.security.NoSuchAlgorithmException
        Returns the SSL context for "TLS" algorithm.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • getDefaultTrustManagerFactory

        public static javax.net.ssl.TrustManagerFactory getDefaultTrustManagerFactory()
                                                                               throws java.security.NoSuchAlgorithmException
        Returns the default trust manager factory.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • getPkixTrustManagerFactory

        public static javax.net.ssl.TrustManagerFactory getPkixTrustManagerFactory()
                                                                            throws java.security.NoSuchAlgorithmException
        Returns the PKIX trust manager factory.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • getDefaultKeyManagerFactory

        public static javax.net.ssl.KeyManagerFactory getDefaultKeyManagerFactory()
                                                                           throws java.security.NoSuchAlgorithmException
        Returns the default key manager factory.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • getPkixKeyManagerFactory

        public static javax.net.ssl.KeyManagerFactory getPkixKeyManagerFactory()
                                                                        throws java.security.NoSuchAlgorithmException
        Returns the PKIX key manager factory.
        Throws:
        java.security.NoSuchAlgorithmException
        Since:
        1.14
      • initSslContext

        @CanIgnoreReturnValue
        public static javax.net.ssl.SSLContext initSslContext​(javax.net.ssl.SSLContext sslContext,
                                                              java.security.KeyStore trustStore,
                                                              javax.net.ssl.TrustManagerFactory trustManagerFactory)
                                                       throws java.security.GeneralSecurityException
        Initializes the SSL context to the trust managers supplied by the trust manager factory for the given trust store.
        Parameters:
        sslContext - SSL context (for example SSLContext.getInstance(java.lang.String))
        trustStore - key store for certificates to trust (for example SecurityUtils.getJavaKeyStore())
        trustManagerFactory - trust manager factory (for example getPkixTrustManagerFactory())
        Throws:
        java.security.GeneralSecurityException
        Since:
        1.14
      • initSslContext

        @Beta
        public static javax.net.ssl.SSLContext initSslContext​(javax.net.ssl.SSLContext sslContext,
                                                              java.security.KeyStore trustStore,
                                                              javax.net.ssl.TrustManagerFactory trustManagerFactory,
                                                              java.security.KeyStore mtlsKeyStore,
                                                              java.lang.String mtlsKeyStorePassword,
                                                              javax.net.ssl.KeyManagerFactory keyManagerFactory)
                                                       throws java.security.GeneralSecurityException
        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:
        sslContext - SSL context (for example SSLContext.getInstance(java.lang.String))
        trustStore - key store for certificates to trust (for example SecurityUtils.getJavaKeyStore())
        trustManagerFactory - trust manager factory (for example getPkixTrustManagerFactory())
        mtlsKeyStore - key store for client certificate and key to establish mutual TLS
        mtlsKeyStorePassword - password for mtlsKeyStore parameter
        keyManagerFactory - key manager factory (for example getDefaultKeyManagerFactory())
        Throws:
        java.security.GeneralSecurityException
        Since:
        1.38
      • trustAllSSLContext

        @Beta
        public static javax.net.ssl.SSLContext trustAllSSLContext()
                                                           throws java.security.GeneralSecurityException
        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.

        Throws:
        java.security.GeneralSecurityException
      • trustAllHostnameVerifier

        @Beta
        public static javax.net.ssl.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.