Class SecurityEnhancedTLSSocketFactory
- java.lang.Object
-
- org.opensaml.security.httpclient.impl.SecurityEnhancedTLSSocketFactory
-
- All Implemented Interfaces:
org.apache.http.conn.socket.ConnectionSocketFactory,org.apache.http.conn.socket.LayeredConnectionSocketFactory
public class SecurityEnhancedTLSSocketFactory extends Object implements org.apache.http.conn.socket.LayeredConnectionSocketFactory
An security-enhanced implementation of HttpClient's TLS-capableLayeredConnectionSocketFactory.This implementation wraps an existing TLS socket factory instance, decorating it with additional support for:
- Loading and clearing thread-local instances of
TrustEngine<Credential>andCriteriaSetused for server TLS. - Loading and clearing a thread-local instance of
X509Credentialused for client TLS.
The context keys used by this component are as follows, defined in
HttpClientSecurityConstants:HttpClientSecurityConstants.CONTEXT_KEY_TRUST_ENGINE: The trust engine instance used. Supplied by the HttpClient caller. Must be an instance ofTrustEngine<Credential>.HttpClientSecurityConstants.CONTEXT_KEY_CRITERIA_SET: The criteria set instance used. Supplied by the HttpClient caller. Must be an instance ofCriteriaSet.HttpClientSecurityConstants.CONTEXT_KEY_SERVER_TLS_CREDENTIAL_TRUSTED: The result of the trust evaluation, if it was performed. Populated by this component. Will be aBoolean, wheretruemeans the server TLS was evaluated as trusted,falsemeans the credential was evaluated as untrusted. A null or missing value means that trust engine evaluation was not performed.HttpClientSecurityConstants.CONTEXT_KEY_CLIENT_TLS_CREDENTIAL: The client TLS credential used. Supplied by the HttpClient caller. Must be an instance ofX509Credential.
Support for server TLS via trust engine evaluation requires use of a compatible
TrustManagerimplementation configured in theSSLContextof the wrappedLayeredConnectionSocketFactory, such asThreadLocalX509TrustManager.Support for client TLS requires use of a compatible
KeyManagerimplementation configured in theSSLContextof the wrappedLayeredConnectionSocketFactory, such asThreadLocalX509CredentialKeyManager.If the trust engine context attribute is not populated by the caller, then no server TLS thread-local data is populated. If the wrapped socket factory's
X509TrustManagerimplementation requires this data (for exampleThreadLocalX509TrustManager), then a fatal exception is expected to be thrown.If the client TLS credential context attribute is not populated by the caller, then no client TLS thread-local data is populated, and client TLS will not be attempted.
-
-
Field Summary
Fields Modifier and Type Field Description private static ThreadLocalClientTLSCredentialHandlerCLIENT_TLS_HANDLERInstance ofThreadLocalClientTLSCredentialHandlerto use.private org.slf4j.LoggerlogLogger.private static ThreadLocalServerTLSHandlerSERVER_TLS_HANDLERInstance ofThreadLocalClientTLSCredentialHandlerto use.private org.apache.http.conn.socket.LayeredConnectionSocketFactorywrappedFactoryThe HttpClient socket factory instance wrapped by this implementation.
-
Constructor Summary
Constructors Constructor Description SecurityEnhancedTLSSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory factory)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SocketconnectSocket(int connectTimeout, Socket sock, org.apache.http.HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, org.apache.http.protocol.HttpContext context)SocketcreateLayeredSocket(Socket socket, String target, int port, org.apache.http.protocol.HttpContext context)SocketcreateSocket(org.apache.http.protocol.HttpContext context)protected voidsetup(org.apache.http.protocol.HttpContext context, String hostname)Setup calling execution environment for server TLS and client TLS based on information supplied in theHttpContext.protected voidsetupClientTLS(org.apache.http.protocol.HttpContext context)Setup thread-local data for server TLS and client TLS based on information supplied in theHttpContext.protected voidsetupServerTLS(org.apache.http.protocol.HttpContext context, String hostname)Setup thread-local data for server TLS.protected voidteardown(org.apache.http.protocol.HttpContext context)Schedule the deferred clearing of theThreadLocalX509CredentialContextof the client TLS credential obtained from theHttpContext.
-
-
-
Field Detail
-
SERVER_TLS_HANDLER
private static final ThreadLocalServerTLSHandler SERVER_TLS_HANDLER
Instance ofThreadLocalClientTLSCredentialHandlerto use.
-
CLIENT_TLS_HANDLER
private static final ThreadLocalClientTLSCredentialHandler CLIENT_TLS_HANDLER
Instance ofThreadLocalClientTLSCredentialHandlerto use.
-
log
private final org.slf4j.Logger log
Logger.
-
wrappedFactory
@Nonnull private org.apache.http.conn.socket.LayeredConnectionSocketFactory wrappedFactory
The HttpClient socket factory instance wrapped by this implementation.
-
-
Method Detail
-
createSocket
public Socket createSocket(org.apache.http.protocol.HttpContext context) throws IOException
- Specified by:
createSocketin interfaceorg.apache.http.conn.socket.ConnectionSocketFactory- Throws:
IOException
-
connectSocket
public Socket connectSocket(int connectTimeout, Socket sock, org.apache.http.HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, org.apache.http.protocol.HttpContext context) throws IOException
- Specified by:
connectSocketin interfaceorg.apache.http.conn.socket.ConnectionSocketFactory- Throws:
IOException
-
createLayeredSocket
public Socket createLayeredSocket(Socket socket, String target, int port, org.apache.http.protocol.HttpContext context) throws IOException
- Specified by:
createLayeredSocketin interfaceorg.apache.http.conn.socket.LayeredConnectionSocketFactory- Throws:
IOException
-
setup
protected void setup(@Nullable org.apache.http.protocol.HttpContext context, @Nonnull String hostname) throws SSLPeerUnverifiedExceptionSetup calling execution environment for server TLS and client TLS based on information supplied in theHttpContext.- Parameters:
context- the HttpContext instancehostname- the hostname for the connection- Throws:
SSLPeerUnverifiedException- if required data is not available from the context
-
setupClientTLS
protected void setupClientTLS(@Nonnull org.apache.http.protocol.HttpContext context)Setup thread-local data for server TLS and client TLS based on information supplied in theHttpContext.- Parameters:
context- the HttpContext instance
-
setupServerTLS
protected void setupServerTLS(@Nonnull org.apache.http.protocol.HttpContext context, @Nonnull String hostname)Setup thread-local data for server TLS.- Parameters:
context- the HttpContext instancehostname- the hostname for the connection
-
teardown
protected void teardown(@Nullable org.apache.http.protocol.HttpContext context)Schedule the deferred clearing of theThreadLocalX509CredentialContextof the client TLS credential obtained from theHttpContext.- Parameters:
context- the HttpContext instance
-
-