Top Description Fields Constructors Methods
org.apache.hc.client5.http.ssl

public Class SSLConnectionSocketFactory

extends Object
implements LayeredConnectionSocketFactory
Class Inheritance
All Implemented Interfaces
org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory, org.apache.hc.client5.http.socket.ConnectionSocketFactory
Annotations
@Contract
threading:STATELESS
Imports
java.io.IOException, .InputStream, java.net.InetSocketAddress, .Proxy, .Socket, .SocketAddress, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.Arrays, .Collections, .List, java.util.regex.Pattern, javax.net.ssl.HostnameVerifier, .SSLContext, .SSLException, .SSLHandshakeException, .SSLSession, .SSLSocket, org.apache.hc.client5.http.config.TlsConfig, org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior, org.apache.hc.core5.http.HttpHost, org.apache.hc.core5.http.protocol.HttpContext, org.apache.hc.core5.http.ssl.TLS, .TlsCiphers, org.apache.hc.core5.io.Closer, org.apache.hc.core5.ssl.SSLContexts, .SSLInitializationException, org.apache.hc.core5.util.Args, .Asserts, .TimeValue, .Timeout, org.slf4j.Logger, .LoggerFactory

Layered socket factory for TLS/SSL connections.

SSLSocketFactory can be used to validate the identity of the HTTPS server against a list of trusted certificates and to authenticate to the HTTPS server using a private key.

Since
4.3

Field Summary

Modifier and TypeField and Description
private final HostnameVerifier
private static final Logger
private final SSLSocketFactory
private final String[]
private final String[]
private final TlsSessionValidator
private static final List<Pattern>
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
public
SSLConnectionSocketFactory(final SSLContext sslContext, final HostnameVerifier hostnameVerifier)

public
SSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)

public
SSLConnectionSocketFactory(final SSLSocketFactory socketFactory, final HostnameVerifier hostnameVerifier)

public
SSLConnectionSocketFactory(final SSLSocketFactory socketFactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)

Method Summary

Modifier and TypeMethod and Description
public Socket
connectSocket(final TimeValue
connect timeout.
connectTimeout
,
final Socket
the socket to connect, as obtained from createSocket(HttpContext). null indicates that a new socket should be created and connected.
socket
,
final HttpHost
target host as specified by the caller (end user).
host
,
final InetSocketAddress
the resolved remote address to connect to.
remoteAddress
,
final InetSocketAddress
the local address to bind the socket to, or null for any.
localAddress
,
final HttpContext
the actual HTTP context.
context
)

Implements org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Connects the socket to the target host with the given resolved remote address.
public Socket
connectSocket(final Socket
the socket to connect, as obtained from createSocket(HttpContext). null indicates that a new socket should be created and connected.
socket
,
final HttpHost
target host as specified by the caller (end user).
host
,
final InetSocketAddress
the resolved remote address to connect to.
remoteAddress
,
final InetSocketAddress
the local address to bind the socket to, or null for any.
localAddress
,
final Timeout
connect timeout.
connectTimeout
,
final Object
connect request attachment.
attachment
,
final HttpContext
the actual HTTP context.
context
)

Overrides default org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Connects the socket to the target host with the given resolved remote address.
protected void
connectSocket(final Socket
the socket to connect.
sock
,
final InetSocketAddress
the resolved remote address to connect to.
remoteAddress
,
final Timeout
connect timeout.
connectTimeout
,
final HttpContext
the actual HTTP context.
context
)

Connects the socket to the target host with the given resolved remote address using Socket#connect(SocketAddress, int).

public Socket
createLayeredSocket(final Socket
the existing socket
socket
,
final String
the name of the target host.
target
,
final int
the port to connect to on the target host.
port
,
final HttpContext
the actual HTTP context.
context
)

Implements org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Returns a socket connected to the given host that is layered over an existing socket.
public Socket
createLayeredSocket(final Socket
the existing socket
socket
,
final String
the name of the target host.
target
,
final int
the port to connect to on the target host.
port
,
final Object
connect request attachment.
attachment
,
final HttpContext
the actual HTTP context.
context
)

Overrides default org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Returns a socket connected to the given host that is layered over an existing socket.
public Socket
createSocket(final HttpContext context)

Implements org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Creates new, unconnected socket.
public Socket
createSocket(final Proxy proxy, final HttpContext context)

Overrides default org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Creates new, unconnected socket via a proxy (generally SOCKS is expected).
private void
executeHandshake(final SSLSocket sslsock, final String target, final Object attachment, final HttpContext context)

public static SSLConnectionSocketFactory

Returns:

default SSL socket factory
getSocketFactory
()

Obtains default SSL socket factory with an SSL context based on the standard JSSE trust material (cacerts file in the security properties directory).

public static SSLConnectionSocketFactory

Returns:

default system SSL socket factory
getSystemSocketFactory
()

Obtains default SSL socket factory with an SSL context based on system properties as described in Java™ Secure Socket Extension (JSSE) Reference Guide.

pack-priv static boolean
isWeakCipherSuite(final String cipherSuite)

protected void
protected void
prepareSocket(final SSLSocket socket, final HttpContext context)

Performs any custom initialization for a newly created SSLSocket (before the SSL handshake happens).

private void
verifyHostname(final SSLSocket sslsock, final String hostname)

protected void
verifySession(final String hostname, final SSLSession sslSession)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hostnameVerifierback to summary
private final HostnameVerifier hostnameVerifier
LOGback to summary
private static final Logger LOG
socketFactoryback to summary
private final SSLSocketFactory socketFactory
supportedCipherSuitesback to summary
private final String[] supportedCipherSuites
supportedProtocolsback to summary
private final String[] supportedProtocols
tlsSessionValidatorback to summary
private final TlsSessionValidator tlsSessionValidator
WEAK_CIPHER_SUITE_PATTERNSback to summary
private static final List<Pattern> WEAK_CIPHER_SUITE_PATTERNS
WEAK_CIPHERSback to summary
private static final String WEAK_CIPHERS
WEAK_KEY_EXCHANGESback to summary
private static final String WEAK_KEY_EXCHANGES

Constructor Detail

SSLConnectionSocketFactoryback to summary
public SSLConnectionSocketFactory(final SSLContext sslContext)
SSLConnectionSocketFactoryback to summary
public SSLConnectionSocketFactory(final SSLContext sslContext, final HostnameVerifier hostnameVerifier)
Since
4.4
SSLConnectionSocketFactoryback to summary
public SSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)
Since
4.4
SSLConnectionSocketFactoryback to summary
public SSLConnectionSocketFactory(final SSLSocketFactory socketFactory, final HostnameVerifier hostnameVerifier)
Since
4.4
SSLConnectionSocketFactoryback to summary
public SSLConnectionSocketFactory(final SSLSocketFactory socketFactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)
Since
4.4

Method Detail

connectSocketback to summary
public Socket connectSocket(final TimeValue connectTimeout, final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException

Implements org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Doc from org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Connects the socket to the target host with the given resolved remote address.

Parameters
connectTimeout:TimeValue

connect timeout.

socket:Socket

the socket to connect, as obtained from createSocket(HttpContext). null indicates that a new socket should be created and connected.

host:HttpHost

target host as specified by the caller (end user).

remoteAddress:InetSocketAddress

the resolved remote address to connect to.

localAddress:InetSocketAddress

the local address to bind the socket to, or null for any.

context:HttpContext

the actual HTTP context.

Returns:Socket

the connected socket. The returned object may be different from the sock argument if this factory supports a layered protocol.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
connectSocketback to summary
public Socket connectSocket(final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final Timeout connectTimeout, final Object attachment, final HttpContext context) throws IOException

Overrides default org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Doc from org.apache.hc.client5.http.socket.ConnectionSocketFactory.connectSocket.

Connects the socket to the target host with the given resolved remote address.

Parameters
socket:Socket

the socket to connect, as obtained from createSocket(HttpContext). null indicates that a new socket should be created and connected.

host:HttpHost

target host as specified by the caller (end user).

remoteAddress:InetSocketAddress

the resolved remote address to connect to.

localAddress:InetSocketAddress

the local address to bind the socket to, or null for any.

connectTimeout:Timeout

connect timeout.

attachment:Object

connect request attachment.

context:HttpContext

the actual HTTP context.

Returns:Socket

the connected socket. The returned object may be different from the sock argument if this factory supports a layered protocol.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
connectSocketback to summary
protected void connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final Timeout connectTimeout, final HttpContext context) throws IOException

Connects the socket to the target host with the given resolved remote address using Socket#connect(SocketAddress, int). This method may be overridden to customize how precisely Socket#connect(SocketAddress, int) is handled without impacting other connection establishment code within executeHandshake(SSLSocket, String, Object, HttpContext), for example.

Parameters
sock:Socket

the socket to connect.

remoteAddress:InetSocketAddress

the resolved remote address to connect to.

connectTimeout:Timeout

connect timeout.

context:HttpContext

the actual HTTP context.

Exceptions
IOException:
if an I/O error occurs
createLayeredSocketback to summary
public Socket createLayeredSocket(final Socket socket, final String target, final int port, final HttpContext context) throws IOException

Implements org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Doc from org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Returns a socket connected to the given host that is layered over an existing socket. Used primarily for creating secure sockets through proxies.

Parameters
socket:Socket

the existing socket

target:String

the name of the target host.

port:int

the port to connect to on the target host.

context:HttpContext

the actual HTTP context.

Returns:Socket

Socket a new socket

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while creating the socket
createLayeredSocketback to summary
public Socket createLayeredSocket(final Socket socket, final String target, final int port, final Object attachment, final HttpContext context) throws IOException

Overrides default org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Doc from org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory.createLayeredSocket.

Returns a socket connected to the given host that is layered over an existing socket. Used primarily for creating secure sockets through proxies.

Parameters
socket:Socket

the existing socket

target:String

the name of the target host.

port:int

the port to connect to on the target host.

attachment:Object

connect request attachment.

context:HttpContext

the actual HTTP context.

Returns:Socket

Socket a new socket

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while creating the socket
createSocketback to summary
public Socket createSocket(final HttpContext context) throws IOException

Implements org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Doc from org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Creates new, unconnected socket. The socket should subsequently be passed to connectSocket method.

Annotations
@Override
createSocketback to summary
public Socket createSocket(final Proxy proxy, final HttpContext context) throws IOException

Overrides default org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Doc from org.apache.hc.client5.http.socket.ConnectionSocketFactory.createSocket.

Creates new, unconnected socket via a proxy (generally SOCKS is expected). The socket should subsequently be passed to connectSocket method.

Annotations
@Override
executeHandshakeback to summary
private void executeHandshake(final SSLSocket sslsock, final String target, final Object attachment, final HttpContext context) throws IOException
getSocketFactoryback to summary
public static SSLConnectionSocketFactory getSocketFactory() throws SSLInitializationException

Obtains default SSL socket factory with an SSL context based on the standard JSSE trust material (cacerts file in the security properties directory). System properties are not taken into consideration.

Returns:SSLConnectionSocketFactory

default SSL socket factory

getSystemSocketFactoryback to summary
public static SSLConnectionSocketFactory getSystemSocketFactory() throws SSLInitializationException

Obtains default SSL socket factory with an SSL context based on system properties as described in Java™ Secure Socket Extension (JSSE) Reference Guide.

Returns:SSLConnectionSocketFactory

default system SSL socket factory

isWeakCipherSuiteback to summary
pack-priv static boolean isWeakCipherSuite(final String cipherSuite)
prepareSocketback to summary
protected void prepareSocket(final SSLSocket socket) throws IOException
Annotations
@Deprecated
prepareSocketback to summary
protected void prepareSocket(final SSLSocket socket, final 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., call javax.net.ssl.SSLSocket#setEnabledCipherSuites(String[]).

Annotations
@SuppressWarnings:deprecation
Exceptions
IOException:
may be thrown if overridden
verifyHostnameback to summary
private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException
verifySessionback to summary
protected void verifySession(final String hostname, final SSLSession sslSession) throws SSLException