jdk/src/java.base/share/classes/sun/security/ssl/SSLServerSocketImpl.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 38865 429c08bd6158
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38865
429c08bd6158 8158978: ALPN not working when values are set directly on a SSLServerSocket
wetmore
parents: 34380
diff changeset
     2
 * Copyright (c) 1996, 2016, 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
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    33
import java.security.AlgorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.net.ssl.SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.net.ssl.SSLServerSocket;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    39
import javax.net.ssl.SSLParameters;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
    40
import javax.net.ssl.SNIMatcher;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class provides a simple way for servers to support conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * use of the Secure Sockets Layer (SSL).  Application code uses an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * SSLServerSocketImpl exactly like it uses a regular TCP ServerSocket; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * difference is that the connections established are secured using SSL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <P> Also, the constructors take an explicit authentication context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * parameter, giving flexibility with respect to how the server socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * authenticates itself.  That policy flexibility is not exposed through
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the standard SSLServerSocketFactory API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <P> System security defaults prevent server sockets from accepting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * connections if they the authentication context has not been given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * a certificate chain and its matching private key.  If the clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * of your application support "anonymous" cipher suites, you may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * able to configure a server socket to accept those suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see SSLSocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see SSLServerSocketFactoryImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
class SSLServerSocketImpl extends SSLServerSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private SSLContextImpl      sslContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* Do newly accepted connections require clients to authenticate? */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    71
    private ClientAuthType    clientAuthType = ClientAuthType.CLIENT_AUTH_NONE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* Do new connections created here use the "server" mode of SSL? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private boolean             useServerMode = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* Can new connections created establish new sessions? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private boolean             enableSessionCreation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* what cipher suites to use by default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private CipherSuiteList     enabledCipherSuites = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* which protocol to use by default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private ProtocolList        enabledProtocols = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    85
    // the endpoint identification protocol to use by default
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    86
    private String              identificationProtocol = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    87
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    88
    // The cryptographic algorithm constraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    89
    private AlgorithmConstraints    algorithmConstraints = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    90
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
    91
    // The server name indication
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
    92
    Collection<SNIMatcher>      sniMatchers =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
    93
                                    Collections.<SNIMatcher>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
    94
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 32649
diff changeset
    95
    // Configured application protocol values
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 32649
diff changeset
    96
    String[] applicationProtocols = new String[0];
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 32649
diff changeset
    97
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
    98
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
    99
     * Whether local cipher suites preference in server side should be
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   100
     * honored during handshaking?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   101
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   102
    private boolean             preferLocalCipherSuites = false;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   103
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Create an SSL server socket on a port, using a non-default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * authentication context and a specified connection backlog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param port the port on which to listen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param backlog how many connections may be pending before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *          the system should start rejecting new requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param context authentication context for this server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    SSLServerSocketImpl(int port, int backlog, SSLContextImpl context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    throws IOException, SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super(port, backlog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        initServer(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Create an SSL server socket on a port, using a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * authentication context and a specified backlog of connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * as well as a particular specified network interface.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * constructor is used on multihomed hosts, such as those used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * for firewalls or as routers, to control through which interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * a network service is provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param port the port on which to listen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param backlog how many connections may be pending before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *          the system should start rejecting new requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param address the address of the network interface through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *          which connections will be accepted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param context authentication context for this server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    SSLServerSocketImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        int             port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        int             backlog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        InetAddress     address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        SSLContextImpl  context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        super(port, backlog, address);
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
     * Creates an unbound server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    SSLServerSocketImpl(SSLContextImpl context) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        initServer(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Initializes the server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private void initServer(SSLContextImpl context) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            throw new SSLException("No Authentication context given");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        sslContext = context;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   165
        enabledCipherSuites = sslContext.getDefaultCipherSuiteList(true);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   166
        enabledProtocols = sslContext.getDefaultProtocolList(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns the names of the cipher suites which could be enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * on an SSL connection.  Normally, only a subset of these will actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * be enabled by default, since this list may include cipher suites which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * do not support the mutual authentication of servers and clients, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * which do not protect data confidentiality.  Servers may also need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * certain kinds of certificates to use certain cipher suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @return an array of cipher suite names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   179
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public String[] getSupportedCipherSuites() {
13815
2de30ecf335e 7199066: Typo in method name
xuelei
parents: 9246
diff changeset
   181
        return sslContext.getSupportedCipherSuiteList().toStringArray();
2
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
     * Returns the list of cipher suites which are currently enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * for use by newly accepted connections.  A null return indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * that the system defaults are in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   189
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   190
    public synchronized String[] getEnabledCipherSuites() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return enabledCipherSuites.toStringArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Controls which particular SSL cipher suites are enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * by accepted connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param suites Names of all the cipher suites to enable; null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *  means to accept system defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   201
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   202
    public synchronized void setEnabledCipherSuites(String[] suites) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        enabledCipherSuites = new CipherSuiteList(suites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   206
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String[] getSupportedProtocols() {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   208
        return sslContext.getSuportedProtocolList().toStringArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Controls which protocols are enabled for use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The protocols must have been listed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * getSupportedProtocols() as being supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param protocols protocols to enable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @exception IllegalArgumentException when one of the protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *  named by the parameter is not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   220
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   221
    public synchronized void setEnabledProtocols(String[] protocols) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        enabledProtocols = new ProtocolList(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   225
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   226
    public synchronized String[] getEnabledProtocols() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return enabledProtocols.toStringArray();
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 must include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   234
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void setNeedClientAuth(boolean flag) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   236
        clientAuthType = (flag ? ClientAuthType.CLIENT_AUTH_REQUIRED :
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   237
                ClientAuthType.CLIENT_AUTH_NONE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   240
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean getNeedClientAuth() {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   242
        return (clientAuthType == ClientAuthType.CLIENT_AUTH_REQUIRED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Controls whether the connections which are accepted should request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   249
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public void setWantClientAuth(boolean flag) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   251
        clientAuthType = (flag ? ClientAuthType.CLIENT_AUTH_REQUESTED :
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   252
                ClientAuthType.CLIENT_AUTH_NONE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   255
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public boolean getWantClientAuth() {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   257
        return (clientAuthType == ClientAuthType.CLIENT_AUTH_REQUESTED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Makes the returned sockets act in SSL "client" mode, not the usual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * server mode.  The canonical example of why this is needed is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * FTP clients, which accept connections from servers and should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * rejoining the already-negotiated SSL connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   266
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void setUseClientMode(boolean flag) {
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   268
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   269
         * If we need to change the socket mode and the enabled
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   270
         * protocols haven't specifically been set by the user,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   271
         * change them to the corresponding default ones.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   272
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   273
        if (useServerMode != (!flag) &&
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   274
                sslContext.isDefaultProtocolList(enabledProtocols)) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   275
            enabledProtocols = sslContext.getDefaultProtocolList(!flag);
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   276
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   277
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        useServerMode = !flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   281
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public boolean getUseClientMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return !useServerMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Controls whether new connections may cause creation of new SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   291
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void setEnableSessionCreation(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        enableSessionCreation = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns true if new connections may cause creation of new SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   300
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean getEnableSessionCreation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return enableSessionCreation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   306
     * Returns the SSLParameters in effect for newly accepted connections.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   307
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   308
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   309
    public synchronized SSLParameters getSSLParameters() {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   310
        SSLParameters params = super.getSSLParameters();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   311
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   312
        // the super implementation does not handle the following parameters
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   313
        params.setEndpointIdentificationAlgorithm(identificationProtocol);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   314
        params.setAlgorithmConstraints(algorithmConstraints);
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   315
        params.setSNIMatchers(sniMatchers);
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   316
        params.setUseCipherSuitesOrder(preferLocalCipherSuites);
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 32649
diff changeset
   317
        params.setApplicationProtocols(applicationProtocols);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   318
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   319
        return params;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   320
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   321
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   322
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   323
     * Applies SSLParameters to newly accepted connections.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   324
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   325
    @Override
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30904
diff changeset
   326
    public synchronized void setSSLParameters(SSLParameters params) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   327
        super.setSSLParameters(params);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   328
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   329
        // the super implementation does not handle the following parameters
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   330
        identificationProtocol = params.getEndpointIdentificationAlgorithm();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   331
        algorithmConstraints = params.getAlgorithmConstraints();
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14665
diff changeset
   332
        preferLocalCipherSuites = params.getUseCipherSuitesOrder();
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   333
        Collection<SNIMatcher> matchers = params.getSNIMatchers();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   334
        if (matchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   335
            sniMatchers = params.getSNIMatchers();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   336
        }
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 32649
diff changeset
   337
        applicationProtocols = params.getApplicationProtocols();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   338
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   339
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   340
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Accept a new SSL connection.  This server identifies itself with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * information provided in the authentication context which was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * presented during construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   345
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public Socket accept() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        SSLSocketImpl s = new SSLSocketImpl(sslContext, useServerMode,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   348
            enabledCipherSuites, clientAuthType, enableSessionCreation,
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 13815
diff changeset
   349
            enabledProtocols, identificationProtocol, algorithmConstraints,
38865
429c08bd6158 8158978: ALPN not working when values are set directly on a SSLServerSocket
wetmore
parents: 34380
diff changeset
   350
            sniMatchers, preferLocalCipherSuites, applicationProtocols);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        implAccept(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        s.doneConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Provides a brief description of this SSL socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   360
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return "[SSL: "+ super.toString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
}