is new.
java.lang.Objectjavax.net.ssl.SSLContext
public class SSLContext
Instances of this class represent a secure socket protocol implementation which acts as a factory for secure socket factories or SSLEngines. This class is initialized with an optional set of key and trust managers and source of secure random bytes.
| Constructor Summary | |
|---|---|
| protected |
SSLContext
(
SSLContextSpi
contextSpi,
Provider
provider,
String
protocol) Creates an SSLContext object. |
| Method Summary | |
|---|---|
| SSLEngine |
createSSLEngine
() Creates a new SSLEngine using this context. |
| SSLEngine |
createSSLEngine
(
String
peerHost, int peerPort) Creates a new SSLEngine using this context using advisory peer information. |
| SSLSessionContext |
getClientSessionContext
() Returns the client session context, which represents the set of SSL sessions available for use during the handshake phase of client-side SSL sockets. |
| static SSLContext |
getDefault
()
Returns
default SSL context.
|
SSLParameters
|
getDefaultSSLParameters
()
Returns a copy of the SSLParameters indicating the default settings for this SSL context.
|
|
|
| static SSLContext |
getInstance
Returns
protocol.
|
static
SSLContext
|
getInstance
(
String
protocol,
Provider
Returns a SSLContext object that implements the specified secure socket protocol.
|
static
SSLContext
|
getInstance
(
String
protocol,
String
Returns a SSLContext object that implements the specified secure socket protocol.
|
| String |
getProtocol
() Returns the protocol name of this SSLContext object. |
| Provider |
getProvider
() Returns the provider of this SSLContext object. |
| SSLSessionContext |
getServerSessionContext
() Returns the server session context, which represents the set of SSL sessions available for use during the handshake phase of server-side SSL sockets. |
| SSLServerSocketFactory |
getServerSocketFactory
() Returns a ServerSocketFactory object for this context. |
| SSLSocketFactory |
getSocketFactory
() Returns a SocketFactory object for this context. |
SSLParameters
|
getSupportedSSLParameters
()
Returns a copy of the SSLParameters indicating the supported settings for this SSL context.
|
| void |
init
(
KeyManager
[] km,
TrustManager
[] tm,
SecureRandom
random) Initializes this context. |
static void
|
setDefault
(
SSLContext
Sets the default SSL context.
|
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Constructor Detail |
|---|
protected SSLContext(SSLContextSpi contextSpi,
Provider provider,
String protocol)
| Method Detail |
|---|
getDefault
public static
SSLContext
getDefault
() throws
NoSuchAlgorithmException
Returns the default SSL context.
If a default context was set using the
SSLContext.setDefault()
method, it is returned. Otherwise, the first call of this method triggers the call SSLContext.getInstance("Default"). If successful, that object is made the default SSL context and returned.
The default context is immediately usable and does not require
initialization
.
Returns:
the default SSL context
Throws:
NoSuchAlgorithmException
- if the
SSLContext.getInstance()
call fails
Since:
1.6
setDefault
public static void
setDefault
(
SSLContext
context)
Sets the default SSL context. It will be returned by subsequent calls to
getDefault()
. The default context must be immediately usable and not require
initialization
.
Parameters:
context - the SSLContext
Throws:
NullPointerException
- if context is null
SecurityException
- if a security manager exists and its checkPermission method does not allow SSLPermission("setDefaultSSLContext")
Since:
1.6
public static SSLContext getInstance(String protocol)
throws NoSuchAlgorithmException
Returns
This method traverses the list of registered security Providers, starting with the most preferred Provider. A new SSLContext object encapsulating the SSLContextSpi implementation from the first Provider that supports the specified protocol is returned.
If the default provider package provides an implementation of the requested key management algorithm, an instance of SSLContext containing that implementation is returned. If the algorithm is not available in the default provider package, other provider packages are searched.
Note that the list of registered providers may be retrieved via the
Security.getProviders()
method.
See Appendix A in the
Java Secure Socket Extension Reference Guide
for information about standard protocol names.
object.
- if no Provider supports a TrustManagerFactorySpi implementation for the specified protocol.
See Also:
Provider
public static SSLContext getInstance(String protocol,
String provider)
throws NoSuchAlgorithmException,
NoSuchProviderException
Returns
protocol.
A new SSLContext object encapsulating the SSLContextSpi implementation from the specified provider is returned. The specified provider must be registered in the security provider list.
Note that the list of registered providers may be retrieved via the
Security.getProviders()
method.
See Appendix A in the
Java Secure Socket Extension Reference Guide
for information about standard protocol names.
provider.
object.
a SSLContextSpi implementation for
the specified protocol is not available from the specified provider.
is
registered in the security provider list.
See Also:
Provider
public static SSLContext getInstance(String protocol,
Provider provider)
throws NoSuchAlgorithmException
Returns
protocol.
A new SSLContext object encapsulating the SSLContextSpi implementation from the specified Provider object is returned. Note that the specified Provider object does not have to be registered in the provider list.
See Appendix A in the
Java Secure Socket Extension Reference Guide
for information about standard protocol names.
provider.
object.
a KeyManagerFactorySpi implementation for
the specified protocol is not available from the specified
Provider object.
See Also:
Provider
public final String getProtocol()
This is the same name that was specified in one of the getInstance calls that created this SSLContext object.
public final Provider getProvider()
public final void init(KeyManager[] km,
TrustManager[] tm,
SecureRandom random)
throws KeyManagementException
Only the first instance of a particular key and/or trust manager implementation type in the array is used. (For example, only the first javax.net.ssl.X509KeyManager in the array will be used.)
public final SSLSocketFactory getSocketFactory()
Throws:
IllegalStateException
- if the SSLContextImpl requires initialization and the init() has not been called
public final SSLServerSocketFactory getServerSocketFactory()
Throws:
IllegalStateException
- if the SSLContextImpl requires initialization and the init() has not been called
public final SSLEngine createSSLEngine()
Applications using this factory method are providing no hints for an internal session reuse strategy. If hints are desired, createSSLEngine(String, int) should be used instead.
Some cipher suites (such as Kerberos) require remote hostname information, in which case this factory method should not be used.
IllegalStateException
- if the SSLContextImpl requires initialization and the init() has not been called
public final SSLEngine createSSLEngine(String peerHost,
int peerPort)
Applications using this factory method are providing hints for an internal session reuse strategy.
Some cipher suites (such as Kerberos) require remote hostname information, in which case peerHost needs to be specified.
IllegalStateException
- if the SSLContextImpl requires initialization and the init() has not been called
public final SSLSessionContext getServerSessionContext()
This context may be unavailable in some environments, in which case this method returns null. For example, when the underlying SSL provider does not provide an implementation of SSLSessionContext interface, this method returns null. A non-null session context is returned otherwise.
public final SSLSessionContext getClientSessionContext()
This context may be unavailable in some environments, in which case this method returns null. For example, when the underlying SSL provider does not provide an implementation of SSLSessionContext interface, this method returns null. A non-null session context is returned otherwise.
getDefaultSSLParameters
public final
SSLParameters
getDefaultSSLParameters
()
Returns a copy of the SSLParameters indicating the default settings for this SSL context.
The parameters will always have the ciphersuites and protocols arrays set to non-null values.
Returns:
a copy of the SSLParameters object with the default settings
Throws:
UnsupportedOperationException
- if the default SSL parameters could not be obtained.
Since:
1.6
getSupportedSSLParameters
public final
SSLParameters
getSupportedSSLParameters
()
Returns a copy of the SSLParameters indicating the supported settings for this SSL context.
The parameters will always have the ciphersuites and protocols arrays set to non-null values.
Returns:
a copy of the SSLParameters object with the supported settings
Throws:
UnsupportedOperationException
- if the supported SSL parameters could not be obtained.
Since:
1.6