Package javax.net.ssl
Class SSLContext
java.lang.Object
javax.net.ssl.SSLContext
public class SSLContext extends Object
The public API for secure socket protocol implementations. It acts as factory
for
SSLSocketFactory's and SSLEngines.-
Constructor Summary
Constructors Modifier Constructor Description protectedSSLContext(SSLContextSpi contextSpi, Provider provider, String protocol)Creates a newSSLContext. -
Method Summary
Modifier and Type Method Description SSLEnginecreateSSLEngine()Creates anSSLEngineinstance from this context.SSLEnginecreateSSLEngine(String peerHost, int peerPort)Creates anSSLEngineinstance from this context with the specified hostname and port.SSLSessionContextgetClientSessionContext()Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of client-side SSL sockets.static SSLContextgetDefault()Returns the default SSLContext.SSLParametersgetDefaultSSLParameters()Returns the default SSL handshake parameters for SSLSockets created by this SSLContext.static SSLContextgetInstance(String protocol)Creates a newSSLContextinstance for the specified protocol.static SSLContextgetInstance(String protocol, String provider)Creates a newSSLContextinstance for the specified protocol from the specified provider.static SSLContextgetInstance(String protocol, Provider provider)Creates a newSSLContextinstance for the specified protocol from the specified provider.StringgetProtocol()Returns the name of the secure socket protocol of this instance.ProvidergetProvider()Returns the provider of thisSSLContextinstance.SSLSessionContextgetServerSessionContext()Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of server-side SSL sockets.SSLServerSocketFactorygetServerSocketFactory()Returns a server socket factory for this instance.SSLSocketFactorygetSocketFactory()Returns a socket factory for this instance.SSLParametersgetSupportedSSLParameters()Returns SSL handshake parameters for SSLSockets that includes all supported cipher suites and protocols.voidinit(KeyManager[] km, TrustManager[] tm, SecureRandom sr)Initializes thisSSLContextinstance.static voidsetDefault(SSLContext sslContext)Sets the default SSLContext instance as returned bygetDefault()to a non-null initialized value.
-
Constructor Details
-
SSLContext
Creates a newSSLContext.- Parameters:
contextSpi- the implementation delegate.provider- the provider.protocol- the protocol name.
-
-
Method Details
-
getDefault
Returns the default SSLContext. The default SSL context can be set withsetDefault(javax.net.ssl.SSLContext). If not, one will be created withSSLContext.getInstance("Default"), which will already be initialized.- Throws:
NoSuchAlgorithmException- if there is a problem creating the default instance.- Since:
- 1.6
-
setDefault
Sets the default SSLContext instance as returned bygetDefault()to a non-null initialized value.- Throws:
NullPointerException- on a null argument- Since:
- 1.6
-
getInstance
Creates a newSSLContextinstance for the specified protocol.- Parameters:
protocol- the requested protocol to create a context for.- Returns:
- the created
SSLContextinstance. - Throws:
NoSuchAlgorithmException- if no installed provider can provide the requested protocolNullPointerException- ifprotocolisnull(instead of NoSuchAlgorithmException as in 1.4 release)
-
getInstance
public static SSLContext getInstance(String protocol, String provider) throws NoSuchAlgorithmException, NoSuchProviderExceptionCreates a newSSLContextinstance 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
SSLContextfor the requested protocol. - Throws:
NoSuchAlgorithmException- if the specified provider cannot provider the requested protocol.NoSuchProviderException- if the specified provider does not exits.NullPointerException- ifprotocolisnull(instead of NoSuchAlgorithmException as in 1.4 release)
-
getInstance
public static SSLContext getInstance(String protocol, Provider provider) throws NoSuchAlgorithmExceptionCreates a newSSLContextinstance for the specified protocol from the specified provider.- Parameters:
protocol- the requested protocol to create a context forprovider- the provider that provides the requested protocol.- Returns:
- an
SSLContextfor the requested protocol. - Throws:
NoSuchAlgorithmException- if the specified provider cannot provide the requested protocol.NullPointerException- ifprotocolisnull(instead of NoSuchAlgorithmException as in 1.4 release)
-
getProtocol
Returns the name of the secure socket protocol of this instance.- Returns:
- the name of the secure socket protocol of this instance.
-
getProvider
Returns the provider of thisSSLContextinstance.- Returns:
- the provider of this
SSLContextinstance.
-
init
public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom sr) throws KeyManagementExceptionInitializes thisSSLContextinstance. 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 ornull.tm- the trust decision sources ornull.sr- the randomness source ornull.- Throws:
KeyManagementException- if initializing this instance fails.
-
getSocketFactory
Returns a socket factory for this instance.- Returns:
- a socket factory for this instance.
-
getServerSocketFactory
Returns a server socket factory for this instance.- Returns:
- a server socket factory for this instance.
-
createSSLEngine
Creates anSSLEngineinstance from this context.- Returns:
- an
SSLEngineinstance from this context. - Throws:
UnsupportedOperationException- if the provider does not support the operation.
-
createSSLEngine
Creates anSSLEngineinstance from this context with the specified hostname and port.- Parameters:
peerHost- the name of the hostpeerPort- the port- Returns:
- an
SSLEngineinstance from this context. - Throws:
UnsupportedOperationException- if the provider does not support the operation.
-
getServerSessionContext
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
nullif the underlying provider does not provide an implementation of theSSLSessionContextinterface.
-
getClientSessionContext
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
nullif the underlying provider does not provide an implementation of theSSLSessionContextinterface.
-
getDefaultSSLParameters
Returns the default SSL handshake parameters for SSLSockets created by this SSLContext.- Throws:
UnsupportedOperationException- Since:
- 1.6
-
getSupportedSSLParameters
Returns SSL handshake parameters for SSLSockets that includes all supported cipher suites and protocols.- Throws:
UnsupportedOperationException- Since:
- 1.6
-