jdk/src/share/classes/javax/net/ssl/SSLParameters.java
author xuelei
Thu, 18 Oct 2012 01:14:00 -0700
changeset 14194 971f46db533d
parent 11838 90e9e05727dc
child 14196 1ebcd181a423
permissions -rw-r--r--
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server Reviewed-by: mullan, weijun, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
11838
90e9e05727dc 7144781: incorrect URLs in JSSE java doc
xuelei
parents: 7043
diff changeset
     2
 * Copyright (c) 2005, 2012, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
package javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    28
import java.security.AlgorithmConstraints;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    29
import java.util.Map;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    30
import java.util.List;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    31
import java.util.HashSet;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    32
import java.util.HashMap;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    33
import java.util.ArrayList;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    34
import java.util.Collection;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    35
import java.util.Collections;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    36
import java.util.LinkedHashMap;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    37
import java.util.regex.Pattern;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    38
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Encapsulates parameters for an SSL/TLS connection. The parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * are the list of ciphersuites to be accepted in an SSL/TLS handshake,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    42
 * the list of protocols to be allowed, the endpoint identification
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    43
 * algorithm during SSL/TLS handshaking, the Server Name Indication (SNI),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    44
 * the algorithm constraints and whether SSL/TLS servers should request
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    45
 * or require client authentication.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    46
 * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    47
 * SSLParameters can be created via the constructors in this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Objects can also be obtained using the <code>getSSLParameters()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@link SSLSocket#getSSLParameters SSLSocket} and
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    51
 * {@link SSLServerSocket#getSSLParameters SSLServerSocket} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link SSLEngine#getSSLParameters SSLEngine} or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * {@link SSLContext#getDefaultSSLParameters getDefaultSSLParameters()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * {@link SSLContext#getSupportedSSLParameters getSupportedSSLParameters()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * methods in <code>SSLContext</code>.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    56
 * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    57
 * SSLParameters can be applied to a connection via the methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * {@link SSLSocket#setSSLParameters SSLSocket.setSSLParameters()} and
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    59
 * {@link SSLServerSocket#setSSLParameters SSLServerSocket.setSSLParameters()}
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    60
 * and {@link SSLEngine#setSSLParameters SSLEngine.setSSLParameters()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see SSLSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see SSLEngine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see SSLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class SSLParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private String[] cipherSuites;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private String[] protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private boolean needClientAuth;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    74
    private String identificationAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    75
    private AlgorithmConstraints algorithmConstraints;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    76
    private Map<Integer, SNIServerName> sniNames = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    77
    private Map<Integer, SNIMatcher> sniMatchers = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Constructs SSLParameters.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    81
     * <p>
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    82
     * The values of cipherSuites, protocols, cryptographic algorithm
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    83
     * constraints, endpoint identification algorithm, server names and
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    84
     * server name matchers are set to <code>null</code>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * wantClientAuth and needClientAuth are set to <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public SSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs SSLParameters from the specified array of ciphersuites.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    93
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <code>setCipherSuites(cipherSuites);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public SSLParameters(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Constructs SSLParameters from the specified array of ciphersuites
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * and protocols.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   107
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>setCipherSuites(cipherSuites); setProtocols(protocols);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public SSLParameters(String[] cipherSuites, String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        setProtocols(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static String[] clone(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return (s == null) ? null : s.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public String[] getCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Sets the array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void setCipherSuites(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.cipherSuites = clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public String[] getProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Sets the array of protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void setProtocols(String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.protocols = clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Sets whether client authentication should be requested. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * this method clears the <code>needClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param wantClientAuth whether client authentication should be requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void setWantClientAuth(boolean wantClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.wantClientAuth = wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        this.needClientAuth = false;
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 whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Sets whether client authentication should be required. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * this method clears the <code>wantClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param needClientAuth whether client authentication should be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public void setNeedClientAuth(boolean needClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this.wantClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        this.needClientAuth = needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   204
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   205
     * Returns the cryptographic algorithm constraints.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   206
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   207
     * @return the cryptographic algorithm constraints, or null if the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   208
     *     constraints have not been set
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   209
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   210
     * @see #setAlgorithmConstraints(AlgorithmConstraints)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   211
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   212
     * @since 1.7
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   213
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   214
    public AlgorithmConstraints getAlgorithmConstraints() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   215
        return algorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   216
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   217
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   218
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   219
     * Sets the cryptographic algorithm constraints, which will be used
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   220
     * in addition to any configured by the runtime environment.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   221
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   222
     * If the <code>constraints</code> parameter is non-null, every
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   223
     * cryptographic algorithm, key and algorithm parameters used in the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   224
     * SSL/TLS handshake must be permitted by the constraints.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   225
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   226
     * @param constraints the algorithm constraints (or null)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   227
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   228
     * @since 1.7
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   229
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   230
    public void setAlgorithmConstraints(AlgorithmConstraints constraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   231
        // the constraints object is immutable
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   232
        this.algorithmConstraints = constraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   233
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   234
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   235
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   236
     * Gets the endpoint identification algorithm.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   237
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   238
     * @return the endpoint identification algorithm, or null if none
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   239
     * has been set.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   240
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   241
     * @see X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   242
     * @see #setEndpointIdentificationAlgorithm(String)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   243
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   244
     * @since 1.7
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   245
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   246
    public String getEndpointIdentificationAlgorithm() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   247
        return identificationAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   248
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   249
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   250
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   251
     * Sets the endpoint identification algorithm.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   252
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   253
     * If the <code>algorithm</code> parameter is non-null or non-empty, the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   254
     * endpoint identification/verification procedures must be handled during
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   255
     * SSL/TLS handshaking.  This is to prevent man-in-the-middle attacks.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   256
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   257
     * @param algorithm The standard string name of the endpoint
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   258
     *     identification algorithm (or null).  See Appendix A in the <a href=
11838
90e9e05727dc 7144781: incorrect URLs in JSSE java doc
xuelei
parents: 7043
diff changeset
   259
     *   "{@docRoot}/../technotes/guides/security/crypto/CryptoSpec.html#AppA">
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   260
     *     Java Cryptography Architecture API Specification &amp; Reference </a>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   261
     *     for information about standard algorithm names.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   262
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   263
     * @see X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   264
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   265
     * @since 1.7
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   266
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   267
    public void setEndpointIdentificationAlgorithm(String algorithm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   268
        this.identificationAlgorithm = algorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   269
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   270
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   271
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   272
     * Sets the desired {@link SNIServerName}s of the Server Name
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   273
     * Indication (SNI) parameter.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   274
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   275
     * This method is only useful to {@link SSLSocket}s or {@link SSLEngine}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   276
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   277
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   278
     * Note that the {@code serverNames} list is cloned
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   279
     * to protect against subsequent modification.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   280
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   281
     * @param  serverNames
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   282
     *         the list of desired {@link SNIServerName}s (or null)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   283
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   284
     * @throws NullPointerException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   285
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   286
     * @throws IllegalArgumentException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   287
     *         contains more than one name of the same name type
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   288
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   289
     * @see SNIServerName
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   290
     * @see #getServerNames()
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   291
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   292
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   293
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   294
    public void setServerNames(List<SNIServerName> serverNames) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   295
        if (serverNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   296
            if (!serverNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   297
                sniNames = new LinkedHashMap<>(serverNames.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   298
                for (SNIServerName serverName : serverNames) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   299
                    if (sniNames.put(serverName.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   300
                                                serverName) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   301
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   302
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   303
                                    serverName.getType());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   304
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   305
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   306
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   307
                sniNames = Collections.<Integer, SNIServerName>emptyMap();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   308
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   309
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   310
            sniNames = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   311
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   312
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   313
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   314
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   315
     * Returns a {@link List} containing all {@link SNIServerName}s of the
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   316
     * Server Name Indication (SNI) parameter, or null if none has been set.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   317
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   318
     * This method is only useful to {@link SSLSocket}s or {@link SSLEngine}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   319
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   320
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   321
     * For SSL/TLS connections, the underlying SSL/TLS provider
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   322
     * may specify a default value for a certain server name type.  In
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   323
     * client mode, it is recommended that, by default, providers should
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   324
     * include the server name indication whenever the server can be located
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   325
     * by a supported server name type.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   326
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   327
     * It is recommended that providers initialize default Server Name
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   328
     * Indications when creating {@code SSLSocket}/{@code SSLEngine}s.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   329
     * In the following examples, the server name could be represented by an
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   330
     * instance of {@link SNIHostName} which has been initialized with the
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   331
     * hostname "www.example.com" and type
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   332
     * {@link StandardConstants#SNI_HOST_NAME}.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   333
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   334
     * <pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   335
     *     Socket socket =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   336
     *         sslSocketFactory.createSocket("www.example.com", 443);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   337
     * </pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   338
     * or
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   339
     * <pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   340
     *     SSLEngine engine =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   341
     *         sslContext.createSSLEngine("www.example.com", 443);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   342
     * </pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   343
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   344
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   345
     * @return null or an immutable list of non-null {@link SNIServerName}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   346
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   347
     * @see List
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   348
     * @see #setServerNames(List<SNIServerName>)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   349
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   350
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   351
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   352
    public List<SNIServerName> getServerNames() {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   353
        if (sniNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   354
            if (!sniNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   355
                return Collections.<SNIServerName>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   356
                                        new ArrayList<>(sniNames.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   357
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   358
                return Collections.<SNIServerName>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   359
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   360
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   361
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   362
        return null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   363
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   364
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   365
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   366
     * Sets the {@link SNIMatcher}s of the Server Name Indication (SNI)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   367
     * parameter.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   368
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   369
     * This method is only useful to {@link SSLSocket}s or {@link SSLEngine}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   370
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   371
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   372
     * Note that the {@code matchers} collection is cloned to protect
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   373
     * against subsequent modification.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   374
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   375
     * @param  matchers
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   376
     *         the collection of {@link SNIMatcher}s (or null)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   377
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   378
     * @throws NullPointerException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   379
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   380
     * @throws IllegalArgumentException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   381
     *         contains more than one name of the same name type
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   382
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   383
     * @see Collection
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   384
     * @see SNIMatcher
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   385
     * @see #getSNIMatchers()
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   386
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   387
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   388
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   389
    public void setSNIMatchers(Collection<SNIMatcher> matchers) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   390
        if (matchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   391
            if (!matchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   392
                sniMatchers = new HashMap<>(matchers.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   393
                for (SNIMatcher matcher : matchers) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   394
                    if (sniMatchers.put(matcher.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   395
                                                matcher) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   396
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   397
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   398
                                    matcher.getType());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   399
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   400
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   401
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   402
                sniMatchers = Collections.<Integer, SNIMatcher>emptyMap();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   403
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   404
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   405
            sniMatchers = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   406
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   407
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   408
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   409
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   410
     * Returns a {@link Collection} containing all {@link SNIMatcher}s of the
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   411
     * Server Name Indication (SNI) parameter, or null if none has been set.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   412
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   413
     * This method is only useful to {@link SSLSocket}s or {@link SSLEngine}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   414
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   415
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   416
     * For better interoperability, providers generally will not define
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   417
     * default matchers so that by default servers will ignore the SNI
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   418
     * extension and continue the handshake.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   419
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   420
     * @return null or an immutable collection of non-null {@link SNIMatcher}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   421
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   422
     * @see SNIMatcher
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   423
     * @see #setSNIMatchers(Collection<SNIMatcher>)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   424
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   425
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   426
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   427
    public Collection<SNIMatcher> getSNIMatchers() {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   428
        if (sniMatchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   429
            if (!sniMatchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   430
                return Collections.<SNIMatcher>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   431
                                        new ArrayList<>(sniMatchers.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   432
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   433
                return Collections.<SNIMatcher>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   434
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   435
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   436
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   437
        return null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   438
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
}
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   440