1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.IOException;
  29 import java.net.InetAddress;
  30 import java.net.ServerSocket;
  31 import javax.net.ssl.SSLServerSocketFactory;
  32 
  33 /**
  34  * This class creates SSL server sockets.
  35  *
  36  * @author David Brownell
  37  */
  38 final public
  39         class SSLServerSocketFactoryImpl extends SSLServerSocketFactory {
  40     private static final int DEFAULT_BACKLOG = 50;
  41     private SSLContextImpl context;
  42 
  43 
  44     /**
  45      * Constructor used to instantiate the default factory. This method is
  46      * only called if the old "ssl.ServerSocketFactory.provider" property in the
  47      * java.security file is set.
  48      */
  49     public SSLServerSocketFactoryImpl() throws Exception {
  50         this.context = SSLContextImpl.DefaultSSLContext.getDefaultImpl();
  51     }
  52 
  53     /**
  54      * Called from SSLContextImpl's getSSLServerSocketFactory().
  55      */
  56     SSLServerSocketFactoryImpl(SSLContextImpl context) {
  57         this.context = context;
  58     }
  59 
  60     /**
  61      * Returns an unbound server socket.
  62      *
  63      * @return the unbound socket
  64      * @throws IOException if the socket cannot be created
  65      * @see java.net.Socket#bind(java.net.SocketAddress)
  66      */
  67     @Override
  68     public ServerSocket createServerSocket() throws IOException {
  69         return new SSLServerSocketImpl(context);
  70     }
  71 
  72     @Override
  73     public ServerSocket createServerSocket(
  74             int port) throws IOException {
  75         return new SSLServerSocketImpl (context, port, DEFAULT_BACKLOG);
  76     }
  77 
  78 
  79     @Override
  80     public ServerSocket createServerSocket (
  81             int port, int backlog) throws IOException {
  82         return new SSLServerSocketImpl (context, port, backlog);
  83     }
  84 
  85     @Override
  86     public ServerSocket
  87     createServerSocket (int port,
  88             int backlog, InetAddress ifAddress) throws IOException {
  89         return new SSLServerSocketImpl (context, port, backlog, ifAddress);
  90     }
  91 
  92     /**
  93      * Returns the subset of the supported cipher suites which are
  94      * enabled by default.  These cipher suites all provide a minimum
  95      * quality of service whereby the server authenticates itself
  96      * (preventing person-in-the-middle attacks) and where traffic
  97      * is encrypted to provide confidentiality.
  98      */
  99     @Override
 100     public String[] getDefaultCipherSuites() {
 101         return CipherSuite.namesOf(context.getDefaultCipherSuites(true));
 102     }
 103 
 104     /**
 105      * Returns the names of the cipher suites which could be enabled for use
 106      * on an SSL connection.  Normally, only a subset of these will actually
 107      * be enabled by default, since this list may include cipher suites which
 108      * do not support the mutual authentication of servers and clients, or
 109      * which do not protect data confidentiality.  Servers may also need
 110      * certain kinds of certificates to use certain cipher suites.
 111      *
 112      * @return an array of cipher suite names
 113      */
 114     @Override
 115     public String[] getSupportedCipherSuites() {
 116         return CipherSuite.namesOf(context.getSupportedCipherSuites());
 117     }
 118 }