Package net.shibboleth.shared.httpclient
Class TLSSocketFactory
java.lang.Object
net.shibboleth.shared.httpclient.TLSSocketFactory
- All Implemented Interfaces:
org.apache.hc.client5.http.socket.ConnectionSocketFactory,org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory
@ThreadSafe
public class TLSSocketFactory
extends Object
implements org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory
An implementation of HttpClient
LayeredConnectionSocketFactory that is a factory
for TLS sockets.
This class is functionally modeled on SSLConnectionSocketFactory,
but provides better support for subclassing, as well as specific additional features:
- Factory hostname verifier defaults to
DefaultHostnameVerifierwithout a configuredPublicSuffixMatcher. - Per-request specification of enabled TLS protocols and cipher suites via
HttpContextattributes. - Per-request specification of hostname verifier via
HttpContextattribute.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HostnameVerifierHostname verifier which passes all hostnames.static final StringHttpContext key for an instance ofHostnameVerifier.static final StringHttpContext key for a a list of TLS cipher suites to enable on the socket.static final StringHttpContext key for a a list of TLS protocols to enable on the socket.static final String[]Default enabled protocols.private final HostnameVerifierHostname verifier.private final org.slf4j.LoggerLogger.private final SSLSocketFactorySocket factory.static final StringProtocol: SSL.static final StringProtocol: SSLv2.static final HostnameVerifierHostname verifier which implements a strict policy.private final String[]Factory-wide supported cipher suites.private final String[]Factory-wide supported protocols.static final StringProtocol: TLS. -
Constructor Summary
ConstructorsConstructorDescriptionTLSSocketFactory(SSLContext sslContext) Constructor.TLSSocketFactory(SSLContext sslContext, String[] protocols, String[] cipherSuites, HostnameVerifier verifier) Constructor.TLSSocketFactory(SSLContext sslContext, HostnameVerifier verifier) Constructor.TLSSocketFactory(SSLSocketFactory factory, String[] protocols, String[] cipherSuites, HostnameVerifier verifier) Constructor.TLSSocketFactory(SSLSocketFactory factory, HostnameVerifier verifier) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionconnectSocket(org.apache.hc.core5.util.TimeValue connectTimeout, Socket socket, org.apache.hc.core5.http.HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, org.apache.hc.core5.http.protocol.HttpContext context) createLayeredSocket(Socket socket, String target, int port, org.apache.hc.core5.http.protocol.HttpContext context) createSocket(org.apache.hc.core5.http.protocol.HttpContext context) protected HostnameVerifierGet the configured hostname verifier.protected String[]getListAttribute(org.apache.hc.core5.http.protocol.HttpContext context, String contextKey) protected SSLSocketFactoryGet the JSSE socket factory instance.protected String[]Get the configured factory-wide supported cipher suites.protected String[]Get the configured factory-wide supported protocols.private voidlogSocketInfo(SSLSocket socket) Log various diagnostic information from theSSLSocketandSSLSession.protected voidprepareSocket(SSLSocket socket, org.apache.hc.core5.http.protocol.HttpContext context) Performs any custom initialization for a newly created SSLSocket (before the SSL handshake happens).protected voidverifyHostname(SSLSocket sslsock, String hostname, org.apache.hc.core5.http.protocol.HttpContext context) Verify the peer's socket hostname against the supplied expected name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hc.client5.http.socket.ConnectionSocketFactory
connectSocket, createSocketMethods inherited from interface org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory
createLayeredSocket
-
Field Details
-
CONTEXT_KEY_TLS_PROTOCOLS
HttpContext key for a a list of TLS protocols to enable on the socket. Must be an instance ofList<String>.- See Also:
-
CONTEXT_KEY_TLS_CIPHER_SUITES
HttpContext key for a a list of TLS cipher suites to enable on the socket. Must be an instance ofList<String>.- See Also:
-
CONTEXT_KEY_HOSTNAME_VERIFIER
HttpContext key for an instance ofHostnameVerifier.- See Also:
-
TLS
Protocol: TLS.- See Also:
-
SSL
Protocol: SSL.- See Also:
-
SSLV2
Protocol: SSLv2.- See Also:
-
ALLOW_ALL_HOSTNAME_VERIFIER
Hostname verifier which passes all hostnames. -
STRICT_HOSTNAME_VERIFIER
Hostname verifier which implements a strict policy. -
DEFAULT_ENABLED_PROTOCOLS
Default enabled protocols. -
log
@Nonnull private final org.slf4j.Logger logLogger. -
socketfactory
Socket factory. -
hostnameVerifier
Hostname verifier. -
supportedProtocols
Factory-wide supported protocols. -
supportedCipherSuites
Factory-wide supported cipher suites.
-
-
Constructor Details
-
TLSSocketFactory
Constructor.- Parameters:
sslContext- the effective SSLContext instance
-
TLSSocketFactory
Constructor.- Parameters:
sslContext- the effective SSLContext instanceverifier- the effective hostname verifier
-
TLSSocketFactory
public TLSSocketFactory(@Nonnull SSLContext sslContext, @Nullable String[] protocols, @Nullable String[] cipherSuites, @Nullable HostnameVerifier verifier) Constructor.- Parameters:
sslContext- the effective SSLContext instanceprotocols- the factory-wide enabled TLS protocolscipherSuites- the factory-wide enabled TLS cipher suitesverifier- the effective hostname verifier
-
TLSSocketFactory
Constructor.- Parameters:
factory- the effective SSL socket factoryverifier- the effective hostname verifier
-
TLSSocketFactory
public TLSSocketFactory(@Nonnull SSLSocketFactory factory, @Nullable String[] protocols, @Nullable String[] cipherSuites, @Nullable HostnameVerifier verifier) Constructor.- Parameters:
factory- the effective SSL socket factoryprotocols- the factory-wide enabled TLS protocolscipherSuites- the factory-wide enabled TLS cipher suitesverifier- the effective hostname verifier
-
-
Method Details
-
getSocketfactory
Get the JSSE socket factory instance.- Returns:
- the socket factory
-
getHostnameVerifier
Get the configured hostname verifier.- Returns:
- the hostname verifier
-
getSupportedProtocols
Get the configured factory-wide supported protocols.- Returns:
- the configured protocols
-
getSupportedCipherSuites
Get the configured factory-wide supported cipher suites.- Returns:
- the configured cipher suites
-
prepareSocket
protected void prepareSocket(@Nonnull SSLSocket socket, @Nullable org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Performs any custom initialization for a newly created SSLSocket (before the SSL handshake happens). The default implementation is a no-op, but could be overridden to, e.g., callSSLSocket.setEnabledCipherSuites(String[]).- Parameters:
socket- the SSL socket instance being preparedcontext- the current HttpContext instance- Throws:
IOException- if there is an error customizing the socket
-
createSocket
@Nonnull public Socket createSocket(@Nullable org.apache.hc.core5.http.protocol.HttpContext context) throws IOException - Specified by:
createSocketin interfaceorg.apache.hc.client5.http.socket.ConnectionSocketFactory- Throws:
IOException
-
connectSocket
public Socket connectSocket(org.apache.hc.core5.util.TimeValue connectTimeout, Socket socket, org.apache.hc.core5.http.HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException - Specified by:
connectSocketin interfaceorg.apache.hc.client5.http.socket.ConnectionSocketFactory- Throws:
IOException
-
createLayeredSocket
public Socket createLayeredSocket(Socket socket, String target, int port, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException - Specified by:
createLayeredSocketin interfaceorg.apache.hc.client5.http.socket.LayeredConnectionSocketFactory- Throws:
IOException
-
logSocketInfo
Log various diagnostic information from theSSLSocketandSSLSession.- Parameters:
socket- the SSLSocket instance
-
getListAttribute
@Nullable protected String[] getListAttribute(@Nullable org.apache.hc.core5.http.protocol.HttpContext context, @Nonnull String contextKey) - Parameters:
context- the current HttpContextcontextKey- the attribute context key- Returns:
- a String array, or null
-
verifyHostname
protected void verifyHostname(@Nonnull SSLSocket sslsock, @Nonnull String hostname, @Nullable org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Verify the peer's socket hostname against the supplied expected name.- Parameters:
sslsock- the SSL socket being preparedhostname- the expected hostnamecontext- the current HttpContext instance- Throws:
IOException- if peer failed hostname verification, or if there was an error during verification
-