src/java.base/share/classes/javax/net/ssl/SSLContext.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 30,45 ****
import sun.security.jca.GetInstance;
/**
* Instances of this class represent a secure socket protocol
* implementation which acts as a factory for secure socket
! * factories or <code>SSLEngine</code>s. This class is initialized
* with an optional set of key and trust managers and source of
* secure random bytes.
*
* <p> Every implementation of the Java platform is required to support the
! * following standard <code>SSLContext</code> protocol:
* <ul>
* <li><tt>TLSv1</tt></li>
* </ul>
* This protocol is described in the <a href=
* "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
--- 30,45 ----
import sun.security.jca.GetInstance;
/**
* Instances of this class represent a secure socket protocol
* implementation which acts as a factory for secure socket
! * factories or {@code SSLEngine}s. This class is initialized
* with an optional set of key and trust managers and source of
* secure random bytes.
*
* <p> Every implementation of the Java platform is required to support the
! * following standard {@code SSLContext} protocol:
* <ul>
* <li><tt>TLSv1</tt></li>
* </ul>
* This protocol is described in the <a href=
* "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
*** 77,87 ****
* Returns the default SSL context.
*
* <p>If a default context was set using the {@link #setDefault
* SSLContext.setDefault()} method, it is returned. Otherwise, the first
* call of this method triggers the call
! * <code>SSLContext.getInstance("Default")</code>.
* If successful, that object is made the default SSL context and returned.
*
* <p>The default context is immediately
* usable and does not require {@linkplain #init initialization}.
*
--- 77,87 ----
* Returns the default SSL context.
*
* <p>If a default context was set using the {@link #setDefault
* SSLContext.setDefault()} method, it is returned. Otherwise, the first
* call of this method triggers the call
! * {@code SSLContext.getInstance("Default")}.
* If successful, that object is made the default SSL context and returned.
*
* <p>The default context is immediately
* usable and does not require {@linkplain #init initialization}.
*
*** 104,115 ****
* and not require {@linkplain #init initialization}.
*
* @param context the SSLContext
* @throws NullPointerException if context is null
* @throws SecurityException if a security manager exists and its
! * <code>checkPermission</code> method does not allow
! * <code>SSLPermission("setDefaultSSLContext")</code>
* @since 1.6
*/
public static synchronized void setDefault(SSLContext context) {
if (context == null) {
throw new NullPointerException();
--- 104,115 ----
* and not require {@linkplain #init initialization}.
*
* @param context the SSLContext
* @throws NullPointerException if context is null
* @throws SecurityException if a security manager exists and its
! * {@code checkPermission} method does not allow
! * {@code SSLPermission("setDefaultSSLContext")}
* @since 1.6
*/
public static synchronized void setDefault(SSLContext context) {
if (context == null) {
throw new NullPointerException();
*** 120,130 ****
}
defaultContext = context;
}
/**
! * Returns a <code>SSLContext</code> object that implements the
* specified secure socket protocol.
*
* <p> This method traverses the list of registered security Providers,
* starting with the most preferred Provider.
* A new SSLContext object encapsulating the
--- 120,130 ----
}
defaultContext = context;
}
/**
! * Returns a {@code SSLContext} object that implements the
* specified secure socket protocol.
*
* <p> This method traverses the list of registered security Providers,
* starting with the most preferred Provider.
* A new SSLContext object encapsulating the
*** 139,149 ****
* "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
* Java Cryptography Architecture Standard Algorithm Name
* Documentation</a>
* for information about standard protocol names.
*
! * @return the new <code>SSLContext</code> object.
*
* @exception NoSuchAlgorithmException if no Provider supports a
* SSLContextSpi implementation for the
* specified protocol.
* @exception NullPointerException if protocol is null.
--- 139,149 ----
* "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
* Java Cryptography Architecture Standard Algorithm Name
* Documentation</a>
* for information about standard protocol names.
*
! * @return the new {@code SSLContext} object.
*
* @exception NoSuchAlgorithmException if no Provider supports a
* SSLContextSpi implementation for the
* specified protocol.
* @exception NullPointerException if protocol is null.
*** 157,167 ****
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns a <code>SSLContext</code> object that implements the
* specified secure socket protocol.
*
* <p> A new SSLContext object encapsulating the
* SSLContextSpi implementation from the specified provider
* is returned. The specified provider must be registered
--- 157,167 ----
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns a {@code SSLContext} object that implements the
* specified secure socket protocol.
*
* <p> A new SSLContext object encapsulating the
* SSLContextSpi implementation from the specified provider
* is returned. The specified provider must be registered
*** 177,187 ****
* Documentation</a>
* for information about standard protocol names.
*
* @param provider the name of the provider.
*
! * @return the new <code>SSLContext</code> object.
*
* @throws NoSuchAlgorithmException if a SSLContextSpi
* implementation for the specified protocol is not
* available from the specified provider.
*
--- 177,187 ----
* Documentation</a>
* for information about standard protocol names.
*
* @param provider the name of the provider.
*
! * @return the new {@code SSLContext} object.
*
* @throws NoSuchAlgorithmException if a SSLContextSpi
* implementation for the specified protocol is not
* available from the specified provider.
*
*** 200,210 ****
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns a <code>SSLContext</code> object that implements the
* specified secure socket protocol.
*
* <p> A new SSLContext object encapsulating the
* SSLContextSpi implementation from the specified Provider
* object is returned. Note that the specified Provider object
--- 200,210 ----
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns a {@code SSLContext} object that implements the
* specified secure socket protocol.
*
* <p> A new SSLContext object encapsulating the
* SSLContextSpi implementation from the specified Provider
* object is returned. Note that the specified Provider object
*** 217,227 ****
* Documentation</a>
* for information about standard protocol names.
*
* @param provider an instance of the provider.
*
! * @return the new <code>SSLContext</code> object.
*
* @throws NoSuchAlgorithmException if a SSLContextSpi
* implementation for the specified protocol is not available
* from the specified Provider object.
*
--- 217,227 ----
* Documentation</a>
* for information about standard protocol names.
*
* @param provider an instance of the provider.
*
! * @return the new {@code SSLContext} object.
*
* @throws NoSuchAlgorithmException if a SSLContextSpi
* implementation for the specified protocol is not available
* from the specified Provider object.
*
*** 237,262 ****
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns the protocol name of this <code>SSLContext</code> object.
*
* <p>This is the same name that was specified in one of the
! * <code>getInstance</code> calls that created this
! * <code>SSLContext</code> object.
*
! * @return the protocol name of this <code>SSLContext</code> object.
*/
public final String getProtocol() {
return this.protocol;
}
/**
! * Returns the provider of this <code>SSLContext</code> object.
*
! * @return the provider of this <code>SSLContext</code> object
*/
public final Provider getProvider() {
return this.provider;
}
--- 237,262 ----
return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
protocol);
}
/**
! * Returns the protocol name of this {@code SSLContext} object.
*
* <p>This is the same name that was specified in one of the
! * {@code getInstance} calls that created this
! * {@code SSLContext} object.
*
! * @return the protocol name of this {@code SSLContext} object.
*/
public final String getProtocol() {
return this.protocol;
}
/**
! * Returns the provider of this {@code SSLContext} object.
*
! * @return the provider of this {@code SSLContext} object
*/
public final Provider getProvider() {
return this.provider;
}
*** 281,329 ****
throws KeyManagementException {
contextSpi.engineInit(km, tm, random);
}
/**
! * Returns a <code>SocketFactory</code> object for this
* context.
*
! * @return the <code>SocketFactory</code> object
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the <code>init()</code> has not been called
*/
public final SSLSocketFactory getSocketFactory() {
return contextSpi.engineGetSocketFactory();
}
/**
! * Returns a <code>ServerSocketFactory</code> object for
* this context.
*
! * @return the <code>ServerSocketFactory</code> object
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the <code>init()</code> has not been called
*/
public final SSLServerSocketFactory getServerSocketFactory() {
return contextSpi.engineGetServerSocketFactory();
}
/**
! * Creates a new <code>SSLEngine</code> using this context.
* <P>
* Applications using this factory method are providing no hints
* for an internal session reuse strategy. If hints are desired,
* {@link #createSSLEngine(String, int)} should be used
* instead.
* <P>
* Some cipher suites (such as Kerberos) require remote hostname
* information, in which case this factory method should not be used.
*
! * @return the <code>SSLEngine</code> object
* @throws UnsupportedOperationException if the underlying provider
* does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the <code>init()</code> has not been called
* @since 1.5
*/
public final SSLEngine createSSLEngine() {
try {
return contextSpi.engineCreateSSLEngine();
--- 281,333 ----
throws KeyManagementException {
contextSpi.engineInit(km, tm, random);
}
/**
! * Returns a {@code SocketFactory} object for this
* context.
*
! * @return the {@code SocketFactory} object
! * @throws UnsupportedOperationException if the underlying provider
! * does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the {@code init()} has not been called
*/
public final SSLSocketFactory getSocketFactory() {
return contextSpi.engineGetSocketFactory();
}
/**
! * Returns a {@code ServerSocketFactory} object for
* this context.
*
! * @return the {@code ServerSocketFactory} object
! * @throws UnsupportedOperationException if the underlying provider
! * does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the {@code init()} has not been called
*/
public final SSLServerSocketFactory getServerSocketFactory() {
return contextSpi.engineGetServerSocketFactory();
}
/**
! * Creates a new {@code SSLEngine} using this context.
* <P>
* Applications using this factory method are providing no hints
* for an internal session reuse strategy. If hints are desired,
* {@link #createSSLEngine(String, int)} should be used
* instead.
* <P>
* Some cipher suites (such as Kerberos) require remote hostname
* information, in which case this factory method should not be used.
*
! * @return the {@code SSLEngine} object
* @throws UnsupportedOperationException if the underlying provider
* does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the {@code init()} has not been called
* @since 1.5
*/
public final SSLEngine createSSLEngine() {
try {
return contextSpi.engineCreateSSLEngine();
*** 336,346 ****
throw unsup;
}
}
/**
! * Creates a new <code>SSLEngine</code> using this context using
* advisory peer information.
* <P>
* Applications using this factory method are providing hints
* for an internal session reuse strategy.
* <P>
--- 340,350 ----
throw unsup;
}
}
/**
! * Creates a new {@code SSLEngine} using this context using
* advisory peer information.
* <P>
* Applications using this factory method are providing hints
* for an internal session reuse strategy.
* <P>
*** 347,361 ****
* Some cipher suites (such as Kerberos) require remote hostname
* information, in which case peerHost needs to be specified.
*
* @param peerHost the non-authoritative name of the host
* @param peerPort the non-authoritative port
! * @return the new <code>SSLEngine</code> object
* @throws UnsupportedOperationException if the underlying provider
* does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the <code>init()</code> has not been called
* @since 1.5
*/
public final SSLEngine createSSLEngine(String peerHost, int peerPort) {
try {
return contextSpi.engineCreateSSLEngine(peerHost, peerPort);
--- 351,365 ----
* Some cipher suites (such as Kerberos) require remote hostname
* information, in which case peerHost needs to be specified.
*
* @param peerHost the non-authoritative name of the host
* @param peerPort the non-authoritative port
! * @return the new {@code SSLEngine} object
* @throws UnsupportedOperationException if the underlying provider
* does not implement the operation.
* @throws IllegalStateException if the SSLContextImpl requires
! * initialization and the {@code init()} has not been called
* @since 1.5
*/
public final SSLEngine createSSLEngine(String peerHost, int peerPort) {
try {
return contextSpi.engineCreateSSLEngine(peerHost, peerPort);