Package org.apache.hc.core5.ssl
Class SSLContextBuilder
- java.lang.Object
-
- org.apache.hc.core5.ssl.SSLContextBuilder
-
public class SSLContextBuilder extends java.lang.Object
Builder forSSLContext
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SSLContextBuilder.KeyManagerDelegate
(package private) static class
SSLContextBuilder.TrustManagerDelegate
-
Field Summary
Fields Modifier and Type Field Description private static javax.net.ssl.KeyManager[]
EMPTY_KEY_MANAGER_ARRAY
An empty immutableKeyManager
array.private static javax.net.ssl.TrustManager[]
EMPTY_TRUST_MANAGER_ARRAY
An empty immutableTrustManager
array.private java.lang.String
keyManagerFactoryAlgorithm
private java.util.Set<javax.net.ssl.KeyManager>
keyManagers
private java.lang.String
keyStoreType
private java.security.Provider
ksProvider
private java.lang.String
protocol
private java.security.Provider
provider
private java.security.SecureRandom
secureRandom
(package private) static java.lang.String
TLS
private java.lang.String
trustManagerFactoryAlgorithm
private java.util.Set<javax.net.ssl.TrustManager>
trustManagers
private java.security.Provider
tsProvider
-
Constructor Summary
Constructors Constructor Description SSLContextBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.net.ssl.SSLContext
build()
static SSLContextBuilder
create()
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)
SSLContextBuilder
loadKeyMaterial(java.io.File file, char[] storePassword, char[] keyPassword)
SSLContextBuilder
loadKeyMaterial(java.io.File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)
SSLContextBuilder
loadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword)
SSLContextBuilder
loadKeyMaterial(java.net.URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy)
SSLContextBuilder
loadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, java.nio.file.OpenOption... openOptions)
SSLContextBuilder
loadKeyMaterial(java.nio.file.Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, java.nio.file.OpenOption... openOptions)
SSLContextBuilder
loadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword)
SSLContextBuilder
loadKeyMaterial(java.security.KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy)
private java.security.KeyStore
loadKeyStore(java.net.URL url, char[] password)
private java.security.KeyStore
loadKeyStore(java.nio.file.Path file, char[] password, java.nio.file.OpenOption... openOptions)
SSLContextBuilder
loadTrustMaterial(java.io.File file)
SSLContextBuilder
loadTrustMaterial(java.io.File file, char[] storePassword)
SSLContextBuilder
loadTrustMaterial(java.io.File file, char[] storePassword, TrustStrategy trustStrategy)
SSLContextBuilder
loadTrustMaterial(java.net.URL url, char[] storePassword)
SSLContextBuilder
loadTrustMaterial(java.net.URL url, char[] storePassword, TrustStrategy trustStrategy)
SSLContextBuilder
loadTrustMaterial(java.nio.file.Path file)
SSLContextBuilder
loadTrustMaterial(java.nio.file.Path file, char[] storePassword)
SSLContextBuilder
loadTrustMaterial(java.nio.file.Path file, char[] storePassword, TrustStrategy trustStrategy, java.nio.file.OpenOption... openOptions)
SSLContextBuilder
loadTrustMaterial(java.security.KeyStore trustStore, TrustStrategy trustStrategy)
SSLContextBuilder
loadTrustMaterial(TrustStrategy trustStrategy)
private java.security.Provider
requireNonNullProvider(java.lang.String name)
SSLContextBuilder
setKeyManagerFactoryAlgorithm(java.lang.String keyManagerFactoryAlgorithm)
Sets the key manager factory algorithm name.SSLContextBuilder
setKeyStoreProvider(java.lang.String name)
Sets the JCA provider name to use for creating key stores.SSLContextBuilder
setKeyStoreProvider(java.security.Provider provider)
Sets the JCA provider to use for creating key stores.SSLContextBuilder
setKeyStoreType(java.lang.String keyStoreType)
Sets the key store type.SSLContextBuilder
setProtocol(java.lang.String protocol)
Sets the SSLContext algorithm name.SSLContextBuilder
setProvider(java.lang.String name)
SSLContextBuilder
setProvider(java.security.Provider provider)
SSLContextBuilder
setSecureRandom(java.security.SecureRandom secureRandom)
SSLContextBuilder
setTrustManagerFactoryAlgorithm(java.lang.String trustManagerFactoryAlgorithm)
Sets the trust manager factory algorithm name.SSLContextBuilder
setTrustStoreProvider(java.lang.String name)
Sets the JCA provider name to use for creating trust stores.SSLContextBuilder
setTrustStoreProvider(java.security.Provider provider)
Sets the JCA provider to use for creating trust stores.java.lang.String
toString()
-
-
-
Field Detail
-
TLS
static final java.lang.String TLS
- See Also:
- Constant Field Values
-
protocol
private java.lang.String protocol
-
keyManagers
private final java.util.Set<javax.net.ssl.KeyManager> keyManagers
-
keyManagerFactoryAlgorithm
private java.lang.String keyManagerFactoryAlgorithm
-
keyStoreType
private java.lang.String keyStoreType
-
trustManagers
private final java.util.Set<javax.net.ssl.TrustManager> trustManagers
-
trustManagerFactoryAlgorithm
private java.lang.String trustManagerFactoryAlgorithm
-
secureRandom
private java.security.SecureRandom secureRandom
-
provider
private java.security.Provider provider
-
tsProvider
private java.security.Provider tsProvider
-
ksProvider
private java.security.Provider ksProvider
-
EMPTY_KEY_MANAGER_ARRAY
private static final javax.net.ssl.KeyManager[] EMPTY_KEY_MANAGER_ARRAY
An empty immutableKeyManager
array.
-
EMPTY_TRUST_MANAGER_ARRAY
private static final javax.net.ssl.TrustManager[] EMPTY_TRUST_MANAGER_ARRAY
An empty immutableTrustManager
array.
-
-
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 builder
- 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 builder
- 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 builder
- Throws:
java.security.NoSuchProviderException
- 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 builder
- 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 builder
- Throws:
java.security.NoSuchProviderException
- 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 builder
- 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 builder
- 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 builder
- 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 benull
in which case only the default trust managers will be used- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(java.nio.file.Path file) 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
- 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
- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.io.IOException
- 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
- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.io.IOException
- Since:
- 5.2
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(TrustStrategy trustStrategy) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException
- Throws:
java.security.NoSuchAlgorithmException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.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
- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.io.IOException
- 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
- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.io.IOException
- 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.NoSuchAlgorithmException
java.security.KeyStoreException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.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.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.UnrecoverableKeyException
java.security.cert.CertificateException
java.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.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
-
loadKeyStore
private java.security.KeyStore loadKeyStore(java.nio.file.Path file, char[] password, java.nio.file.OpenOption... openOptions) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException
- Throws:
java.security.KeyStoreException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
-
loadKeyStore
private java.security.KeyStore loadKeyStore(java.net.URL url, char[] password) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException
- Throws:
java.security.KeyStoreException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
-
build
public javax.net.ssl.SSLContext build() throws java.security.NoSuchAlgorithmException, java.security.KeyManagementException
- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
-
requireNonNullProvider
private java.security.Provider requireNonNullProvider(java.lang.String name) throws java.security.NoSuchProviderException
- Throws:
java.security.NoSuchProviderException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-