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.
SSLSocketFactory will enable server authentication when supplied with
a trust-store file containing one or several trusted certificates. The client
secure socket will reject the connection during the SSL session handshake if the target HTTPS
server attempts to authenticate itself with a non-trusted certificate.
Use JDK keytool utility to import a trusted certificate and generate a trust-store file:
keytool -import -alias "my server cert" -file server.crt -keystore my.truststore
In special cases the standard trust verification process can be bypassed by using a custom
org.. This interface is primarily intended for allowing self-signed
certificates to be accepted as trusted without having to add them to the trust-store file.
SSLSocketFactory will enable client authentication when supplied with
a key-store file containing a private key/public certificate
pair. The client secure socket will use the private key to authenticate
itself to the target HTTPS server during the SSL session handshake if
requested to do so by the server.
The target HTTPS server will in its turn verify the certificate presented
by the client in order to establish client's authenticity.
Use the following sequence of actions to generate a key-store file
Use JDK keytool utility to generate a new key
keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore
For simplicity use the same password for the key as that of the key-store
Issue a certificate signing request (CSR)
keytool -certreq -alias "my client key" -file mycertreq.csr -keystore my.keystore
Send the certificate request to the trusted Certificate Authority for signature. One may choose to act as her own CA and sign the certificate request using a PKI tool, such as OpenSSL.
Import the trusted CA root certificate
keytool -import -alias "my trusted ca" -file caroot.crt -keystore my.keystore
Import the PKCS#7 file containing the complete certificate chain
keytool -import -alias "my client key" -file mycert.p7 -keystore my.keystore
Verify the content of the resultant keystore file
keytool -list -v -keystore my.keystore
| Modifier and Type | Field and Description |
|---|---|
| public static final X509HostnameVerifier | ALLOW_ALL_HOSTNAME_VERIFIER
Deprecated
Use
AllowAllHostnameVerifier#INSTANCE.
|
| public static final X509HostnameVerifier | |
| private final HostnameVerifier | |
| private final Log | |
| private final SSLSocketFactory | |
| public static final String | |
| public static final String | |
| public static final X509HostnameVerifier | STRICT_HOSTNAME_VERIFIER
Deprecated
Use
StrictHostnameVerifier#INSTANCE.
|
| private final String[] | |
| private final String[] | |
| public static final String | |
| private static final List | |
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SSLConnectionSocketFactory(final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier)
Deprecated
(4.4) Use
SSLConnectionSocketFactory(javax.
|
| public | SSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier)
|
| public | SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final X509HostnameVerifier hostnameVerifier)
|
| public | SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier)
|
| public | |
| 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)
|
| Modifier and Type | Method and Description |
|---|---|
| public Socket | connectSocket(final int
connect timeout. connectTimeout, final Socket the socket to connect, as obtained from socket, final HttpHost createSocket(HttpContext).
null indicates that a new socket should be created and connected.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 localAddress, final HttpContext null for any.the actual HTTP context. context)Implements org. |
| 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. |
| public Socket | createSocket(final HttpContext context)
Implements org. |
| public static HostnameVerifier | |
| public static SSLConnectionSocketFactory | Returns: default SSL socket factoryObtains default SSL socket factory with an SSL context based on the standard JSSE
trust material ( |
| public static SSLConnectionSocketFactory | Returns: default system SSL socket factoryObtains 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 | |
| protected void | prepareSocket(final SSLSocket socket)
Performs any custom initialization for a newly created SSLSocket (before the SSL handshake happens). |
| private static String[] | |
| private void |
| ALLOW_ALL_HOSTNAME_VERIFIER | back to summary |
|---|---|
| public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
Deprecated | |
| BROWSER_COMPATIBLE_HOSTNAME_VERIFIER | back to summary |
|---|---|
| public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
Deprecated | |
| hostnameVerifier | back to summary |
|---|---|
| private final HostnameVerifier hostnameVerifier | |
| log | back to summary |
|---|---|
| private final Log log | |
| socketfactory | back to summary |
|---|---|
| private final SSLSocketFactory socketfactory | |
| SSL | back to summary |
|---|---|
| public static final String SSL | |
| SSLV2 | back to summary |
|---|---|
| public static final String SSLV2 | |
| STRICT_HOSTNAME_VERIFIER | back to summary |
|---|---|
| public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER
Deprecated | |
| supportedCipherSuites | back to summary |
|---|---|
| private final String[] supportedCipherSuites | |
| supportedProtocols | back to summary |
|---|---|
| private final String[] supportedProtocols | |
| TLS | back to summary |
|---|---|
| public static final String TLS | |
| WEAK_CIPHER_SUITE_PATTERNS | back to summary |
|---|---|
| private static final List<Pattern> WEAK_CIPHER_SUITE_PATTERNS | |
| WEAK_CIPHERS | back to summary |
|---|---|
| private static final String WEAK_CIPHERS | |
| WEAK_KEY_EXCHANGES | back to summary |
|---|---|
| private static final String WEAK_KEY_EXCHANGES | |
| SSLConnectionSocketFactory | back to summary |
|---|---|
| public SSLConnectionSocketFactory(final SSLContext sslContext) | |
| SSLConnectionSocketFactory | back to summary |
|---|---|
| public SSLConnectionSocketFactory(final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier)
Deprecated (4.4) Use
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
| public SSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier)
Deprecated
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
| public SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final X509HostnameVerifier hostnameVerifier)
Deprecated (4.4) Use
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
| public SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier)
Deprecated
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
public SSLConnectionSocketFactory(final SSLContext sslContext, final HostnameVerifier hostnameVerifier)
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
public SSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
public SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final HostnameVerifier hostnameVerifier)
| |
| SSLConnectionSocketFactory | back to summary |
|---|---|
public SSLConnectionSocketFactory(final SSLSocketFactory socketfactory, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)
| |
| connectSocket | back to summary |
|---|---|
| public Socket connectSocket(final int connectTimeout, final Socket socket, final HttpHost host, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException Implements org. Doc from org. Connects the socket to the target host with the given resolved remote address.
| |
| createLayeredSocket | back to summary |
|---|---|
| public Socket createLayeredSocket(final Socket socket, final String target, final int port, final HttpContext context) throws IOException Implements org. Doc from org. Returns a socket connected to the given host that is layered over an existing socket. Used primarily for creating secure sockets through proxies.
| |
| createSocket | back to summary |
|---|---|
| public Socket createSocket(final HttpContext context) throws IOException Implements org. Doc from org. Creates new, unconnected socket. The socket should subsequently be passed to
| |
| getDefaultHostnameVerifier | back to summary |
|---|---|
public static HostnameVerifier getDefaultHostnameVerifier()
| |
| getSocketFactory | back to summary |
|---|---|
| public static SSLConnectionSocketFactory getSocketFactory() throws SSLInitializationException Obtains default SSL socket factory with an SSL context based on the standard JSSE
trust material (
| |
| getSystemSocketFactory | back 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.
| |
| isWeakCipherSuite | back to summary |
|---|---|
| pack-priv static boolean isWeakCipherSuite(final String cipherSuite) | |
| prepareSocket | back to summary |
|---|---|
| protected void prepareSocket(final SSLSocket socket) 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
| |
| split | back to summary |
|---|---|
| private static String[] split(final String s) | |
| verifyHostname | back to summary |
|---|---|
| private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException | |