public class

SSLContext

extends Object
java.lang.Object
   ↳ javax.net.ssl.SSLContext

Class Overview

The public API for secure socket protocol implementations. It acts as factory for SSLSocketFactory's and SSLEngines.

Summary

Protected Constructors
SSLContext(SSLContextSpi contextSpi, Provider provider, String protocol)
Creates a new SSLContext.
Public Methods
final SSLEngine createSSLEngine(String peerHost, int peerPort)
Creates an SSLEngine instance from this context with the specified hostname and port.
final SSLEngine createSSLEngine()
Creates an SSLEngine instance from this context.
final SSLSessionContext getClientSessionContext()
Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of client-side SSL sockets.
static SSLContext getInstance(String protocol, String provider)
Creates a new SSLContext instance for the specified protocol from the specified provider.
static SSLContext getInstance(String protocol, Provider provider)
Creates a new SSLContext instance for the specified protocol from the specified provider.
static SSLContext getInstance(String protocol)
Creates a new SSLContext instance for the specified protocol.
final String getProtocol()
Returns the name of the secure socket protocol of this instance.
final Provider getProvider()
Returns the provider of this SSLContext instance.
final SSLSessionContext getServerSessionContext()
Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of server-side SSL sockets.
final SSLServerSocketFactory getServerSocketFactory()
Returns a server socket factory for this instance.
final SSLSocketFactory getSocketFactory()
Returns a socket factory for this instance.
final void init(KeyManager[] km, TrustManager[] tm, SecureRandom sr)
Initializes this SSLContext instance.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected SSLContext (SSLContextSpi contextSpi, Provider provider, String protocol)

Since: API Level 1

Creates a new SSLContext.

Parameters
contextSpi the implementation delegate.
provider the provider.
protocol the protocol name.

Public Methods

public final SSLEngine createSSLEngine (String peerHost, int peerPort)

Since: API Level 1

Creates an SSLEngine instance from this context with the specified hostname and port.

Parameters
peerHost the name of the host
peerPort the port
Returns
  • an SSLEngine instance from this context.
Throws
UnsupportedOperationException if the provider does not support the operation.

public final SSLEngine createSSLEngine ()

Since: API Level 1

Creates an SSLEngine instance from this context.

Returns
  • an SSLEngine instance from this context.
Throws
UnsupportedOperationException if the provider does not support the operation.

public final SSLSessionContext getClientSessionContext ()

Since: API Level 1

Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of client-side SSL sockets.

Returns
  • the SSL client session context for this context or null if the underlying provider does not provide an implementation of the SSLSessionContext interface.

public static SSLContext getInstance (String protocol, String provider)

Since: API Level 1

Creates a new SSLContext instance for the specified protocol from the specified provider.

Parameters
protocol the requested protocol to create a context for.
provider the name of the provider that provides the requested protocol.
Returns
  • an SSLContext for the requested protocol.
Throws
NoSuchAlgorithmException if the specified provider cannot provider the requested protocol.
NoSuchProviderException if the specified provider does not exits.
NullPointerException if protocol is null (instead of NoSuchAlgorithmException as in 1.4 release)

public static SSLContext getInstance (String protocol, Provider provider)

Since: API Level 1

Creates a new SSLContext instance for the specified protocol from the specified provider.

Parameters
protocol the requested protocol to create a context for
provider the provider that provides the requested protocol.
Returns
  • an SSLContext for the requested protocol.
Throws
NoSuchAlgorithmException if the specified provider cannot provide the requested protocol.
NullPointerException if protocol is null (instead of NoSuchAlgorithmException as in 1.4 release)

public static SSLContext getInstance (String protocol)

Since: API Level 1

Creates a new SSLContext instance for the specified protocol.

Parameters
protocol the requested protocol to create a context for.
Returns
  • the created SSLContext instance.
Throws
NoSuchAlgorithmException if no installed provider can provide the requested protocol
NullPointerException if protocol is null (instead of NoSuchAlgorithmException as in 1.4 release)

public final String getProtocol ()

Since: API Level 1

Returns the name of the secure socket protocol of this instance.

Returns
  • the name of the secure socket protocol of this instance.

public final Provider getProvider ()

Since: API Level 1

Returns the provider of this SSLContext instance.

Returns
  • the provider of this SSLContext instance.

public final SSLSessionContext getServerSessionContext ()

Since: API Level 1

Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of server-side SSL sockets.

Returns
  • the SSL server session context for this context or null if the underlying provider does not provide an implementation of the SSLSessionContext interface.

public final SSLServerSocketFactory getServerSocketFactory ()

Since: API Level 1

Returns a server socket factory for this instance.

Returns
  • a server socket factory for this instance.

public final SSLSocketFactory getSocketFactory ()

Since: API Level 1

Returns a socket factory for this instance.

Returns
  • a socket factory for this instance.

public final void init (KeyManager[] km, TrustManager[] tm, SecureRandom sr)

Since: API Level 1

Initializes this SSLContext instance. All of the arguments are optional, and the security providers will be searched for the required implementations of the needed algorithms.

Parameters
km the key sources or null.
tm the trust decision sources or null.
sr the randomness source or null.
Throws
KeyManagementException if initializing this instance fails.