SSLEngines. 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 SummaryConstructorsModifierConstructorDescriptionprotectedSSLContext(SSLContextSpi contextSpi, Provider provider, String protocol) Creates an SSLContext object.
- 
Method SummaryModifier and TypeMethodDescriptionfinal SSLEngineCreates a newSSLEngineusing this context.final SSLEnginecreateSSLEngine(String peerHost, int peerPort) Creates a newSSLEngineusing this context using advisory peer information.final SSLSessionContextReturns the client session context, which represents the set of SSL sessions available for use during the handshake phase of client-side SSL sockets.static SSLContextReturns the default SSL context.final SSLParametersReturns a copy of the SSLParameters indicating the default settings for this SSL context.static SSLContextgetInstance(String protocol) Returns aSSLContextobject that implements the specified secure socket protocol.static SSLContextgetInstance(String protocol, String provider) Returns aSSLContextobject that implements the specified secure socket protocol.static SSLContextgetInstance(String protocol, Provider provider) Returns aSSLContextobject that implements the specified secure socket protocol.final StringReturns the protocol name of thisSSLContextobject.final ProviderReturns the provider of thisSSLContextobject.final SSLSessionContextReturns the server session context, which represents the set of SSL sessions available for use during the handshake phase of server-side SSL sockets.final SSLServerSocketFactoryReturns aServerSocketFactoryobject for this context.final SSLSocketFactoryReturns aSocketFactoryobject for this context.final SSLParametersReturns a copy of the SSLParameters indicating the supported settings for this SSL context.final voidinit(KeyManager[] km, TrustManager[] tm, SecureRandom random) Initializes this context.static voidsetDefault(SSLContext context) Sets the default SSL context.
- 
Constructor Details- 
SSLContextCreates an SSLContext object.- Parameters:
- contextSpi- the delegate
- provider- the provider
- protocol- the protocol
 
 
- 
- 
Method Details- 
getDefaultReturns 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 the- SSLContext.getInstance()call fails
- Since:
- 1.6
 
- 
setDefaultSets 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 null
- SecurityException- if a security manager exists and its- checkPermissionmethod does not allow- SSLPermission("setDefaultSSLContext")
- Since:
- 1.6
 
- 
getInstanceReturns aSSLContextobject 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.preferredSecurityproperty to determine the preferred provider order for the specified algorithm. This may be different than 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 SSLContextobject
- Throws:
- NoSuchAlgorithmException- if no- Providersupports a- SSLContextSpiimplementation for the specified protocol
- NullPointerException- if- protocolis- null
- See Also:
 
- 
getInstancepublic static SSLContext getInstance(String protocol, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns aSSLContextobject 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 SSLContextobject
- Throws:
- IllegalArgumentException- if the provider name is- nullor empty
- NoSuchAlgorithmException- if a- SSLContextSpiimplementation for the specified protocol is not available from the specified provider
- NoSuchProviderException- if the specified provider is not registered in the security provider list
- NullPointerException- if- protocolis- null
- See Also:
 
- 
getInstancepublic static SSLContext getInstance(String protocol, Provider provider) throws NoSuchAlgorithmException Returns aSSLContextobject 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 SSLContextobject
- Throws:
- IllegalArgumentException- if the provider is- null
- NoSuchAlgorithmException- if a- SSLContextSpiimplementation for the specified protocol is not available from the specified- Providerobject
- NullPointerException- if- protocolis- null
- See Also:
 
- 
getProtocolReturns the protocol name of thisSSLContextobject.This is the same name that was specified in one of the getInstancecalls that created thisSSLContextobject.- Returns:
- the protocol name of this SSLContextobject.
 
- 
getProviderReturns the provider of thisSSLContextobject.- Returns:
- the provider of this SSLContextobject
 
- 
initpublic final void init(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws KeyManagementException Initializes this context. Either of the first two parameters may be null in which case the installed security providers will be searched for the highest priority implementation of the appropriate factory. Likewise, the secure random parameter may be null in which case the default implementation will be used.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.) - Parameters:
- km- the sources of authentication keys or null
- tm- the sources of peer authentication trust decisions or null
- random- the source of randomness for this generator or null
- Throws:
- KeyManagementException- if this operation fails
 
- 
getSocketFactoryReturns aSocketFactoryobject for this context.- Returns:
- the SocketFactoryobject
- Throws:
- UnsupportedOperationException- if the underlying provider does not implement the operation.
- IllegalStateException- if the SSLContextImpl requires initialization and the- init()has not been called
 
- 
getServerSocketFactoryReturns aServerSocketFactoryobject for this context.- Returns:
- the ServerSocketFactoryobject
- Throws:
- UnsupportedOperationException- if the underlying provider does not implement the operation.
- IllegalStateException- if the SSLContextImpl requires initialization and the- init()has not been called
 
- 
createSSLEngineCreates a newSSLEngineusing this context.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. - Implementation Note:
- It is provider-specific if the returned SSLEngine uses client or
 server mode by default for the (D)TLS connection. The JDK SunJSSE
 provider implementation uses server mode by default.  However, it
 is recommended to always set the desired mode explicitly by calling
 SSLEngine.setUseClientMode()before invoking other methods of the SSLEngine.
- Returns:
- the SSLEngineobject
- Throws:
- UnsupportedOperationException- if the underlying provider does not implement the operation.
- IllegalStateException- if the SSLContextImpl requires initialization and the- init()has not been called
- Since:
- 1.5
 
- 
createSSLEngineCreates a newSSLEngineusing this context using advisory peer information.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. - Implementation Note:
- It is provider-specific if the returned SSLEngine uses client or
 server mode by default for the (D)TLS connection. The JDK SunJSSE
 provider implementation uses server mode by default.  However, it
 is recommended to always set the desired mode explicitly by calling
 SSLEngine.setUseClientMode()before invoking other methods of the SSLEngine.
- Parameters:
- peerHost- the non-authoritative name of the host
- peerPort- the non-authoritative port
- Returns:
- the new SSLEngineobject
- Throws:
- UnsupportedOperationException- if the underlying provider does not implement the operation.
- IllegalStateException- if the SSLContextImpl requires initialization and the- init()has not been called
- Since:
- 1.5
 
- 
getServerSessionContextReturns the server session context, which represents the set of SSL sessions available for use during the handshake phase of server-side SSL sockets.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. - Returns:
- server session context bound to this SSL context
 
- 
getClientSessionContextReturns the client session context, which represents the set of SSL sessions available for use during the handshake phase of client-side SSL sockets.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. - Returns:
- client session context bound to this SSL context
 
- 
getDefaultSSLParametersReturns 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
 
- 
getSupportedSSLParametersReturns 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
 
 
-