Package org.wildfly.security.ssl
Class SSLUtils
- java.lang.Object
- 
- org.wildfly.security.ssl.SSLUtils
 
- 
 public final class SSLUtils extends Object SSL factories and utilities.- Author:
- David M. Lloyd
 
- 
- 
Field SummaryFields Modifier and Type Field Description private static SecurityFactory<X509TrustManager>DEFAULT_TRUST_MANAGER_SECURITY_FACTORYprivate static String[]NO_STRINGSprivate static StringSERVICE_TYPEstatic StringSSL_SESSION_IDENTITY_KEYThe key used to store the authenticatedSecurityIdentityonto theSSLSession.
 - 
Constructor SummaryConstructors Modifier Constructor Description privateSSLUtils()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <R> RcomputeIfAbsent(SSLSession sslSession, String key, Function<String,R> mappingFunction)Get or compute the value for the given key, storing the computed value (if one is generated).static SSLContextcreateConfiguredSslContext(SSLContext original, SSLConfigurator sslConfigurator)Create a configured SSL context from an outside SSL context.static SSLContextcreateConfiguredSslContext(SSLContext original, SSLConfigurator sslConfigurator, boolean wrap)Create a configured SSL context from an outside SSL context.static SecurityFactory<SSLContext>createConfiguredSslContextFactory(SecurityFactory<SSLContext> originalFactory, SSLConfigurator sslConfigurator)Create a configured SSL context factory from an outside SSL context.static SecurityFactory<SSLEngine>createDispatchingSSLEngineFactory(SSLContextSelector selector)Get a factory which produces SSL engines which dispatch to the appropriate SSL context based on the information in the SSL greeting.static SNIMatchercreateHostNamePredicateSNIMatcher(Predicate<SNIHostName> predicate)Create anSNIMatcherwhich matches SNI host names that satisfy the given predicate.static SNIMatchercreateHostNameStringPredicateSNIMatcher(Predicate<String> predicate)Create anSNIMatcherwhich matches SNI host name strings that satisfy the given predicate.static SNIMatchercreateHostNameStringSNIMatcher(String string)Create anSNIMatcherwhich matches SNI host names that are equal to the given (ASCII) string.static SNIMatchercreateHostNameSuffixSNIMatcher(String suffix)Create anSNIMatcherwhich matches SNI host name strings which end with the given suffix.static SSLEnginecreateSelectingSSLEngine(SSLContextSelector selector)Get a server SSL engine which dispatches to the appropriate SSL context based on the information in the SSL greeting.static SSLEnginecreateSelectingSSLEngine(SSLContextSelector selector, String host, int port)Get a server SSL engine which dispatches to the appropriate SSL context based on the information in the SSL greeting.static SecurityFactory<SSLContext>createSimpleSslContextFactory(String protocol, Provider provider)Create a simple security factory for SSL contexts.static SecurityFactory<SSLContext>createSslContextFactory(ProtocolSelector protocolSelector, Supplier<Provider[]> providerSupplier)Create an SSL context factory which locates the best context by searching the preferred providers in order using the rules established in the given protocol selector.static SecurityFactory<SSLContext>createSslContextFactory(ProtocolSelector protocolSelector, Supplier<Provider[]> providerSupplier, String providerName)Create an SSL context factory which locates the best context by searching the preferred providers in order using the rules established in the given protocol selector.static SecurityFactory<X509TrustManager>getDefaultX509TrustManagerSecurityFactory()Get the platform's default X.509 trust manager security factory.static ObjectgetOrDefault(SSLSession sslSession, String key, Object defaultValue)Get the value of the given key from the SSL session, or a default value if the key is not set.static ObjectputSessionValueIfAbsent(SSLSession sslSession, String key, Object newValue)Put a value on the session if the value is not yet set.static ObjectremoveSessionValue(SSLSession sslSession, String key)Remove and return a value on the session.static booleanremoveSessionValue(SSLSession sslSession, String key, Object value)Remove the given key-value pair on the session.static ObjectreplaceSessionValue(SSLSession sslSession, String key, Object newValue)Replace the given key's value with a new value.static booleanreplaceSessionValue(SSLSession sslSession, String key, Object oldValue, Object newValue)Replace the given key's value with a new value if (and only if) it is mapped to the given existing value.private static SSLContextthrowIt()
 
- 
- 
- 
Field Detail- 
NO_STRINGSprivate static final String[] NO_STRINGS 
 - 
SERVICE_TYPEprivate static final String SERVICE_TYPE 
 - 
SSL_SESSION_IDENTITY_KEYpublic static final String SSL_SESSION_IDENTITY_KEY The key used to store the authenticatedSecurityIdentityonto theSSLSession.- See Also:
- Constant Field Values
 
 - 
DEFAULT_TRUST_MANAGER_SECURITY_FACTORYprivate static final SecurityFactory<X509TrustManager> DEFAULT_TRUST_MANAGER_SECURITY_FACTORY 
 
- 
 - 
Method Detail- 
createSslContextFactorypublic static SecurityFactory<SSLContext> createSslContextFactory(ProtocolSelector protocolSelector, Supplier<Provider[]> providerSupplier) Create an SSL context factory which locates the best context by searching the preferred providers in order using the rules established in the given protocol selector. If there are no matches, a factory is returned which- Parameters:
- protocolSelector- the protocol selector
- providerSupplier- the provider supplier
- Returns:
- the SSL context factory
 
 - 
createSslContextFactorypublic static SecurityFactory<SSLContext> createSslContextFactory(ProtocolSelector protocolSelector, Supplier<Provider[]> providerSupplier, String providerName) Create an SSL context factory which locates the best context by searching the preferred providers in order using the rules established in the given protocol selector. If there are no matches, a factory is returned which- Parameters:
- protocolSelector- the protocol selector
- providerSupplier- the provider supplier
- providerName- the provider name to select, or- nullto allow any
- Returns:
- the SSL context factory
 
 - 
throwItprivate static SSLContext throwIt() throws NoSuchAlgorithmException - Throws:
- NoSuchAlgorithmException
 
 - 
createSimpleSslContextFactorypublic static SecurityFactory<SSLContext> createSimpleSslContextFactory(String protocol, Provider provider) Create a simple security factory for SSL contexts.- Parameters:
- protocol- the protocol name
- provider- the provider to use
- Returns:
- the SSL context factory
 
 - 
createConfiguredSslContextpublic static SSLContext createConfiguredSslContext(SSLContext original, SSLConfigurator sslConfigurator) Create a configured SSL context from an outside SSL context.- Parameters:
- original- the original SSL context
- sslConfigurator- the SSL configurator
- Returns:
- the configured SSL context
 
 - 
createConfiguredSslContextpublic static SSLContext createConfiguredSslContext(SSLContext original, SSLConfigurator sslConfigurator, boolean wrap) Create a configured SSL context from an outside SSL context.- Parameters:
- original- the original SSL context
- sslConfigurator- the SSL configurator
- wrap- should the resulting SSLEngine, SSLSocket, and SSLServerSocket instances be wrapped using the configurator.
- Returns:
- the configured SSL context
 
 - 
createConfiguredSslContextFactorypublic static SecurityFactory<SSLContext> createConfiguredSslContextFactory(SecurityFactory<SSLContext> originalFactory, SSLConfigurator sslConfigurator) Create a configured SSL context factory from an outside SSL context. The returned factory will create new instances for every call, so it might be necessary to wrap with aOneTimeSecurityFactoryinstance.- Parameters:
- originalFactory- the original SSL context factory
- sslConfigurator- the SSL configurator
- Returns:
- the configured SSL context
 
 - 
getDefaultX509TrustManagerSecurityFactorypublic static SecurityFactory<X509TrustManager> getDefaultX509TrustManagerSecurityFactory() Get the platform's default X.509 trust manager security factory. The factory caches the instance.- Returns:
- the security factory for the default trust manager
 
 - 
createSelectingSSLEnginepublic static SSLEngine createSelectingSSLEngine(SSLContextSelector selector) Get a server SSL engine which dispatches to the appropriate SSL context based on the information in the SSL greeting.- Parameters:
- selector- the context selector to use (cannot be- null)
- Returns:
- the SSL engine (not null)
 
 - 
createSelectingSSLEnginepublic static SSLEngine createSelectingSSLEngine(SSLContextSelector selector, String host, int port) Get a server SSL engine which dispatches to the appropriate SSL context based on the information in the SSL greeting.- Parameters:
- selector- the context selector to use (cannot be- null)
- host- the advisory host name
- port- the advisory port number
- Returns:
- the SSL engine (not null)
 
 - 
createHostNamePredicateSNIMatcherpublic static SNIMatcher createHostNamePredicateSNIMatcher(Predicate<SNIHostName> predicate) Create anSNIMatcherwhich matches SNI host names that satisfy the given predicate.- Parameters:
- predicate- the predicate (must not be- null)
- Returns:
- the SNI matcher (not null)
 
 - 
createHostNameStringPredicateSNIMatcherpublic static SNIMatcher createHostNameStringPredicateSNIMatcher(Predicate<String> predicate) Create anSNIMatcherwhich matches SNI host name strings that satisfy the given predicate.- Parameters:
- predicate- the predicate (must not be- null)
- Returns:
- the SNI matcher (not null)
- See Also:
- IDN
 
 - 
createHostNameStringSNIMatcherpublic static SNIMatcher createHostNameStringSNIMatcher(String string) Create anSNIMatcherwhich matches SNI host names that are equal to the given (ASCII) string.- Parameters:
- string- the host name string (must not be- null)
- Returns:
- the SNI matcher (not null)
- See Also:
- IDN
 
 - 
createHostNameSuffixSNIMatcherpublic static SNIMatcher createHostNameSuffixSNIMatcher(String suffix) Create anSNIMatcherwhich matches SNI host name strings which end with the given suffix.- Parameters:
- suffix- the suffix to match (must not be- nullor empty)
- Returns:
- the SNI matcher (not null)
 
 - 
createDispatchingSSLEngineFactorypublic static SecurityFactory<SSLEngine> createDispatchingSSLEngineFactory(SSLContextSelector selector) Get a factory which produces SSL engines which dispatch to the appropriate SSL context based on the information in the SSL greeting.- Parameters:
- selector- the context selector to use (cannot be- null)
- Returns:
- the SSL engine factory (not null)
 
 - 
getOrDefaultpublic static Object getOrDefault(SSLSession sslSession, String key, Object defaultValue) Get the value of the given key from the SSL session, or a default value if the key is not set.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- defaultValue- the value to return if the key is not present
- Returns:
- the session value or the default value
 
 - 
putSessionValueIfAbsentpublic static Object putSessionValueIfAbsent(SSLSession sslSession, String key, Object newValue) Put a value on the session if the value is not yet set. This method is atomic with respect to other methods on this class.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- newValue- the value to set (must not be- null)
- Returns:
- the existing value, or nullif the value was successfully set
 
 - 
removeSessionValuepublic static Object removeSessionValue(SSLSession sslSession, String key) Remove and return a value on the session. This method is atomic with respect to other methods on this class.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- Returns:
- the existing value, or nullif no such value was set
 
 - 
removeSessionValuepublic static boolean removeSessionValue(SSLSession sslSession, String key, Object value) Remove the given key-value pair on the session. This method is atomic with respect to other methods on this class.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to remove (must not be- null)
- value- the value to remove (must not be- null)
- Returns:
- trueif the key/value pair was removed,- falseif the key was not present or the value was not equal to the given value
 
 - 
replaceSessionValuepublic static Object replaceSessionValue(SSLSession sslSession, String key, Object newValue) Replace the given key's value with a new value. If there is no value for the given key, no action is performed. This method is atomic with respect to other methods on this class.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- newValue- the value to set (must not be- null)
- Returns:
- the existing value, or nullif the value was not set
 
 - 
replaceSessionValuepublic static boolean replaceSessionValue(SSLSession sslSession, String key, Object oldValue, Object newValue) Replace the given key's value with a new value if (and only if) it is mapped to the given existing value. This method is atomic with respect to other methods on this class.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- oldValue- the value to match (must not be- null)
- newValue- the value to set (must not be- null)
- Returns:
- trueif the value was matched and replaced, or- falseif the value did not match and no action was taken
 
 - 
computeIfAbsentpublic static <R> R computeIfAbsent(SSLSession sslSession, String key, Function<String,R> mappingFunction) Get or compute the value for the given key, storing the computed value (if one is generated). The function must not generate anullvalue or an unspecified exception will result.- Parameters:
- sslSession- the SSL session (must not be- null)
- key- the key to retrieve (must not be- null)
- mappingFunction- the function to apply to acquire the value (must not be- null)
- Returns:
- the stored or new value (not null)
 
 
- 
 
-