SSLEngine
s. This class is initialized
with an optional set of key and trust managers and source of
secure random bytes.
Every implementation of the Java platform is required to support the
following standard SSLContext
protocol:
TLSv1.2
- Since:
- 1.4
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SSLContext
(SSLContextSpi contextSpi, Provider provider, String protocol) Creates an SSLContext object. -
Method Summary
Modifier and TypeMethodDescriptionfinal SSLEngine
Creates a newSSLEngine
using this context.final SSLEngine
createSSLEngine
(String peerHost, int peerPort) Creates a newSSLEngine
using this context using advisory peer information.final SSLSessionContext
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
Returns the default SSL context.final SSLParameters
Returns a copy of the SSLParameters indicating the default settings for this SSL context.static SSLContext
getInstance
(String protocol) Returns aSSLContext
object that implements the specified secure socket protocol.static SSLContext
getInstance
(String protocol, String provider) Returns aSSLContext
object that implements the specified secure socket protocol.static SSLContext
getInstance
(String protocol, Provider provider) Returns aSSLContext
object that implements the specified secure socket protocol.final String
Returns the protocol name of thisSSLContext
object.final Provider
Returns the provider of thisSSLContext
object.final SSLSessionContext
Returns the server session context, which represents the set of SSL sessions available for use during the handshake phase of server-side SSL sockets.final SSLServerSocketFactory
Returns aServerSocketFactory
object for this context.final SSLSocketFactory
Returns aSocketFactory
object for this context.final SSLParameters
Returns a copy of the SSLParameters indicating the supported settings for this SSL context.final void
init
(KeyManager[] km, TrustManager[] tm, SecureRandom random) Initializes this context.static void
setDefault
(SSLContext context) Sets the default SSL context.
-
Constructor Details
-
SSLContext
Creates an SSLContext object.- Parameters:
contextSpi
- the delegateprovider
- the providerprotocol
- the protocol
-
-
Method Details
-
getDefault
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 callSSLContext.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 theSSLContext.getInstance()
call fails- Since:
- 1.6
-
setDefault
Sets the default SSL context. It will be returned by subsequent calls togetDefault()
. The default context must be immediately usable and not require initialization.- Parameters:
context
- the SSLContext- Throws:
NullPointerException
- if context is nullSecurityException
- if a security manager exists and itscheckPermission
method does not allowSSLPermission("setDefaultSSLContext")
- Since:
- 1.6
-
getInstance
Returns aSSLContext
object that implements the specified secure socket protocol.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.
Note that the list of registered providers may be retrieved via the
Security.getProviders()
method.- Implementation Note:
- The JDK Reference Implementation additionally uses the
jdk.security.provider.preferred
Security
property to determine the preferred provider order for the specified algorithm. This may be different from the order of providers returned bySecurity.getProviders()
. - Parameters:
protocol
- the standard name of the requested protocol. See the SSLContext section in the Java Security Standard Algorithm Names Specification for information about standard protocol names.- Returns:
- the new
SSLContext
object - Throws:
NoSuchAlgorithmException
- if noProvider
supports aSSLContextSpi
implementation for the specified protocolNullPointerException
- ifprotocol
isnull
- See Also:
-
getInstance
public static SSLContext getInstance(String protocol, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns aSSLContext
object that implements the specified secure socket 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.- Parameters:
protocol
- the standard name of the requested protocol. See the SSLContext section in the Java Security Standard Algorithm Names Specification for information about standard protocol names.provider
- the name of the provider.- Returns:
- the new
SSLContext
object - Throws:
IllegalArgumentException
- if the provider name isnull
or emptyNoSuchAlgorithmException
- if aSSLContextSpi
implementation for the specified protocol is not available from the specified providerNoSuchProviderException
- if the specified provider is not registered in the security provider listNullPointerException
- ifprotocol
isnull
- See Also:
-
getInstance
public static SSLContext getInstance(String protocol, Provider provider) throws NoSuchAlgorithmException Returns aSSLContext
object that implements the specified secure socket 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.
- Parameters:
protocol
- the standard name of the requested protocol. See the SSLContext section in the Java Security Standard Algorithm Names Specification for information about standard protocol names.provider
- an instance of the provider.- Returns:
- the new
SSLContext
object - Throws:
-