Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/net/ssl/SSLServerSocketFactory.java
38918 views
/*1* Copyright (c) 1997, 2012, 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*/242526package javax.net.ssl;2728import java.io.IOException;29import java.net.InetAddress;30import java.net.ServerSocket;31import java.net.SocketException;32import javax.net.ServerSocketFactory;33import java.security.*;3435/**36* <code>SSLServerSocketFactory</code>s create37* <code>SSLServerSocket</code>s.38*39* @since 1.440* @see SSLSocket41* @see SSLServerSocket42* @author David Brownell43*/44public abstract class SSLServerSocketFactory extends ServerSocketFactory45{46private static SSLServerSocketFactory theFactory;4748private static boolean propertyChecked;4950private static void log(String msg) {51if (SSLSocketFactory.DEBUG) {52System.out.println(msg);53}54}5556/**57* Constructor is used only by subclasses.58*/59protected SSLServerSocketFactory() { /* NOTHING */ }6061/**62* Returns the default SSL server socket factory.63*64* <p>The first time this method is called, the security property65* "ssl.ServerSocketFactory.provider" is examined. If it is non-null, a66* class by that name is loaded and instantiated. If that is successful and67* the object is an instance of SSLServerSocketFactory, it is made the68* default SSL server socket factory.69*70* <p>Otherwise, this method returns71* <code>SSLContext.getDefault().getServerSocketFactory()</code>. If that72* call fails, an inoperative factory is returned.73*74* @return the default <code>ServerSocketFactory</code>75* @see SSLContext#getDefault76*/77public static synchronized ServerSocketFactory getDefault() {78if (theFactory != null) {79return theFactory;80}8182if (propertyChecked == false) {83propertyChecked = true;84String clsName = SSLSocketFactory.getSecurityProperty85("ssl.ServerSocketFactory.provider");86if (clsName != null) {87log("setting up default SSLServerSocketFactory");88try {89Class<?> cls = null;90try {91cls = Class.forName(clsName);92} catch (ClassNotFoundException e) {93ClassLoader cl = ClassLoader.getSystemClassLoader();94if (cl != null) {95cls = cl.loadClass(clsName);96}97}98log("class " + clsName + " is loaded");99SSLServerSocketFactory fac = (SSLServerSocketFactory)cls.newInstance();100log("instantiated an instance of class " + clsName);101theFactory = fac;102return fac;103} catch (Exception e) {104log("SSLServerSocketFactory instantiation failed: " + e);105theFactory = new DefaultSSLServerSocketFactory(e);106return theFactory;107}108}109}110111try {112return SSLContext.getDefault().getServerSocketFactory();113} catch (NoSuchAlgorithmException e) {114return new DefaultSSLServerSocketFactory(e);115}116}117118/**119* Returns the list of cipher suites which are enabled by default.120* Unless a different list is enabled, handshaking on an SSL connection121* will use one of these cipher suites. The minimum quality of service122* for these defaults requires confidentiality protection and server123* authentication (that is, no anonymous cipher suites).124*125* @see #getSupportedCipherSuites()126* @return array of the cipher suites enabled by default127*/128public abstract String [] getDefaultCipherSuites();129130131/**132* Returns the names of the cipher suites which could be enabled for use133* on an SSL connection created by this factory.134* Normally, only a subset of these will actually135* be enabled by default, since this list may include cipher suites which136* do not meet quality of service requirements for those defaults. Such137* cipher suites are useful in specialized applications.138*139* @return an array of cipher suite names140* @see #getDefaultCipherSuites()141*/142public abstract String [] getSupportedCipherSuites();143}144145146//147// The default factory does NOTHING.148//149class DefaultSSLServerSocketFactory extends SSLServerSocketFactory {150151private final Exception reason;152153DefaultSSLServerSocketFactory(Exception reason) {154this.reason = reason;155}156157private ServerSocket throwException() throws SocketException {158throw (SocketException)159new SocketException(reason.toString()).initCause(reason);160}161162@Override163public ServerSocket createServerSocket() throws IOException {164return throwException();165}166167168@Override169public ServerSocket createServerSocket(int port)170throws IOException171{172return throwException();173}174175@Override176public ServerSocket createServerSocket(int port, int backlog)177throws IOException178{179return throwException();180}181182@Override183public ServerSocket184createServerSocket(int port, int backlog, InetAddress ifAddress)185throws IOException186{187return throwException();188}189190@Override191public String [] getDefaultCipherSuites() {192return new String[0];193}194195@Override196public String [] getSupportedCipherSuites() {197return new String[0];198}199}200201202