Class SslContextBuilder


  • public class SslContextBuilder
    extends java.lang.Object
    Builder for SSLContext instances.

    Please note: the default Oracle JSSE implementation of SSLContext.init(KeyManager[], TrustManager[], SecureRandom) accepts multiple key and trust managers, however only first matching type is ever used. See for example: SSLContext.html#init

    Since:
    4.4
    • Constructor Detail

      • SslContextBuilder

        public SslContextBuilder()
    • Method Detail

      • setSecureRandom

        public SslContextBuilder setSecureRandom​(java.security.SecureRandom secureRandom)
      • setProvider

        public SslContextBuilder setProvider​(java.security.Provider provider)
      • loadTrustMaterial

        public SslContextBuilder loadTrustMaterial​(java.security.KeyStore truststore)
                                            throws java.security.NoSuchAlgorithmException,
                                                   java.security.KeyStoreException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
      • loadTrustMaterial

        public SslContextBuilder loadTrustMaterial()
                                            throws java.security.NoSuchAlgorithmException,
                                                   java.security.KeyStoreException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
      • loadTrustMaterial

        public SslContextBuilder loadTrustMaterial​(java.io.File file,
                                                   char[] storePassword)
                                            throws java.security.NoSuchAlgorithmException,
                                                   java.security.KeyStoreException,
                                                   java.security.cert.CertificateException,
                                                   java.io.IOException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
        java.security.cert.CertificateException
        java.io.IOException
      • loadTrustMaterial

        public SslContextBuilder loadTrustMaterial​(java.io.InputStream instream,
                                                   char[] storePassword)
                                            throws java.security.NoSuchAlgorithmException,
                                                   java.security.KeyStoreException,
                                                   java.security.cert.CertificateException,
                                                   java.io.IOException
        Load trust material from keystore in input stream. The specified stream remains open after this method returns.
        Parameters:
        instream - input stream that contains the keystore.
        storePassword - Keystore password.
        Returns:
        an SslContextbuilder which trusts the certificates in the keystore.
        Throws:
        java.security.NoSuchAlgorithmException - If th keystore type or other algorithms is not supported.
        java.security.KeyStoreException - if error occurs when parsing the keystore.
        java.security.cert.CertificateException - if error occurs when parsing the certificates.
        java.io.IOException - if error occurs when reading keystore from the input stream.
      • loadKeyMaterial

        public SslContextBuilder loadKeyMaterial​(java.security.KeyStore keystore,
                                                 char[] keyPassword)
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.security.KeyStoreException,
                                                 java.security.UnrecoverableKeyException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
        java.security.UnrecoverableKeyException
      • loadKeyMaterial

        public SslContextBuilder loadKeyMaterial​(java.io.File file,
                                                 char[] storePassword,
                                                 char[] keyPassword)
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.security.KeyStoreException,
                                                 java.security.UnrecoverableKeyException,
                                                 java.security.cert.CertificateException,
                                                 java.io.IOException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
        java.security.UnrecoverableKeyException
        java.security.cert.CertificateException
        java.io.IOException
      • loadKeyMaterial

        public SslContextBuilder loadKeyMaterial​(java.io.InputStream instream,
                                                 char[] storePassword,
                                                 char[] keyPassword)
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.security.KeyStoreException,
                                                 java.security.UnrecoverableKeyException,
                                                 java.security.cert.CertificateException,
                                                 java.io.IOException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyStoreException
        java.security.UnrecoverableKeyException
        java.security.cert.CertificateException
        java.io.IOException
      • initSSLContext

        protected void initSSLContext​(javax.net.ssl.SSLContext sslContext,
                                      java.util.Collection<javax.net.ssl.KeyManager> keyManagers,
                                      java.util.Collection<javax.net.ssl.TrustManager> trustManagers,
                                      java.security.SecureRandom secureRandom)
                               throws java.security.KeyManagementException
        Throws:
        java.security.KeyManagementException
      • build

        public javax.net.ssl.SSLContext build()
                                       throws java.security.NoSuchAlgorithmException,
                                              java.security.KeyManagementException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyManagementException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object