jdk/src/share/classes/javax/net/ssl/SSLParameters.java
author xuelei
Sun, 18 Nov 2012 01:31:44 -0800
changeset 14514 46a8ed03c7fc
parent 14196 1ebcd181a423
child 14663 49b7de969579
permissions -rw-r--r--
8003587: Warning cleanup in package javax.net.ssl Summary: Removes unnecessary imports and adds missing Override annotations Reviewed-by: xuelei Contributed-by: Florian Weimer <fweimer@redhat.com>
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.HashMap;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    32
import java.util.ArrayList;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    33
import java.util.Collection;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    34
import java.util.Collections;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    35
import java.util.LinkedHashMap;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    36
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Encapsulates parameters for an SSL/TLS connection. The parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * 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
    40
 * 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
    41
 * 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
    42
 * 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
    43
 * or require client authentication.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    44
 * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    45
 * SSLParameters can be created via the constructors in this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Objects can also be obtained using the <code>getSSLParameters()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * {@link SSLSocket#getSSLParameters SSLSocket} and
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    49
 * {@link SSLServerSocket#getSSLParameters SSLServerSocket} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@link SSLEngine#getSSLParameters SSLEngine} or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * {@link SSLContext#getDefaultSSLParameters getDefaultSSLParameters()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link SSLContext#getSupportedSSLParameters getSupportedSSLParameters()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * methods in <code>SSLContext</code>.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    54
 * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    55
 * SSLParameters can be applied to a connection via the methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * {@link SSLSocket#setSSLParameters SSLSocket.setSSLParameters()} and
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    57
 * {@link SSLServerSocket#setSSLParameters SSLServerSocket.setSSLParameters()}
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    58
 * and {@link SSLEngine#setSSLParameters SSLEngine.setSSLParameters()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see SSLSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see SSLEngine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see SSLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public class SSLParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private String[] cipherSuites;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private String[] protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private boolean wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean needClientAuth;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    72
    private String identificationAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    73
    private AlgorithmConstraints algorithmConstraints;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    74
    private Map<Integer, SNIServerName> sniNames = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    75
    private Map<Integer, SNIMatcher> sniMatchers = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructs SSLParameters.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    79
     * <p>
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    80
     * The values of cipherSuites, protocols, cryptographic algorithm
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    81
     * constraints, endpoint identification algorithm, server names and
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    82
     * server name matchers are set to <code>null</code>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * wantClientAuth and needClientAuth are set to <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public SSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructs SSLParameters from the specified array of ciphersuites.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    91
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <code>setCipherSuites(cipherSuites);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public SSLParameters(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Constructs SSLParameters from the specified array of ciphersuites
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * and protocols.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   105
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <code>setCipherSuites(cipherSuites); setProtocols(protocols);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public SSLParameters(String[] cipherSuites, String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        setProtocols(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static String[] clone(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return (s == null) ? null : s.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Returns a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public String[] getCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Sets the array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void setCipherSuites(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.cipherSuites = clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Returns a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public String[] getProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Sets the array of protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void setProtocols(String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.protocols = clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Sets whether client authentication should be requested. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * this method clears the <code>needClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param wantClientAuth whether client authentication should be requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void setWantClientAuth(boolean wantClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this.wantClientAuth = wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.needClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Sets whether client authentication should be required. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * this method clears the <code>wantClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param needClientAuth whether client authentication should be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void setNeedClientAuth(boolean needClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.wantClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.needClientAuth = needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   202
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   203
     * Returns the cryptographic algorithm constraints.
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
     * @return the cryptographic algorithm constraints, or null if the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   206
     *     constraints have not been set
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   207
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   208
     * @see #setAlgorithmConstraints(AlgorithmConstraints)
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
     * @since 1.7
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
    public AlgorithmConstraints getAlgorithmConstraints() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   213
        return algorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   214
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   215
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
     * Sets the cryptographic algorithm constraints, which will be used
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   218
     * in addition to any configured by the runtime environment.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   219
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   220
     * If the <code>constraints</code> parameter is non-null, every
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   221
     * cryptographic algorithm, key and algorithm parameters used in the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   222
     * SSL/TLS handshake must be permitted by the constraints.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   223
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   224
     * @param constraints the algorithm constraints (or null)
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
     * @since 1.7
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
    public void setAlgorithmConstraints(AlgorithmConstraints constraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   229
        // the constraints object is immutable
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   230
        this.algorithmConstraints = constraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   231
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   232
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
     * Gets the endpoint identification algorithm.
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
     * @return the endpoint identification algorithm, or null if none
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   237
     * has been set.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   238
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   239
     * @see X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   240
     * @see #setEndpointIdentificationAlgorithm(String)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   241
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   242
     * @since 1.7
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
    public String getEndpointIdentificationAlgorithm() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   245
        return identificationAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   246
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   247
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
     * Sets the endpoint identification algorithm.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   250
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   251
     * 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
   252
     * endpoint identification/verification procedures must be handled during
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   253
     * 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
   254
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   255
     * @param algorithm The standard string name of the endpoint
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   256
     *     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
   257
     *   "{@docRoot}/../technotes/guides/security/crypto/CryptoSpec.html#AppA">
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   258
     *     Java Cryptography Architecture API Specification &amp; Reference </a>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   259
     *     for information about standard algorithm names.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   260
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   261
     * @see X509ExtendedTrustManager
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
     * @since 1.7
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
    public void setEndpointIdentificationAlgorithm(String algorithm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   266
        this.identificationAlgorithm = algorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   267
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   268
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   269
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   270
     * 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
   271
     * Indication (SNI) parameter.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   272
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   273
     * 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
   274
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   275
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   276
     * 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
   277
     * to protect against subsequent modification.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   278
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   279
     * @param  serverNames
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   280
     *         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
   281
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   282
     * @throws NullPointerException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   283
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   284
     * @throws IllegalArgumentException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   285
     *         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
   286
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   287
     * @see SNIServerName
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   288
     * @see #getServerNames()
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   289
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   290
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   291
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   292
    public final void setServerNames(List<SNIServerName> serverNames) {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   293
        if (serverNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   294
            if (!serverNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   295
                sniNames = new LinkedHashMap<>(serverNames.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   296
                for (SNIServerName serverName : serverNames) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   297
                    if (sniNames.put(serverName.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   298
                                                serverName) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   299
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   300
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   301
                                    serverName.getType());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   302
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   303
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   304
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   305
                sniNames = Collections.<Integer, SNIServerName>emptyMap();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   306
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   307
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   308
            sniNames = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   309
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   310
    }
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
     * 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
   314
     * 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
   315
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   316
     * 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
   317
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   318
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   319
     * 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
   320
     * 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
   321
     * 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
   322
     * 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
   323
     * by a supported server name type.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   324
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   325
     * 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
   326
     * 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
   327
     * 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
   328
     * 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
   329
     * hostname "www.example.com" and type
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   330
     * {@link StandardConstants#SNI_HOST_NAME}.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   331
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   332
     * <pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   333
     *     Socket socket =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   334
     *         sslSocketFactory.createSocket("www.example.com", 443);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   335
     * </pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   336
     * or
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
     *     SSLEngine engine =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   339
     *         sslContext.createSSLEngine("www.example.com", 443);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   340
     * </pre>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   341
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   342
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   343
     * @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
   344
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   345
     * @see List
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   346
     * @see #setServerNames(List<SNIServerName>)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   347
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   348
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   349
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   350
    public final List<SNIServerName> getServerNames() {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   351
        if (sniNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   352
            if (!sniNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   353
                return Collections.<SNIServerName>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   354
                                        new ArrayList<>(sniNames.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   355
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   356
                return Collections.<SNIServerName>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   357
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   358
        }
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
        return null;
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
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
     * 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
   365
     * parameter.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   366
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   367
     * 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
   368
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   369
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   370
     * 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
   371
     * against subsequent modification.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   372
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   373
     * @param  matchers
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   374
     *         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
   375
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   376
     * @throws NullPointerException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   377
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   378
     * @throws IllegalArgumentException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   379
     *         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
   380
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   381
     * @see Collection
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   382
     * @see SNIMatcher
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   383
     * @see #getSNIMatchers()
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   384
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   385
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   386
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   387
    public final void setSNIMatchers(Collection<SNIMatcher> matchers) {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   388
        if (matchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   389
            if (!matchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   390
                sniMatchers = new HashMap<>(matchers.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   391
                for (SNIMatcher matcher : matchers) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   392
                    if (sniMatchers.put(matcher.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   393
                                                matcher) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   394
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   395
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   396
                                    matcher.getType());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   397
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   398
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   399
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   400
                sniMatchers = Collections.<Integer, SNIMatcher>emptyMap();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   401
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   402
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   403
            sniMatchers = null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   404
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   405
    }
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
     * 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
   409
     * 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
   410
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   411
     * 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
   412
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   413
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   414
     * 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
   415
     * 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
   416
     * extension and continue the handshake.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   417
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   418
     * @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
   419
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   420
     * @see SNIMatcher
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   421
     * @see #setSNIMatchers(Collection<SNIMatcher>)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   422
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   423
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   424
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   425
    public final Collection<SNIMatcher> getSNIMatchers() {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   426
        if (sniMatchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   427
            if (!sniMatchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   428
                return Collections.<SNIMatcher>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   429
                                        new ArrayList<>(sniMatchers.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   430
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   431
                return Collections.<SNIMatcher>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   432
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   433
        }
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
        return null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   436
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   438