Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/net/ssl/SSLContext.java
38922 views
/*1* Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* NOTE: this file was copied from javax.net.ssl.SSLContext27*/2829package com.sun.net.ssl;3031import java.security.*;32import java.util.*;33import javax.net.ssl.*;3435import sun.security.ssl.SSLSocketFactoryImpl;36import sun.security.ssl.SSLServerSocketFactoryImpl;3738/**39* Instances of this class represent a secure socket protocol40* implementation which acts as a factory for secure socket41* factories. This class is initialized with an optional set of42* key and trust managers and source of secure random bytes.43*44* @deprecated As of JDK 1.4, this implementation-specific class was45* replaced by {@link javax.net.ssl.SSLContext}.46*/47@Deprecated48public class SSLContext {49private Provider provider;5051private SSLContextSpi contextSpi;5253private String protocol;5455/**56* Creates an SSLContext object.57*58* @param contextSpi the delegate59* @param provider the provider60* @param algorithm the algorithm61*/62protected SSLContext(SSLContextSpi contextSpi, Provider provider,63String protocol) {64this.contextSpi = contextSpi;65this.provider = provider;66this.protocol = protocol;67}6869/**70* Generates a <code>SSLContext</code> object that implements the71* specified secure socket protocol.72*73* @param protocol the standard name of the requested protocol.74*75* @return the new <code>SSLContext</code> object76*77* @exception NoSuchAlgorithmException if the specified protocol is not78* available in the default provider package or any of the other provider79* packages that were searched.80*/81public static SSLContext getInstance(String protocol)82throws NoSuchAlgorithmException83{84try {85Object[] objs = SSLSecurity.getImpl(protocol, "SSLContext",86(String) null);87return new SSLContext((SSLContextSpi)objs[0], (Provider)objs[1],88protocol);89} catch (NoSuchProviderException e) {90throw new NoSuchAlgorithmException(protocol + " not found");91}92}9394/**95* Generates a <code>SSLContext</code> object that implements the96* specified secure socket protocol.97*98* @param protocol the standard name of the requested protocol.99* @param provider the name of the provider100*101* @return the new <code>SSLContext</code> object102*103* @exception NoSuchAlgorithmException if the specified protocol is not104* available from the specified provider.105* @exception NoSuchProviderException if the specified provider has not106* been configured.107*/108public static SSLContext getInstance(String protocol, String provider)109throws NoSuchAlgorithmException, NoSuchProviderException110{111if (provider == null || provider.length() == 0)112throw new IllegalArgumentException("missing provider");113Object[] objs = SSLSecurity.getImpl(protocol, "SSLContext",114provider);115return new SSLContext((SSLContextSpi)objs[0], (Provider)objs[1],116protocol);117}118119/**120* Generates a <code>SSLContext</code> object that implements the121* specified secure socket protocol.122*123* @param protocol the standard name of the requested protocol.124* @param provider an instance of the provider125*126* @return the new <code>SSLContext</code> object127*128* @exception NoSuchAlgorithmException if the specified protocol is not129* available from the specified provider.130*/131public static SSLContext getInstance(String protocol, Provider provider)132throws NoSuchAlgorithmException133{134if (provider == null)135throw new IllegalArgumentException("missing provider");136Object[] objs = SSLSecurity.getImpl(protocol, "SSLContext",137provider);138return new SSLContext((SSLContextSpi)objs[0], (Provider)objs[1],139protocol);140}141142/**143* Returns the protocol name of this <code>SSLContext</code> object.144*145* <p>This is the same name that was specified in one of the146* <code>getInstance</code> calls that created this147* <code>SSLContext</code> object.148*149* @return the protocol name of this <code>SSLContext</code> object.150*/151public final String getProtocol() {152return this.protocol;153}154155/**156* Returns the provider of this <code>SSLContext</code> object.157*158* @return the provider of this <code>SSLContext</code> object159*/160public final Provider getProvider() {161return this.provider;162}163164/**165* Initializes this context. Either of the first two parameters166* may be null in which case the installed security providers will167* be searched for the highest priority implementation of the168* appropriate factory. Likewise, the secure random parameter may169* be null in which case the default implementation will be used.170*171* @param km the sources of authentication keys or null172* @param tm the sources of peer authentication trust decisions or null173* @param random the source of randomness for this generator or null174*/175public final void init(KeyManager[] km, TrustManager[] tm,176SecureRandom random)177throws KeyManagementException {178contextSpi.engineInit(km, tm, random);179}180181/**182* Returns a <code>SocketFactory</code> object for this183* context.184*185* @return the factory186*/187public final SSLSocketFactory getSocketFactory() {188return contextSpi.engineGetSocketFactory();189}190191/**192* Returns a <code>ServerSocketFactory</code> object for193* this context.194*195* @return the factory196*/197public final SSLServerSocketFactory getServerSocketFactory() {198return contextSpi.engineGetServerSocketFactory();199}200}201202203