Package org.apache.hc.core5.ssl
Class SSLContextBuilder
java.lang.Object
org.apache.hc.core5.ssl.SSLContextBuilder
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final KeyManager[]
An empty immutableKeyManager
array.private static final TrustManager[]
An empty immutableTrustManager
array.private String
private final Set
<KeyManager> private String
private Provider
private String
private Provider
private SecureRandom
(package private) static final String
private String
private final Set
<TrustManager> private Provider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
static SSLContextBuilder
create()
protected void
initSSLContext
(SSLContext sslContext, Collection<KeyManager> keyManagers, Collection<TrustManager> trustManagers, SecureRandom secureRandom) loadKeyMaterial
(File file, char[] storePassword, char[] keyPassword) loadKeyMaterial
(File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) loadKeyMaterial
(URL url, char[] storePassword, char[] keyPassword) loadKeyMaterial
(URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) loadKeyMaterial
(Path file, char[] storePassword, char[] keyPassword, OpenOption... openOptions) loadKeyMaterial
(Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, OpenOption... openOptions) loadKeyMaterial
(KeyStore keyStore, char[] keyPassword) loadKeyMaterial
(KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy) private KeyStore
loadKeyStore
(URL url, char[] password) private KeyStore
loadKeyStore
(Path file, char[] password, OpenOption... openOptions) loadTrustMaterial
(File file) loadTrustMaterial
(File file, char[] storePassword) loadTrustMaterial
(File file, char[] storePassword, TrustStrategy trustStrategy) loadTrustMaterial
(URL url, char[] storePassword) loadTrustMaterial
(URL url, char[] storePassword, TrustStrategy trustStrategy) loadTrustMaterial
(Path file) loadTrustMaterial
(Path file, char[] storePassword) loadTrustMaterial
(Path file, char[] storePassword, TrustStrategy trustStrategy, OpenOption... openOptions) loadTrustMaterial
(KeyStore trustStore, TrustStrategy trustStrategy) loadTrustMaterial
(TrustStrategy trustStrategy) private Provider
requireNonNullProvider
(String name) setKeyManagerFactoryAlgorithm
(String keyManagerFactoryAlgorithm) Sets the key manager factory algorithm name.setKeyStoreProvider
(String name) Sets the JCA provider name to use for creating key stores.setKeyStoreProvider
(Provider provider) Sets the JCA provider to use for creating key stores.setKeyStoreType
(String keyStoreType) Sets the key store type.setProtocol
(String protocol) Sets the SSLContext algorithm name.setProvider
(String name) setProvider
(Provider provider) setSecureRandom
(SecureRandom secureRandom) setTrustManagerFactoryAlgorithm
(String trustManagerFactoryAlgorithm) Sets the trust manager factory algorithm name.setTrustStoreProvider
(String name) Sets the JCA provider name to use for creating trust stores.setTrustStoreProvider
(Provider provider) Sets the JCA provider to use for creating trust stores.toString()
-
Field Details
-
TLS
- See Also:
-
protocol
-
keyManagers
-
keyManagerFactoryAlgorithm
-
keyStoreType
-
trustManagers
-
trustManagerFactoryAlgorithm
-
secureRandom
-
provider
-
tsProvider
-
ksProvider
-
EMPTY_KEY_MANAGER_ARRAY
An empty immutableKeyManager
array. -
EMPTY_TRUST_MANAGER_ARRAY
An empty immutableTrustManager
array.
-
-
Constructor Details
-
SSLContextBuilder
public SSLContextBuilder()
-
-
Method Details
-
create
-
setProtocol
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:
-
setProvider
-
setProvider
-
setTrustStoreProvider
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
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
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
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
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:
-
setKeyManagerFactoryAlgorithm
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:
-
setTrustManagerFactoryAlgorithm
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:
-
setSecureRandom
-
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(KeyStore trustStore, TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException - Parameters:
trustStrategy
- custom trust strategy to use; can benull
in which case only the default trust managers will be used- 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 -
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(File file, char[] storePassword, TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException -
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(File file, char[] storePassword) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException -
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(File file) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException -
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(URL url, char[] storePassword, TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException -
loadTrustMaterial
public SSLContextBuilder loadTrustMaterial(URL url, char[] storePassword) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(KeyStore keyStore, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(Path file, char[] storePassword, char[] keyPassword, OpenOption... openOptions) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(Path file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy, OpenOption... openOptions) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(KeyStore keyStore, char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(File file, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(File file, char[] storePassword, char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(URL url, char[] storePassword, char[] keyPassword, PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(URL url, char[] storePassword, char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException -
initSSLContext
protected void initSSLContext(SSLContext sslContext, Collection<KeyManager> keyManagers, Collection<TrustManager> trustManagers, SecureRandom secureRandom) throws KeyManagementException - Throws:
KeyManagementException
-
loadKeyStore
private KeyStore loadKeyStore(Path file, char[] password, OpenOption... openOptions) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException -
loadKeyStore
private KeyStore loadKeyStore(URL url, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException -
build
-
requireNonNullProvider
- Throws:
NoSuchProviderException
-
toString
-