org.apache.hc.core5.ssl

## Class SSLContextBuilder

- java.lang.Object
- - org.apache.hc.core5.ssl.SSLContextBuilder

-     public class SSLContextBuilder
      extends 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 only first matching type is ever used. See for example: SSLContext.html#init

  Since:
    4.4

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SSLContextBuilder()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `SSLContext` | `build()`
    `static SSLContextBuilder` | `create()`
    `protected void` | `initSSLContext(SSLContext sslContext, Collection<KeyManager> keyManagers, Collection<TrustManager> trustManagers, SecureRandom secureRandom)`
    `SSLContextBuilder` | `loadKeyMaterial(File file, char[] storePassword, char[] keyPassword)`
    `SSLContextBuilder` | `loadKeyMaterial(File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)`
    `SSLContextBuilder` | `loadKeyMaterial(KeyStore keyStore, char[] keyPassword)`
    `SSLContextBuilder` | `loadKeyMaterial(KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy)`
    `SSLContextBuilder` | `loadKeyMaterial(Path file, char[] storePassword, char[] keyPassword, OpenOption... openOptions)`
    `SSLContextBuilder` | `loadKeyMaterial(Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, OpenOption... openOptions)`
    `SSLContextBuilder` | `loadKeyMaterial(URL url, char[] storePassword, char[] keyPassword)`
    `SSLContextBuilder` | `loadKeyMaterial(URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)`
    `SSLContextBuilder` | `loadTrustMaterial(File file)`
    `SSLContextBuilder` | `loadTrustMaterial(File file, char[] storePassword)`
    `SSLContextBuilder` | `loadTrustMaterial(File file, char[] storePassword, TrustStrategy trustStrategy)`
    `SSLContextBuilder` | `loadTrustMaterial(KeyStore trustStore, TrustStrategy trustStrategy)`
    `SSLContextBuilder` | `loadTrustMaterial(Path file)`
    `SSLContextBuilder` | `loadTrustMaterial(Path file, char[] storePassword)`
    `SSLContextBuilder` | `loadTrustMaterial(Path file, char[] storePassword, TrustStrategy trustStrategy, OpenOption... openOptions)`
    `SSLContextBuilder` | `loadTrustMaterial(TrustStrategy trustStrategy)`
    `SSLContextBuilder` | `loadTrustMaterial(URL url, char[] storePassword)`
    `SSLContextBuilder` | `loadTrustMaterial(URL url, char[] storePassword, TrustStrategy trustStrategy)`
    `SSLContextBuilder` | `setKeyManagerFactoryAlgorithm(String keyManagerFactoryAlgorithm)` Sets the key manager factory algorithm name.
    `SSLContextBuilder` | `setKeyStoreProvider(Provider provider)` Sets the JCA provider to use for creating key stores.
    `SSLContextBuilder` | `setKeyStoreProvider(String name)` Sets the JCA provider name to use for creating key stores.
    `SSLContextBuilder` | `setKeyStoreType(String keyStoreType)` Sets the key store type.
    `SSLContextBuilder` | `setProtocol(String protocol)` Sets the SSLContext algorithm name.
    `SSLContextBuilder` | `setProvider(Provider provider)`
    `SSLContextBuilder` | `setProvider(String name)`
    `SSLContextBuilder` | `setSecureRandom(SecureRandom secureRandom)`
    `SSLContextBuilder` | `setTrustManagerFactoryAlgorithm(String trustManagerFactoryAlgorithm)` Sets the trust manager factory algorithm name.
    `SSLContextBuilder` | `setTrustStoreProvider(Provider provider)` Sets the JCA provider to use for creating trust stores.
    `SSLContextBuilder` | `setTrustStoreProvider(String name)` Sets the JCA provider name to use for creating trust stores.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SSLContextBuilder

          public SSLContextBuilder()

  - ### Method Detail

    - #### create

          public static SSLContextBuilder create()

    - #### setProtocol

          public SSLContextBuilder setProtocol(String protocol)

      Sets the SSLContext algorithm name.
      Parameters:
        `protocol` - the SSLContext algorithm name of the requested protocol. See the SSLContext section in the Java Cryptography Architecture Standard Algorithm Name Documentation for more information.
      Returns:
        this builder
      See Also:
        Java Cryptography Architecture Standard Algorithm Name Documentation

    - #### setProvider

          public SSLContextBuilder setProvider(Provider provider)

    - #### setProvider

          public SSLContextBuilder setProvider(String name)

    - #### setTrustStoreProvider

          public SSLContextBuilder setTrustStoreProvider(Provider provider)

      Sets the JCA provider to use for creating trust stores.
      Parameters:
        `provider` - provider to use for creating trust stores.
      Returns:
        this builder
      Since:
        5.2

    - #### setTrustStoreProvider

          public SSLContextBuilder setTrustStoreProvider(String name)
                                                  throws NoSuchProviderException

      Sets the JCA provider name to use for creating trust stores.
      Parameters:
        `name` - Name of the provider to use for creating trust stores, the provider must be registered with the JCA.
      Returns:
        this builder
      Throws:
        `NoSuchProviderException`
      Since:
        5.2

    - #### setKeyStoreProvider

          public SSLContextBuilder setKeyStoreProvider(Provider provider)

      Sets the JCA provider to use for creating key stores.
      Parameters:
        `provider` - provider to use for creating key stores.
      Returns:
        this builder
      Since:
        5.2

    - #### setKeyStoreProvider

          public SSLContextBuilder setKeyStoreProvider(String name)
                                                throws NoSuchProviderException

      Sets the JCA provider name to use for creating key stores.
      Parameters:
        `name` - Name of the provider to use for creating key stores, the provider must be registered with the JCA.
      Returns:
        this builder
      Throws:
        `NoSuchProviderException`
      Since:
        5.2

    - #### setKeyStoreType

          public SSLContextBuilder setKeyStoreType(String keyStoreType)

      Sets the key store type.
      Parameters:
        `keyStoreType` - the SSLkey store type. See the KeyStore section in the Java Cryptography Architecture Standard Algorithm Name Documentation for more information.
      Returns:
        this builder
      Since:
        4.4.7
      See Also:
        Java Cryptography Architecture Standard Algorithm Name Documentation

    - #### setKeyManagerFactoryAlgorithm

          public SSLContextBuilder setKeyManagerFactoryAlgorithm(String keyManagerFactoryAlgorithm)

      Sets the key manager factory algorithm name.
      Parameters:
        `keyManagerFactoryAlgorithm` - the key manager factory algorithm name of the requested protocol. See the KeyManagerFactory section in the Java Cryptography Architecture Standard Algorithm Name Documentation for more information.
      Returns:
        this builder
      Since:
        4.4.7
      See Also:
        Java Cryptography Architecture Standard Algorithm Name Documentation

    - #### setTrustManagerFactoryAlgorithm

          public SSLContextBuilder setTrustManagerFactoryAlgorithm(String trustManagerFactoryAlgorithm)

      Sets the trust manager factory algorithm name.
      Parameters:
        `trustManagerFactoryAlgorithm` - the trust manager algorithm name of the requested protocol. See the TrustManagerFactory section in the Java Cryptography Architecture Standard Algorithm Name Documentation for more information.
      Returns:
        this builder
      Since:
        4.4.7
      See Also:
        Java Cryptography Architecture Standard Algorithm Name Documentation

    - #### setSecureRandom

          public SSLContextBuilder setSecureRandom(SecureRandom secureRandom)

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(KeyStore trustStore,
                                                     TrustStrategy trustStrategy)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(Path file)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`
      Since:
        5.2

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(Path file,
                                                     char[] storePassword)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`
      Since:
        5.2

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(Path file,
                                                     char[] storePassword,
                                                     TrustStrategy trustStrategy,
                                                     OpenOption... openOptions)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`
      Since:
        5.2

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(TrustStrategy trustStrategy)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(File file,
                                                     char[] storePassword,
                                                     TrustStrategy trustStrategy)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(File file,
                                                     char[] storePassword)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(File file)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(URL url,
                                                     char[] storePassword,
                                                     TrustStrategy trustStrategy)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`

    - #### loadTrustMaterial

          public SSLContextBuilder loadTrustMaterial(URL url,
                                                     char[] storePassword)
                                              throws NoSuchAlgorithmException,
                                                     KeyStoreException,
                                                     CertificateException,
                                                     IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `CertificateException`
        `IOException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(KeyStore keyStore,
                                                   char[] keyPassword,
                                                   PrivateKeyStrategy aliasStrategy)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(Path file,
                                                   char[] storePassword,
                                                   char[] keyPassword,
                                                   OpenOption... openOptions)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`
      Since:
        5.2

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(Path file,
                                                   char[] storePassword,
                                                   char[] keyPassword,
                                                   PrivateKeyStrategy aliasStrategy,
                                                   OpenOption... openOptions)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`
      Since:
        5.2

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(KeyStore keyStore,
                                                   char[] keyPassword)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(File file,
                                                   char[] storePassword,
                                                   char[] keyPassword,
                                                   PrivateKeyStrategy aliasStrategy)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(File file,
                                                   char[] storePassword,
                                                   char[] keyPassword)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(URL url,
                                                   char[] storePassword,
                                                   char[] keyPassword,
                                                   PrivateKeyStrategy aliasStrategy)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`

    - #### loadKeyMaterial

          public SSLContextBuilder loadKeyMaterial(URL url,
                                                   char[] storePassword,
                                                   char[] keyPassword)
                                            throws NoSuchAlgorithmException,
                                                   KeyStoreException,
                                                   UnrecoverableKeyException,
                                                   CertificateException,
                                                   IOException

      Throws:
        `NoSuchAlgorithmException`
        `KeyStoreException`
        `UnrecoverableKeyException`
        `CertificateException`
        `IOException`

    - #### initSSLContext

          protected void initSSLContext(SSLContext sslContext,
                                        Collection<KeyManager> keyManagers,
                                        Collection<TrustManager> trustManagers,
                                        SecureRandom secureRandom)
                                 throws KeyManagementException

      Throws:
        `KeyManagementException`

    - #### build

          public SSLContext build()
                           throws NoSuchAlgorithmException,
                                  KeyManagementException

      Throws:
        `NoSuchAlgorithmException`
        `KeyManagementException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.