1 /*
   2  * Copyright (c) 1997, 2012, 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 
  32 import javax.net.ssl.SSLServerSocketFactory;
  33 
  34 /**
  35  * This class creates SSL server sockets.
  36  *
  37  * @author David Brownell
  38  */
  39 final
  40 public class SSLServerSocketFactoryImpl extends SSLServerSocketFactory
  41 {
  42     private static final int DEFAULT_BACKLOG = 50;
  43     private SSLContextImpl context;
  44 
  45 
  46     /**
  47      * Constructor used to instantiate the default factory. This method is
  48      * only called if the old "ssl.ServerSocketFactory.provider" property in the
  49      * java.security file is set.
  50      */
  51     public SSLServerSocketFactoryImpl() throws Exception {
  52         this.context = SSLContextImpl.DefaultSSLContext.getDefaultImpl();
  53     }
  54 
  55     /**
  56      * Called from SSLContextImpl's getSSLServerSocketFactory().
  57      */
  58     SSLServerSocketFactoryImpl (SSLContextImpl context)
  59     {
  60         this.context = context;
  61     }
  62 
  63     /**
  64      * Returns an unbound server socket.
  65      *
  66      * @return the unbound socket
  67      * @throws IOException if the socket cannot be created
  68      * @see java.net.Socket#bind(java.net.SocketAddress)
  69      */
  70     @Override
  71     public ServerSocket createServerSocket() throws IOException {
  72         return new SSLServerSocketImpl(context);
  73     }
  74 
  75     @Override
  76     public ServerSocket createServerSocket (int port)
  77     throws IOException
  78     {
  79         return new SSLServerSocketImpl (port, DEFAULT_BACKLOG, context);
  80     }
  81 
  82 
  83     @Override
  84     public ServerSocket createServerSocket (int port, int backlog)
  85     throws IOException
  86     {
  87         return new SSLServerSocketImpl (port, backlog, context);
  88     }
  89 
  90     @Override
  91     public ServerSocket
  92     createServerSocket (int port, int backlog, InetAddress ifAddress)
  93     throws IOException
  94     {
  95         return new SSLServerSocketImpl (port, backlog, ifAddress, context);
  96     }
  97 
  98     /**
  99      * Returns the subset of the supported cipher suites which are
 100      * enabled by default.  These cipher suites all provide a minimum
 101      * quality of service whereby the server authenticates itself
 102      * (preventing person-in-the-middle attacks) and where traffic
 103      * is encrypted to provide confidentiality.
 104      */
 105     @Override
 106     public String[] getDefaultCipherSuites() {
 107         return context.getDefaultCipherSuiteList(true).toStringArray();
 108     }
 109 
 110     /**
 111      * Returns the names of the cipher suites which could be enabled for use
 112      * on an SSL connection.  Normally, only a subset of these will actually
 113      * be enabled by default, since this list may include cipher suites which
 114      * do not support the mutual authentication of servers and clients, or
 115      * which do not protect data confidentiality.  Servers may also need
 116      * certain kinds of certificates to use certain cipher suites.
 117      *
 118      * @return an array of cipher suite names
 119      */
 120     @Override
 121     public String[] getSupportedCipherSuites() {
 122         return context.getSupportedCipherSuiteList().toStringArray();
 123     }
 124 
 125 }