org.apache.http.ssl
Class SSLContextBuilder

java.lang.Object
  extended by org.apache.http.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

TODO Specify which Oracle JSSE versions the above has been verified.

Since:
4.4

Constructor Summary
SSLContextBuilder()
           
 
Method Summary
 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(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(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 setKeyStoreType(String keyStoreType)
          Sets the key store type.
 SSLContextBuilder setProtocol(String protocol)
          Sets the SSLContext protocol 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.
 String toString()
           
 SSLContextBuilder useProtocol(String protocol)
          Deprecated. Use setProtocol(String).
 
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()

useProtocol

@Deprecated
public SSLContextBuilder useProtocol(String protocol)
Deprecated. Use setProtocol(String).

Sets the SSLContext protocol algorithm name.

Parameters:
protocol - the SSLContext protocol 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

setProtocol

public SSLContextBuilder setProtocol(String protocol)
Sets the SSLContext protocol algorithm name.

Parameters:
protocol - the SSLContext protocol 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
Since:
4.4.7
See Also:
Java Cryptography Architecture Standard Algorithm Name Documentation

setSecureRandom

public SSLContextBuilder setSecureRandom(SecureRandom secureRandom)

setProvider

public SSLContextBuilder setProvider(Provider provider)

setProvider

public SSLContextBuilder setProvider(String name)

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

loadTrustMaterial

public SSLContextBuilder loadTrustMaterial(KeyStore truststore,
                                           TrustStrategy trustStrategy)
                                    throws NoSuchAlgorithmException,
                                           KeyStoreException
Throws:
NoSuchAlgorithmException
KeyStoreException

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(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–2019 The Apache Software Foundation. All rights reserved.