Class TlsContextConfiguration
- All Implemented Interfaces:
KeyAndTrustStoreConfigProvider,TrustStoreConfigProvider
As this is a configuration class that supports population from external configuration, it is mutable
NOTE: This requires dropwizard-client as a dependency.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()static TlsContextConfigurationfromDropwizardTlsConfiguration(io.dropwizard.client.ssl.TlsConfiguration tlsConfig) Given a DropwizardTlsConfiguration, create a newTlsContextConfiguration.The alias of a specific client certificate to present when authenticating.Key store password.Absolute path to the key store.The name of the provider for the key store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the key store.Key store type.The TLS/SSL protocol to use.The name of the JCE (Java Cryptography Extension) provider to use on the client side for cryptographic support (for example, SunJCE, Conscrypt, BC, etc.).A list of cipher suites (e.g., TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) which are supported.List of supported protocols.Trust store password.Absolute path to the trust store.The name of the provider for the trust store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the trust store.Trust store type.booleanWhether the SNI (Server Name Indication) host check is disabled.booleanWhether self-signed certificates should be trusted.booleanShould host names be verified when establishing secure connections?voidsetCertAlias(String certAlias) The alias of a specific client certificate to present when authenticating.voidsetDisableSniHostCheck(boolean disableSniHostCheck) Whether the SNI (Server Name Indication) host check is disabled.voidsetKeyStorePassword(String keyStorePassword) Key store password.voidsetKeyStorePath(String keyStorePath) Absolute path to the key store.voidsetKeyStoreProvider(String keyStoreProvider) The name of the provider for the key store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the key store.voidsetKeyStoreType(String keyStoreType) Key store type.voidsetProtocol(String protocol) The TLS/SSL protocol to use.voidsetProvider(String provider) The name of the JCE (Java Cryptography Extension) provider to use on the client side for cryptographic support (for example, SunJCE, Conscrypt, BC, etc.).voidsetSupportedCiphers(List<String> supportedCiphers) A list of cipher suites (e.g., TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) which are supported.voidsetSupportedProtocols(List<String> supportedProtocols) List of supported protocols.voidsetTrustSelfSignedCertificates(boolean trustSelfSignedCertificates) Whether self-signed certificates should be trusted.voidsetTrustStorePassword(String trustStorePassword) Trust store password.voidsetTrustStorePath(String trustStorePath) Absolute path to the trust store.voidsetTrustStoreProvider(String trustStoreProvider) The name of the provider for the trust store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the trust store.voidsetTrustStoreType(String trustStoreType) Trust store type.voidsetVerifyHostname(boolean verifyHostname) Should host names be verified when establishing secure connections?io.dropwizard.client.ssl.TlsConfigurationConvert thisTlsContextConfigurationinto a DropwizardTlsConfigurationobject.Convert this configuration into aSSLContextConfiguration.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.kiwiproject.security.KeyAndTrustStoreConfigProvider
toSSLContextMethods inherited from interface org.kiwiproject.security.TrustStoreConfigProvider
toSslSocketFactory
-
Constructor Details
-
TlsContextConfiguration
public TlsContextConfiguration()
-
-
Method Details
-
fromDropwizardTlsConfiguration
public static TlsContextConfiguration fromDropwizardTlsConfiguration(io.dropwizard.client.ssl.TlsConfiguration tlsConfig) Given a DropwizardTlsConfiguration, create a newTlsContextConfiguration.Even though
TlsContextConfigurationdoes not permit null trust store properties (per the validation annotations), theTlsConfigurationdoes. If we encounter this situation, we will be lenient; even though this could possibly cause downstream problems, we will just assume the caller knows what it is doing.The Dropwizard
TlsConfigurationclass does not contain adisableSniHostCheckproperty, so it cannot transfer and is therefore ignored during conversions. Also note that it is set tofalsein the returnedTlsContextConfigurationsince that is the more secure option.- Parameters:
tlsConfig- the Dropwizard TlsConfiguration from which to pull information- Returns:
- a new TlsContextConfiguration instance
- Implementation Note:
- Currently we do not support
supportedCiphersorcertAlias, which Dropwizard does.
-
toDropwizardTlsConfiguration
public io.dropwizard.client.ssl.TlsConfiguration toDropwizardTlsConfiguration()Convert thisTlsContextConfigurationinto a DropwizardTlsConfigurationobject. Assumes that this object is valid.The Dropwizard
TlsConfigurationclass does not contain adisableSniHostCheckproperty, so it cannot transfer and is therefore ignored during conversions.- Returns:
- a new Dropwizard TlsConfiguration instance
- Implementation Note:
- Requires dropwizard-client as a dependency
-
toSslContextConfiguration
Convert this configuration into aSSLContextConfiguration.Note that
SSLContextConfigurationdoes not haveprovider,keyStoreProvider,trustStoreProvider,trustSelfSignedCertificates,supportedProtocols,supportedCiphers, orcertAlias. As a result, this is a "lossy" conversion since it loses these values.- Returns:
- the new SSLContextConfiguration instance
-
builder
-
getProtocol
The TLS/SSL protocol to use. Default isSSLContextProtocol.TLS_1_2.- Specified by:
getProtocolin interfaceTrustStoreConfigProvider- Returns:
- protocol
- See Also:
-
getProvider
The name of the JCE (Java Cryptography Extension) provider to use on the client side for cryptographic support (for example, SunJCE, Conscrypt, BC, etc.).For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
-
getKeyStorePath
Absolute path to the key store.- Specified by:
getKeyStorePathin interfaceKeyAndTrustStoreConfigProvider- Returns:
- key store path
-
getKeyStorePassword
Key store password.- Specified by:
getKeyStorePasswordin interfaceKeyAndTrustStoreConfigProvider- Returns:
- key store password
-
getKeyStoreType
Key store type. Defaults toKeyStoreType.JKS.- Specified by:
getKeyStoreTypein interfaceKeyAndTrustStoreConfigProvider- Returns:
- key store type
- See Also:
-
getKeyStoreProvider
The name of the provider for the key store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the key store.For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
- See Also:
-
getTrustStorePath
Absolute path to the trust store.- Specified by:
getTrustStorePathin interfaceTrustStoreConfigProvider- Returns:
- path to trust store
-
getTrustStorePassword
Trust store password.- Specified by:
getTrustStorePasswordin interfaceTrustStoreConfigProvider- Returns:
- trust store password
-
getTrustStoreType
Trust store type. Defaults toKeyStoreType.JKS.- Specified by:
getTrustStoreTypein interfaceTrustStoreConfigProvider- Returns:
- trust store type
- See Also:
-
getTrustStoreProvider
The name of the provider for the trust store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the trust store.For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
- See Also:
-
isTrustSelfSignedCertificates
public boolean isTrustSelfSignedCertificates()Whether self-signed certificates should be trusted. Default isfalse. -
isVerifyHostname
public boolean isVerifyHostname()Should host names be verified when establishing secure connections? Default istrue.- Specified by:
isVerifyHostnamein interfaceTrustStoreConfigProvider- Returns:
- true if hostname verification should be performed
-
isDisableSniHostCheck
public boolean isDisableSniHostCheck()Whether the SNI (Server Name Indication) host check is disabled. Default isfalse -
getSupportedProtocols
List of supported protocols. It can benull. See the implementation note for why.- Implementation Note:
- Yes, this is null by default. This is due to the Dropwizard
TlsConfigurationwhich has this same property null by default; I suspect this is ultimately due to the (unfortunate) way in which Apache HttpClient'sSSLConnectionSocketFactoryacceptssupportedProtocolsin its constructors as arrays that are supposed to be null if you aren't specifying a specific list of them. The HttpClient code does an explicit null check on thesupportedProtocolsinSSLConnectionSocketFactory.createLayeredSocket(Socket, String, int, org.apache.hc.core5.http.protocol.HttpContext). You will need to look at the source code, as the JavaDoc doesn't mention this tidbit, nor do the constructors since they don't have any documentation regarding their arguments. If you don't like reading source code of the open-source tools you rely on, then please close this file, log out, and change careers.
-
getSupportedCiphers
A list of cipher suites (e.g., TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) which are supported. All other cipher suites will be refused.Note that this can be
nullfor similar reason assupportedProtocols. See the implementation note onsupportedProtocols. -
getCertAlias
The alias of a specific client certificate to present when authenticating. Use this when the specified keystore has multiple certificates to force use of a non-default certificate. -
setProtocol
The TLS/SSL protocol to use. Default isSSLContextProtocol.TLS_1_2.- See Also:
-
setProvider
The name of the JCE (Java Cryptography Extension) provider to use on the client side for cryptographic support (for example, SunJCE, Conscrypt, BC, etc.).For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
-
setKeyStorePath
Absolute path to the key store. -
setKeyStorePassword
Key store password. -
setKeyStoreType
Key store type. Defaults toKeyStoreType.JKS.- See Also:
-
setKeyStoreProvider
The name of the provider for the key store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the key store.For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
- See Also:
-
setTrustStorePath
Absolute path to the trust store. -
setTrustStorePassword
Trust store password. -
setTrustStoreType
Trust store type. Defaults toKeyStoreType.JKS.- See Also:
-
setTrustStoreProvider
The name of the provider for the trust store, i.e., the value ofproviderto use when getting theKeyStoreinstance for the trust store.For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java Security Developer’s Guide.
- See Also:
-
setTrustSelfSignedCertificates
public void setTrustSelfSignedCertificates(boolean trustSelfSignedCertificates) Whether self-signed certificates should be trusted. Default isfalse. -
setVerifyHostname
public void setVerifyHostname(boolean verifyHostname) Should host names be verified when establishing secure connections? Default istrue. -
setDisableSniHostCheck
public void setDisableSniHostCheck(boolean disableSniHostCheck) Whether the SNI (Server Name Indication) host check is disabled. Default isfalse -
setSupportedProtocols
List of supported protocols. It can benull. See the implementation note for why.- Implementation Note:
- Yes, this is null by default. This is due to the Dropwizard
TlsConfigurationwhich has this same property null by default; I suspect this is ultimately due to the (unfortunate) way in which Apache HttpClient'sSSLConnectionSocketFactoryacceptssupportedProtocolsin its constructors as arrays that are supposed to be null if you aren't specifying a specific list of them. The HttpClient code does an explicit null check on thesupportedProtocolsinSSLConnectionSocketFactory.createLayeredSocket(Socket, String, int, org.apache.hc.core5.http.protocol.HttpContext). You will need to look at the source code, as the JavaDoc doesn't mention this tidbit, nor do the constructors since they don't have any documentation regarding their arguments. If you don't like reading source code of the open-source tools you rely on, then please close this file, log out, and change careers.
-
setSupportedCiphers
A list of cipher suites (e.g., TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) which are supported. All other cipher suites will be refused.Note that this can be
nullfor similar reason assupportedProtocols. See the implementation note onsupportedProtocols. -
setCertAlias
The alias of a specific client certificate to present when authenticating. Use this when the specified keystore has multiple certificates to force use of a non-default certificate. -
toString
-