public class SSLContext extends Object
SSLSocketFactory's and SSLEngines.| Modifier | Constructor and Description |
|---|---|
protected |
SSLContext(SSLContextSpi contextSpi,
Provider provider,
String protocol)
Creates a new
SSLContext. |
| Modifier and Type | Method and Description |
|---|---|
SSLEngine |
createSSLEngine()
Creates an
SSLEngine instance from this context. |
SSLEngine |
createSSLEngine(String peerHost,
int peerPort)
Creates an
SSLEngine instance from this context with the
specified hostname and port. |
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 |
getDefault()
Returns the default SSLContext.
|
SSLParameters |
getDefaultSSLParameters()
Returns the default SSL handshake parameters for SSLSockets
created by this SSLContext.
|
static SSLContext |
getInstance(String protocol)
Creates a new
SSLContext instance for the specified protocol. |
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,
String provider)
Creates a new
SSLContext instance for the specified protocol from
the specified provider. |
String |
getProtocol()
Returns the name of the secure socket protocol of this instance.
|
Provider |
getProvider()
Returns the provider of this
SSLContext instance. |
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.
|
SSLServerSocketFactory |
getServerSocketFactory()
Returns a server socket factory for this instance.
|
SSLSocketFactory |
getSocketFactory()
Returns a socket factory for this instance.
|
SSLParameters |
getSupportedSSLParameters()
Returns SSL handshake parameters for SSLSockets that includes
all supported cipher suites and protocols.
|
void |
init(KeyManager[] km,
TrustManager[] tm,
SecureRandom sr)
Initializes this
SSLContext instance. |
static void |
setDefault(SSLContext sslContext)
Sets the default SSLContext instance as returned by
getDefault() to a non-null initialized value. |
protected SSLContext(SSLContextSpi contextSpi, Provider provider, String protocol)
SSLContext.contextSpi - the implementation delegate.provider - the provider.protocol - the protocol name.public static SSLContext getDefault() throws NoSuchAlgorithmException
setDefault(javax.net.ssl.SSLContext). If
not, one will be created with SSLContext.getInstance("Default"), which will already be
initialized.NoSuchAlgorithmException - if there is a problem creating
the default instance.public static void setDefault(SSLContext sslContext)
getDefault() to a non-null initialized value.NullPointerException - on a null argumentpublic static SSLContext getInstance(String protocol) throws NoSuchAlgorithmException
SSLContext instance for the specified protocol.
The following protocols are supported:
| Protocol | API Levels |
|---|---|
| Default | 9+ |
| SSL | 9+ |
| SSLv3 | 9+ |
| TLS | 1+ |
| TLSv1 | 1+ |
| TLSv1.1 | 16+ |
| TLSv1.2 | 16+ |
protocol - the requested protocol to create a context for.SSLContext instance.NoSuchAlgorithmException - if no installed provider can provide the requested protocolNullPointerException - if protocol is null (instead of
NoSuchAlgorithmException as in 1.4 release)public static SSLContext getInstance(String protocol, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
SSLContext instance for the specified protocol from
the specified provider.
The following combinations are supported:
| Protocol | Provider | API Levels |
|---|---|---|
| Default | AndroidOpenSSL | 9+ |
| SSL | AndroidOpenSSL | 9+ |
| SSL | HarmonyJSSE | 9-19 |
| SSLv3 | AndroidOpenSSL | 9+ |
| SSLv3 | HarmonyJSSE | 9-19 |
| TLS | AndroidOpenSSL | 9+ |
| TLS | HarmonyJSSE | 1-19 |
| TLSv1 | AndroidOpenSSL | 9+ |
| TLSv1 | HarmonyJSSE | 1-19 |
| TLSv1.1 | AndroidOpenSSL | 16+ |
| TLSv1.2 | AndroidOpenSSL | 16+ |
NOTE: The best practice is to rely on platform
defaults rather than explicitly specify a provider.
getDefault() and getInstance(String) are normally
preferred over this method.
protocol - the requested protocol to create a context for.provider - the name of the provider that provides the requested protocol.SSLContext for the requested protocol.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) throws NoSuchAlgorithmException
SSLContext instance for the specified protocol from
the specified provider.protocol - the requested protocol to create a context forprovider - the provider that provides the requested protocol.SSLContext for the requested protocol.NoSuchAlgorithmException - if the specified provider cannot provide the requested
protocol.NullPointerException - if protocol is null (instead of
NoSuchAlgorithmException as in 1.4 release)public final String getProtocol()
public final Provider getProvider()
SSLContext instance.SSLContext instance.public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom sr) throws KeyManagementException
SSLContext instance. Three aspects of the context can be configured
during initialization:
KeyManager instances),TrustManager instances),
SecureRandom instance).For each type of KeyManager or TrustManager used by this context, only the
first matching instance from km or tm will be used. For example, only the
first instance of X509TrustManager from tm will be used.
For any parameter set to null defaults will be used. In that case, the installed
security providers will be searched for the highest priority implementation of the required
primitives. For km and tm, the highest priority implementation
of KeyManagerFactory and TrustManagerFactory will be used to obtain the
required types of KeyManager and TrustManager. For sr, the default
SecureRandom implementation will be used.
km - the key sources or null for default.tm - the trust decision sources or null for default.sr - the randomness source or null for default.KeyManagementException - if initializing this instance fails.public final SSLSocketFactory getSocketFactory()
public final SSLServerSocketFactory getServerSocketFactory()
public final SSLEngine createSSLEngine()
SSLEngine instance from this context.SSLEngine instance from this context.UnsupportedOperationException - if the provider does not support the operation.public final SSLEngine createSSLEngine(String peerHost, int peerPort)
SSLEngine instance from this context with the
specified hostname and port.peerHost - the name of the hostpeerPort - the portSSLEngine instance from this context.UnsupportedOperationException - if the provider does not support the operation.public final SSLSessionContext getServerSessionContext()
null
if the underlying provider does not provide an implementation of
the SSLSessionContext interface.public final SSLSessionContext getClientSessionContext()
null
if the underlying provider does not provide an implementation of
the SSLSessionContext interface.public final SSLParameters getDefaultSSLParameters()
UnsupportedOperationExceptionpublic final SSLParameters getSupportedSSLParameters()
UnsupportedOperationException