Package org.kiwiproject.security
Class SimpleSSLContextFactory
java.lang.Object
org.kiwiproject.security.SimpleSSLContextFactory
A "simple" factory class that makes it simpler to create
SSLContext instances.
Construct using one of the public constructors or via the builder().
Prefer using the builder, as the constructors may be deprecated
(most likely for removal) in the future.
This abstracts the much lower level KiwiSecurity class.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword, String protocol) Create a newSimpleSSLContextFactorywithverifyHostnameset totrueand "JKS" as the key and trust store type.SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword, String protocol, boolean verifyHostname) Create a newSimpleSSLContextFactorywith "JKS" as the key and trust store type.SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String keyStoreType, String trustStorePath, String trustStorePassword, String trustStoreType, String protocol, boolean verifyHostname) Create a newSimpleSSLContextFactory.SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String keyStoreType, String trustStorePath, String trustStorePassword, String trustStoreType, String protocol, boolean verifyHostname, boolean disableSniHostCheck) Create a newSimpleSSLContextFactory. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Return a new builder instance.Get the properties this factory was configured with, including passwords.Create/get aSSLContextinstance for the key and trust store properties and protocol that thisSimpleSSLContextFactoryinstance was built with.booleanThis is not strictly needed when creatingSSLContexts.booleanThis is not strictly needed when creatingSSLContexts.
-
Constructor Details
-
SimpleSSLContextFactory
public SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword, String protocol) Create a newSimpleSSLContextFactorywithverifyHostnameset totrueand "JKS" as the key and trust store type.- Parameters:
keyStorePath- path to the key storekeyStorePassword- password of the key storetrustStorePath- path to the trust storetrustStorePassword- password of the trust storeprotocol- the protocol to use
-
SimpleSSLContextFactory
public SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String trustStorePath, String trustStorePassword, String protocol, boolean verifyHostname) Create a newSimpleSSLContextFactorywith "JKS" as the key and trust store type.- Parameters:
keyStorePath- path to the key storekeyStorePassword- password of the key storetrustStorePath- path to the trust storetrustStorePassword- password of the trust storeprotocol- the protocol to useverifyHostname- whether to verify host names or not
-
SimpleSSLContextFactory
public SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String keyStoreType, String trustStorePath, String trustStorePassword, String trustStoreType, String protocol, boolean verifyHostname) Create a newSimpleSSLContextFactory.- Parameters:
keyStorePath- path to the key storekeyStorePassword- password of the key storekeyStoreType- the keystore typetrustStorePath- path to the trust storetrustStorePassword- password of the trust storetrustStoreType- the trust store typeprotocol- the protocol to useverifyHostname- whether to verify host names or not
-
SimpleSSLContextFactory
public SimpleSSLContextFactory(String keyStorePath, String keyStorePassword, String keyStoreType, String trustStorePath, String trustStorePassword, String trustStoreType, String protocol, boolean verifyHostname, boolean disableSniHostCheck) Create a newSimpleSSLContextFactory.- Parameters:
keyStorePath- path to the key storekeyStorePassword- password of the key storekeyStoreType- the keystore typetrustStorePath- path to the trust storetrustStorePassword- password of the trust storetrustStoreType- the trust store typeprotocol- the protocol to useverifyHostname- whether to verify host names or notdisableSniHostCheck- whether to disable SNI host checking
-
-
Method Details
-
builder
Return a new builder instance.- Returns:
- new Builder
-
getSslContext
Create/get aSSLContextinstance for the key and trust store properties and protocol that thisSimpleSSLContextFactoryinstance was built with.- Returns:
- a new
SSLContextinstance when first called; all subsequent calls return the same cached instance - Implementation Note:
- This is intended to be called infrequently, e.g., once when a service/app starts.
It is internally synchronized to ensure thread-safety when creating the
SSLContext.
-
configuration
Get the properties this factory was configured with, including passwords. Callers are responsible for securely handling the result, and not unnecessarily exposing it.- Returns:
- a map containing the configuration of this factory
- API Note:
- This is publicly exposed, but should not generally be needed except in tests, and perhaps debugging.
- Implementation Note:
- Uses
KiwiMaps.newHashMap(Object...)because some values may benull, e.g., the key store path, and wraps that usingCollections.unmodifiableMap(Map)to prevent modification of the returned map.
-
isVerifyHostname
public boolean isVerifyHostname()This is not strictly needed when creatingSSLContexts. It is here only in case this factory will be supplied to other code that makes HTTPS connections and needs to createSSLContextinstances AND also needs to know whether it should perform hostname verification when making HTTPS requests. -
isDisableSniHostCheck
public boolean isDisableSniHostCheck()This is not strictly needed when creatingSSLContexts. It is here only in case this factory will be supplied to other code that makes HTTPS connections and needs to createSSLContextinstances AND also needs to know whether it should perform SNI host checking.
-