Package org.apache.hc.core5.ssl
Class SSLContextBuilder
- java.lang.Object
-
- org.apache.hc.core5.ssl.SSLContextBuilder
-
public class SSLContextBuilder extends java.lang.ObjectBuilder forSSLContextinstances.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 Description SSLContextBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.net.ssl.SSLContextbuild()Builds a new SSLContext.static SSLContextBuildercreate()protected voidinitSSLContext(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)SSLContextBuilderloadKeyMaterial(java.io.File file, char[] storePassword, char[] keyPassword)SSLContextBuilderloadKeyMaterial(java.io.File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)SSLContextBuilderloadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword)SSLContextBuilderloadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)SSLContextBuilderloadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, java.nio.file.OpenOption... openOptions)SSLContextBuilderloadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, java.nio.file.OpenOption... openOptions)SSLContextBuilderloadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword)SSLContextBuilderloadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy)SSLContextBuilderloadTrustMaterial(java.io.File file)SSLContextBuilderloadTrustMaterial(java.io.File file, char[] storePassword)SSLContextBuilderloadTrustMaterial(java.io.File file, char[] storePassword, TrustStrategy trustStrategy)SSLContextBuilderloadTrustMaterial(java.net.URL url, char[] storePassword)SSLContextBuilderloadTrustMaterial(java.net.URL url, char[] storePassword, TrustStrategy trustStrategy)SSLContextBuilderloadTrustMaterial(java.nio.file.Path file)SSLContextBuilderloadTrustMaterial(java.nio.file.Path file, char[] storePassword)SSLContextBuilderloadTrustMaterial(java.nio.file.Path file, char[] storePassword, TrustStrategy trustStrategy, java.nio.file.OpenOption... openOptions)SSLContextBuilderloadTrustMaterial(java.security.KeyStore trustStore, TrustStrategy trustStrategy)SSLContextBuilderloadTrustMaterial(TrustStrategy trustStrategy)SSLContextBuildersetKeyManagerFactoryAlgorithm(java.lang.String keyManagerFactoryAlgorithm)Sets the key manager factory algorithm name.SSLContextBuildersetKeyStoreProvider(java.lang.String name)Sets the JCA provider name to use for creating key stores.SSLContextBuildersetKeyStoreProvider(java.security.Provider provider)Sets the JCA provider to use for creating key stores.SSLContextBuildersetKeyStoreType(java.lang.String keyStoreType)Sets the key store type.SSLContextBuildersetProtocol(java.lang.String protocol)Sets the SSLContext algorithm name.SSLContextBuildersetProvider(java.lang.String name)SSLContextBuildersetProvider(java.security.Provider provider)SSLContextBuildersetSecureRandom(java.security.SecureRandom secureRandom)SSLContextBuildersetTrustManagerFactoryAlgorithm(java.lang.String trustManagerFactoryAlgorithm)Sets the trust manager factory algorithm name.SSLContextBuildersetTrustStoreProvider(java.lang.String name)Sets the JCA provider name to use for creating trust stores.SSLContextBuildersetTrustStoreProvider(java.security.Provider provider)Sets the JCA provider to use for creating trust stores.java.lang.StringtoString()
-
-
-
Method Detail
-
create
public static SSLContextBuilder create()
-
setProtocol
public SSLContextBuilder setProtocol(java.lang.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 instance.
- See Also:
- Java Cryptography Architecture Standard Algorithm Name Documentation
-
setProvider
public SSLContextBuilder setProvider(java.security.Provider provider)
-
setProvider
public SSLContextBuilder setProvider(java.lang.String name)
-
setTrustStoreProvider
public SSLContextBuilder setTrustStoreProvider(java.security.Provider provider)
Sets the JCA provider to use for creating trust stores.- Parameters:
provider- provider to use for creating trust stores.- Returns:
- this instance.
- Since:
- 5.2
-
setTrustStoreProvider
public SSLContextBuilder setTrustStoreProvider(java.lang.String name) throws java.security.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 instance.
- Throws:
java.security.NoSuchProviderException- if no provider with the specified name is installed or if name is null.- Since:
- 5.2
-
setKeyStoreProvider
public SSLContextBuilder setKeyStoreProvider(java.security.Provider provider)
Sets the JCA provider to use for creating key stores.- Parameters:
provider- provider to use for creating key stores.- Returns:
- this instance.
- Since:
- 5.2
-
setKeyStoreProvider
public SSLContextBuilder setKeyStoreProvider(java.lang.String name) throws java.security.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 instance.
- Throws:
java.security.NoSuchProviderException- if no provider with the specified name is installed or if name is null.- Since:
- 5.2
-
setKeyStoreType
public SSLContextBuilder setKeyStoreType(java.lang.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 instance.
- Since:
- 4.4.7
- See Also:
- Java Cryptography Architecture Standard Algorithm Name Documentation
-
setKeyManagerFactoryAlgorithm
public SSLContextBuilder setKeyManagerFactoryAlgorithm(java.lang.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 instance.
- Since:
- 4.4.7
- See Also:
- Java Cryptography Architecture Standard Algorithm Name Documentation
-
setTrustManagerFactoryAlgorithm
public SSLContextBuilder setTrustManagerFactoryAlgorithm(java.lang.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 instance.
- Since:
- 4.4.7
- See Also:
- Java Cryptography Architecture Standard Algorithm Name Documentation
-
setSecureRandom
public SSLContextBuilder setSecureRandom(java.security.SecureRandom secureRandom)
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.security.KeyStore trustStore, TrustStrategy trustStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException
- Parameters:
trustStrategy- custom trust strategy to use; can benullin which case only the default trust managers will be used- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if a TrustManagerFactory operation fails.
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.nio.file.Path file) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if no Provider supports a KeyStoreSpi implementation for the specified type.java.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded.java.io.IOException- if an I/O exception occurs.- Since:
- 5.2
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.nio.file.Path file, char[] storePassword) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if no Provider supports a KeyStoreSpi implementation for the specified type.java.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded.java.io.IOException- if an I/O exception occurs.- Since:
- 5.2
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.nio.file.Path file, char[] storePassword, TrustStrategy trustStrategy, java.nio.file.OpenOption... openOptions) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if no Provider supports a KeyStoreSpi implementation for the specified type.java.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded.java.io.IOException- if an I/O exception occurs.- Since:
- 5.2
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(TrustStrategy trustStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreException
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.io.File file, char[] storePassword, TrustStrategy trustStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
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.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.io.File file) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.net.URL url, char[] storePassword, TrustStrategy trustStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.net.URL url, char[] storePassword) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyException
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, java.nio.file.OpenOption... openOptions) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.cert.CertificateException, java.io.IOException
- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if no Provider supports a KeyStoreSpi implementation for the specified type.java.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded.java.io.IOException- if an I/O exception occurs.java.security.UnrecoverableKeyException- if the key cannot be recovered (for example, the given password is wrong).- Since:
- 5.2
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, java.nio.file.OpenOption... openOptions) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.cert.CertificateException, java.io.IOException
- Returns:
- this instance.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyStoreException- if no Provider supports a KeyStoreSpi implementation for the specified type.java.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded.java.io.IOException- if an I/O exception occurs.java.security.UnrecoverableKeyException- if the key cannot be recovered (for example, the given password is wrong).- Since:
- 5.2
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyException
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.io.File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
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.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.cert.CertificateExceptionjava.io.IOException
-
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.cert.CertificateException, java.io.IOException
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.cert.CertificateExceptionjava.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- if this SSLContext operation fails.
-
build
public javax.net.ssl.SSLContext build() throws java.security.NoSuchAlgorithmException, java.security.KeyManagementExceptionBuilds a new SSLContext.- Returns:
- a new SSLContext.
- Throws:
java.security.NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.java.security.KeyManagementException- if this SSLContext operation fails.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-