public class

SSLCertificateSocketFactory

extends SSLSocketFactory
java.lang.Object
   ↳ javax.net.SocketFactory
     ↳ javax.net.ssl.SSLSocketFactory
       ↳ android.net.SSLCertificateSocketFactory

Class Overview

SSLSocketFactory implementation with several extra features:

  • Timeout specification for SSL handshake operations
  • Optional SSL session caching with SSLSessionCache
  • Optionally bypass all SSL certificate checks
Note that the handshake timeout does not apply to actual connection. If you want a connection timeout as well, use createSocket() and connect(SocketAddress, int).

On development devices, "setprop socket.relaxsslcheck yes" bypasses all SSL certificate checks, for testing with development servers.

Summary

Public Constructors
SSLCertificateSocketFactory(int handshakeTimeoutMillis)
This constructor is deprecated. Use getDefault(int) instead.
Public Methods
Socket createSocket(String host, int port)
Creates a new socket which is connected to the remote host specified by the parameters host and port.
Socket createSocket(InetAddress addr, int port, InetAddress localAddr, int localPort)
Creates a new socket which is connected to the remote host specified by the InetAddress address.
Socket createSocket()
Creates a new socket which is not connected to any remote host.
Socket createSocket(String host, int port, InetAddress localAddr, int localPort)
Creates a new socket which is connected to the remote host specified by the parameters host and port.
Socket createSocket(InetAddress addr, int port)
Creates a new socket which is connected to the remote host specified by the InetAddress host.
Socket createSocket(Socket k, String host, int port, boolean close)
Creates an SSLSocket over the specified socket that is connected to the specified host at the specified port.
static SSLSocketFactory getDefault(int handshakeTimeoutMillis, SSLSessionCache cache)
Returns a new socket factory instance with an optional handshake timeout and SSL session cache.
static SocketFactory getDefault(int handshakeTimeoutMillis)
Returns a new socket factory instance with an optional handshake timeout.
String[] getDefaultCipherSuites()
Returns the names of the cipher suites that are enabled by default.
static SSLSocketFactory getHttpSocketFactory(int handshakeTimeoutMillis, SSLSessionCache cache)
Returns a socket factory (also named SSLSocketFactory, but in a different namespace) for use with the Apache HTTP stack.
static SSLSocketFactory getInsecure(int handshakeTimeoutMillis, SSLSessionCache cache)
Returns a new instance of a socket factory with all SSL security checks disabled, using an optional handshake timeout and SSL session cache.
String[] getSupportedCipherSuites()
Returns the names of the cipher suites that are supported and could be enabled for an SSL connection.
[Expand]
Inherited Methods
From class javax.net.ssl.SSLSocketFactory
From class javax.net.SocketFactory
From class java.lang.Object

Public Constructors

public SSLCertificateSocketFactory (int handshakeTimeoutMillis)

Since: API Level 1

This constructor is deprecated.
Use getDefault(int) instead.

Public Methods

public Socket createSocket (String host, int port)

Since: API Level 1

Creates a new socket which is connected to the remote host specified by the parameters host and port. The socket is bound to any available local address and port.

Parameters
host the remote host address the socket has to be connected to.
port the port number of the remote host at which the socket is connected.
Returns
  • the created connected socket.
Throws
IOException

public Socket createSocket (InetAddress addr, int port, InetAddress localAddr, int localPort)

Since: API Level 1

Creates a new socket which is connected to the remote host specified by the InetAddress address. The socket is bound to the local network interface specified by the InetAddress localHost on port localPort.

Parameters
addr the remote host address the socket has to be connected to.
port the port number of the remote host at which the socket is connected.
localAddr the local host address the socket is bound to.
localPort the port number of the local host at which the socket is bound.
Returns
  • the created connected socket.
Throws
IOException

public Socket createSocket ()

Since: API Level 1

Creates a new socket which is not connected to any remote host. This method has to be overridden by a subclass otherwise a SocketException is thrown.

Returns
  • the created unconnected socket.
Throws
IOException

public Socket createSocket (String host, int port, InetAddress localAddr, int localPort)

Since: API Level 1

Creates a new socket which is connected to the remote host specified by the parameters host and port. The socket is bound to the local network interface specified by the InetAddress localHost on port localPort.

Parameters
host the remote host address the socket has to be connected to.
port the port number of the remote host at which the socket is connected.
localAddr the local host address the socket is bound to.
localPort the port number of the local host at which the socket is bound.
Returns
  • the created connected socket.
Throws
IOException

public Socket createSocket (InetAddress addr, int port)

Since: API Level 1

Creates a new socket which is connected to the remote host specified by the InetAddress host. The socket is bound to any available local address and port.

Parameters
addr the host address the socket has to be connected to.
port the port number of the remote host at which the socket is connected.
Returns
  • the created connected socket.
Throws
IOException

public Socket createSocket (Socket k, String host, int port, boolean close)

Since: API Level 1

Creates an SSLSocket over the specified socket that is connected to the specified host at the specified port.

Parameters
k the socket.
host the host.
port the port number.
close true if socket s should be closed when the created socket is closed, false if the socket s should be left open.
Returns
  • the creates ssl socket.
Throws
IOException

public static SSLSocketFactory getDefault (int handshakeTimeoutMillis, SSLSessionCache cache)

Since: API Level 8

Returns a new socket factory instance with an optional handshake timeout and SSL session cache.

Parameters
handshakeTimeoutMillis to use for SSL connection handshake, or 0 for none. The socket timeout is reset to 0 after the handshake.
cache The SSLClientSessionCache to use, or null for no cache.
Returns
  • a new SocketFactory with the specified parameters

public static SocketFactory getDefault (int handshakeTimeoutMillis)

Since: API Level 1

Returns a new socket factory instance with an optional handshake timeout.

Parameters
handshakeTimeoutMillis to use for SSL connection handshake, or 0 for none. The socket timeout is reset to 0 after the handshake.
Returns
  • a new SocketFactory with the specified parameters

public String[] getDefaultCipherSuites ()

Since: API Level 1

Returns the names of the cipher suites that are enabled by default.

Returns
  • the names of the cipher suites that are enabled by default.

public static SSLSocketFactory getHttpSocketFactory (int handshakeTimeoutMillis, SSLSessionCache cache)

Since: API Level 8

Returns a socket factory (also named SSLSocketFactory, but in a different namespace) for use with the Apache HTTP stack.

Parameters
handshakeTimeoutMillis to use for SSL connection handshake, or 0 for none. The socket timeout is reset to 0 after the handshake.
cache The SSLClientSessionCache to use, or null for no cache.
Returns
  • a new SocketFactory with the specified parameters

public static SSLSocketFactory getInsecure (int handshakeTimeoutMillis, SSLSessionCache cache)

Since: API Level 8

Returns a new instance of a socket factory with all SSL security checks disabled, using an optional handshake timeout and SSL session cache. Sockets created using this factory are vulnerable to man-in-the-middle attacks!

Parameters
handshakeTimeoutMillis to use for SSL connection handshake, or 0 for none. The socket timeout is reset to 0 after the handshake.
cache The SSLClientSessionCache to use, or null for no cache.
Returns
  • an insecure SocketFactory with the specified parameters

public String[] getSupportedCipherSuites ()

Since: API Level 1

Returns the names of the cipher suites that are supported and could be enabled for an SSL connection.

Returns
  • the names of the cipher suites that are supported.