@ThreadSafe public class TLSSocketFactory extends Object implements LayeredConnectionSocketFactory
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:
StrictHostnameVerifier rather than
BrowserCompatHostnameVerifierHttpContext attributes.HttpContext attribute.| Modifier and Type | Field and Description |
|---|---|
static X509HostnameVerifier |
ALLOW_ALL_HOSTNAME_VERIFIER
Hostname verifier which passes all hostnames.
|
static X509HostnameVerifier |
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
Hostname verifier which implements a policy similar to most browsers.
|
static String |
CONTEXT_KEY_HOSTNAME_VERIFIER
HttpContext key for an instance of
X509HostnameVerifier. |
static String |
CONTEXT_KEY_TLS_CIPHER_SUITES
HttpContext key for a a list of TLS cipher suites to enable on the socket.
|
static String |
CONTEXT_KEY_TLS_PROTOCOLS
HttpContext key for a a list of TLS protocols to enable on the socket.
|
private X509HostnameVerifier |
hostnameVerifier
Hostname verifier.
|
private Logger |
log
Logger.
|
private SSLSocketFactory |
socketfactory
Socket factory.
|
static String |
SSL
Protocol: SSL.
|
static String |
SSLV2
Protocol: SSLv2.
|
static X509HostnameVerifier |
STRICT_HOSTNAME_VERIFIER
Hostname verifier which implements a strict policy.
|
private String[] |
supportedCipherSuites
Factory-wide supported cipher suites.
|
private String[] |
supportedProtocols
Factory-wide supported protocols.
|
static String |
TLS
Protocol: TLS.
|
| Constructor and Description |
|---|
TLSSocketFactory(SSLContext sslContext)
Constructor.
|
TLSSocketFactory(SSLContext sslContext,
String[] protocols,
String[] cipherSuites,
X509HostnameVerifier verifier)
Constructor.
|
TLSSocketFactory(SSLContext sslContext,
X509HostnameVerifier verifier)
Constructor.
|
TLSSocketFactory(SSLSocketFactory factory,
String[] protocols,
String[] cipherSuites,
X509HostnameVerifier verifier)
Constructor.
|
TLSSocketFactory(SSLSocketFactory factory,
X509HostnameVerifier verifier)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Socket |
connectSocket(int connectTimeout,
Socket socket,
org.apache.http.HttpHost host,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
org.apache.http.protocol.HttpContext context) |
Socket |
createLayeredSocket(Socket socket,
String target,
int port,
org.apache.http.protocol.HttpContext context) |
Socket |
createSocket(org.apache.http.protocol.HttpContext context) |
protected X509HostnameVerifier |
getHostnameVerifier()
Get the configured hostname verifier.
|
protected String[] |
getListAttribute(org.apache.http.protocol.HttpContext context,
String contextKey)
Get a normalized String array from a context attribute holding a
List. |
protected SSLSocketFactory |
getSocketfactory()
Get the JSSE socket factory instance.
|
protected String[] |
getSupportedCipherSuites()
Get the configured factory-wide supported cipher suites.
|
protected String[] |
getSupportedProtocols()
Get the configured factory-wide supported protocols.
|
private void |
logSocketInfo(SSLSocket socket)
Log various diagnostic information from the
SSLSocket and SSLSession. |
protected void |
prepareSocket(SSLSocket socket,
org.apache.http.protocol.HttpContext context)
Performs any custom initialization for a newly created SSLSocket
(before the SSL handshake happens).
|
protected void |
verifyHostname(SSLSocket sslsock,
String hostname,
org.apache.http.protocol.HttpContext context)
Verify the peer's socket hostname against the supplied expected name.
|
public static final String CONTEXT_KEY_TLS_PROTOCOLS
List.public static final String CONTEXT_KEY_TLS_CIPHER_SUITES
List.public static final String CONTEXT_KEY_HOSTNAME_VERIFIER
X509HostnameVerifier.public static final String TLS
public static final String SSL
public static final String SSLV2
public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER
private final Logger log
private final SSLSocketFactory socketfactory
private final X509HostnameVerifier hostnameVerifier
private final String[] supportedProtocols
private final String[] supportedCipherSuites
public TLSSocketFactory(@Nonnull SSLContext sslContext)
sslContext - the effective SSLContext instancepublic TLSSocketFactory(@Nonnull SSLContext sslContext, @Nullable X509HostnameVerifier verifier)
sslContext - the effective SSLContext instanceverifier - the effective hostname verifierpublic TLSSocketFactory(@Nonnull SSLContext sslContext, @Nullable String[] protocols, @Nullable String[] cipherSuites, @Nullable X509HostnameVerifier verifier)
sslContext - the effective SSLContext instanceprotocols - the factory-wide enabled TLS protocolscipherSuites - the factory-wide enabled TLS cipher suitesverifier - the effective hostname verifierpublic TLSSocketFactory(@Nonnull SSLSocketFactory factory, @Nullable X509HostnameVerifier verifier)
factory - the effective SSL socket factoryverifier - the effective hostname verifierpublic TLSSocketFactory(@Nonnull SSLSocketFactory factory, @Nullable String[] protocols, @Nullable String[] cipherSuites, @Nullable X509HostnameVerifier verifier)
factory - the effective SSL socket factoryprotocols - the factory-wide enabled TLS protocolscipherSuites - the factory-wide enabled TLS cipher suitesverifier - the effective hostname verifier@Nonnull protected SSLSocketFactory getSocketfactory()
@Nonnull protected X509HostnameVerifier getHostnameVerifier()
@Nullable protected String[] getSupportedProtocols()
@Nullable protected String[] getSupportedCipherSuites()
protected void prepareSocket(@Nonnull SSLSocket socket, @Nullable org.apache.http.protocol.HttpContext context) throws IOException
SSLSocket.setEnabledCipherSuites(String[]).socket - the SSL socket instance being preparedcontext - the current HttpContext instanceIOException - if there is an error customizing the socket@Nonnull public Socket createSocket(@Nullable org.apache.http.protocol.HttpContext context) throws IOException
createSocket in interface ConnectionSocketFactoryIOExceptionpublic Socket connectSocket(int connectTimeout, @Nullable Socket socket, @Nonnull org.apache.http.HttpHost host, @Nonnull InetSocketAddress remoteAddress, @Nullable InetSocketAddress localAddress, @Nullable org.apache.http.protocol.HttpContext context) throws IOException
connectSocket in interface ConnectionSocketFactoryIOExceptionpublic Socket createLayeredSocket(@Nonnull Socket socket, @Nonnull@NotEmpty String target, int port, @Nullable org.apache.http.protocol.HttpContext context) throws IOException
createLayeredSocket in interface LayeredConnectionSocketFactoryIOExceptionprivate void logSocketInfo(SSLSocket socket)
SSLSocket and SSLSession.socket - the SSLSocket instance@Nullable protected String[] getListAttribute(@Nullable org.apache.http.protocol.HttpContext context, @Nonnull String contextKey)
List.context - the current HttpContextcontextKey - the attribute context keyprotected void verifyHostname(@Nonnull SSLSocket sslsock, @Nonnull String hostname, @Nullable org.apache.http.protocol.HttpContext context) throws IOException
sslsock - the SSL socket being preparedhostname - the expected hostnamecontext - the current HttpContext instanceIOException - if peer failed hostname verification, or if there was an error during verificationCopyright © 1999–2016 Shibboleth Consortium. All rights reserved.