jdk/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java
author smarks
Fri, 14 Jan 2011 15:31:45 -0800
changeset 7990 57019dc81b66
parent 7043 5e2d1edeb2c7
child 9246 c459f79af46b
permissions -rw-r--r--
7012003: diamond conversion for ssl Reviewed-by: wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1580
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1580
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1580
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1580
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1580
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.Socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.ServerSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    34
import java.security.AlgorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    35
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.net.ServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.net.ssl.SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.net.ssl.SSLServerSocket;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    41
import javax.net.ssl.SSLParameters;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This class provides a simple way for servers to support conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * use of the Secure Sockets Layer (SSL).  Application code uses an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * SSLServerSocketImpl exactly like it uses a regular TCP ServerSocket; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * difference is that the connections established are secured using SSL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <P> Also, the constructors take an explicit authentication context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * parameter, giving flexibility with respect to how the server socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * authenticates itself.  That policy flexibility is not exposed through
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the standard SSLServerSocketFactory API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <P> System security defaults prevent server sockets from accepting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * connections if they the authentication context has not been given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * a certificate chain and its matching private key.  If the clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * of your application support "anonymous" cipher suites, you may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * able to configure a server socket to accept those suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see SSLSocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see SSLServerSocketFactoryImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
class SSLServerSocketImpl extends SSLServerSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private SSLContextImpl      sslContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /* Do newly accepted connections require clients to authenticate? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private byte                doClientAuth = SSLEngineImpl.clauth_none;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* Do new connections created here use the "server" mode of SSL? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private boolean             useServerMode = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /* Can new connections created establish new sessions? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private boolean             enableSessionCreation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /* what cipher suites to use by default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private CipherSuiteList     enabledCipherSuites = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /* which protocol to use by default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private ProtocolList        enabledProtocols = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /* could enabledCipherSuites ever complete handshaking? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private boolean             checkedEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    89
    // the endpoint identification protocol to use by default
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    90
    private String              identificationProtocol = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    91
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    92
    // The cryptographic algorithm constraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    93
    private AlgorithmConstraints    algorithmConstraints = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    94
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Create an SSL server socket on a port, using a non-default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * authentication context and a specified connection backlog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param port the port on which to listen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param backlog how many connections may be pending before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *          the system should start rejecting new requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param context authentication context for this server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    SSLServerSocketImpl(int port, int backlog, SSLContextImpl context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    throws IOException, SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        super(port, backlog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        initServer(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Create an SSL server socket on a port, using a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * authentication context and a specified backlog of connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * as well as a particular specified network interface.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * constructor is used on multihomed hosts, such as those used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * for firewalls or as routers, to control through which interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * a network service is provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param port the port on which to listen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param backlog how many connections may be pending before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *          the system should start rejecting new requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param address the address of the network interface through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *          which connections will be accepted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param context authentication context for this server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    SSLServerSocketImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int             port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int             backlog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        InetAddress     address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        SSLContextImpl  context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        super(port, backlog, address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        initServer(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Creates an unbound server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    SSLServerSocketImpl(SSLContextImpl context) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        initServer(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Initializes the server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private void initServer(SSLContextImpl context) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new SSLException("No Authentication context given");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        sslContext = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        enabledCipherSuites = CipherSuiteList.getDefault();
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   157
        enabledProtocols = ProtocolList.getDefault(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the names of the cipher suites which could be enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * on an SSL connection.  Normally, only a subset of these will actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * be enabled by default, since this list may include cipher suites which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * do not support the mutual authentication of servers and clients, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * which do not protect data confidentiality.  Servers may also need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * certain kinds of certificates to use certain cipher suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return an array of cipher suite names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public String[] getSupportedCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        CipherSuiteList.clearAvailableCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return CipherSuiteList.getSupported().toStringArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns the list of cipher suites which are currently enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * for use by newly accepted connections.  A null return indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * that the system defaults are in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    synchronized public String[] getEnabledCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return enabledCipherSuites.toStringArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Controls which particular SSL cipher suites are enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * by accepted connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param suites Names of all the cipher suites to enable; null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *  means to accept system defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    synchronized public void setEnabledCipherSuites(String[] suites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        enabledCipherSuites = new CipherSuiteList(suites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        checkedEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public String[] getSupportedProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return ProtocolList.getSupported().toStringArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Controls which protocols are enabled for use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * The protocols must have been listed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * getSupportedProtocols() as being supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param protocols protocols to enable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @exception IllegalArgumentException when one of the protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *  named by the parameter is not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    synchronized public void setEnabledProtocols(String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        enabledProtocols = new ProtocolList(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    synchronized public String[] getEnabledProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return enabledProtocols.toStringArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Controls whether the connections which are accepted must include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void setNeedClientAuth(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        doClientAuth = (flag ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            SSLEngineImpl.clauth_required : SSLEngineImpl.clauth_none);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return (doClientAuth == SSLEngineImpl.clauth_required);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Controls whether the connections which are accepted should request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void setWantClientAuth(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        doClientAuth = (flag ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            SSLEngineImpl.clauth_requested : SSLEngineImpl.clauth_none);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return (doClientAuth == SSLEngineImpl.clauth_requested);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Makes the returned sockets act in SSL "client" mode, not the usual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * server mode.  The canonical example of why this is needed is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * FTP clients, which accept connections from servers and should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * rejoining the already-negotiated SSL connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public void setUseClientMode(boolean flag) {
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   250
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   251
         * If we need to change the socket mode and the enabled
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   252
         * protocols haven't specifically been set by the user,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   253
         * change them to the corresponding default ones.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   254
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   255
        if (useServerMode != (!flag) &&
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   256
                ProtocolList.isDefaultProtocolList(enabledProtocols)) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   257
            enabledProtocols = ProtocolList.getDefault(!flag);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   258
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   259
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        useServerMode = !flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public boolean getUseClientMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return !useServerMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Controls whether new connections may cause creation of new SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void setEnableSessionCreation(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        enableSessionCreation = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Returns true if new connections may cause creation of new SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public boolean getEnableSessionCreation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return enableSessionCreation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   285
     * Returns the SSLParameters in effect for newly accepted connections.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   286
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   287
    synchronized public SSLParameters getSSLParameters() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   288
        SSLParameters params = super.getSSLParameters();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   289
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   290
        // the super implementation does not handle the following parameters
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   291
        params.setEndpointIdentificationAlgorithm(identificationProtocol);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   292
        params.setAlgorithmConstraints(algorithmConstraints);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   293
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   294
        return params;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   295
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   296
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   297
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   298
     * Applies SSLParameters to newly accepted connections.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   299
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   300
    synchronized public void setSSLParameters(SSLParameters params) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   301
        super.setSSLParameters(params);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   302
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   303
        // the super implementation does not handle the following parameters
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   304
        identificationProtocol = params.getEndpointIdentificationAlgorithm();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   305
        algorithmConstraints = params.getAlgorithmConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   306
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   307
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   308
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Accept a new SSL connection.  This server identifies itself with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * information provided in the authentication context which was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * presented during construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public Socket accept() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        SSLSocketImpl s = new SSLSocketImpl(sslContext, useServerMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            enabledCipherSuites, doClientAuth, enableSessionCreation,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   316
            enabledProtocols, identificationProtocol, algorithmConstraints);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        implAccept(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        s.doneConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Provides a brief description of this SSL socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return "[SSL: "+ super.toString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}