jdk/src/java.base/share/classes/javax/net/ssl/SSLParameters.java
author xuelei
Tue, 02 Jun 2015 04:01:04 +0000
changeset 30904 ec0224270f90
parent 29492 a4bf9a570035
child 34380 2b2609379881
permissions -rw-r--r--
8043758: Datagram Transport Layer Security (DTLS) Reviewed-by: jnimeh, weijun, mullan, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
     2
 * Copyright (c) 2005, 2015, 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
/**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    38
 * Encapsulates parameters for an SSL/TLS/DTLS connection. The parameters
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    39
 * are the list of ciphersuites to be accepted in an SSL/TLS/DTLS 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
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    41
 * algorithm during SSL/TLS/DTLS handshaking, the Server Name Indication (SNI),
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    42
 * the maximum network packet size, the algorithm constraints and whether
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    43
 * SSL/TLS/DTLS servers should request or require client authentication, etc.
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.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    46
 * Objects can also be obtained using the {@code getSSLParameters()}
2
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()}
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    53
 * methods in {@code SSLContext}.
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;
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
    76
    private boolean preferLocalCipherSuites;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    77
    private boolean enableRetransmissions = true;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    78
    private int maximumPacketSize = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Constructs SSLParameters.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    82
     * <p>
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    83
     * The values of cipherSuites, protocols, cryptographic algorithm
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
    84
     * constraints, endpoint identification algorithm, server names and
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    85
     * server name matchers are set to {@code null}; useCipherSuitesOrder,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    86
     * wantClientAuth and needClientAuth are set to {@code false};
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    87
     * enableRetransmissions is set to {@code true}; maximum network packet
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    88
     * size is set to {@code 0}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public SSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Constructs SSLParameters from the specified array of ciphersuites.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    96
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * constructor followed by
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
    99
     * {@code setCipherSuites(cipherSuites);}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public SSLParameters(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs SSLParameters from the specified array of ciphersuites
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * and protocols.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   110
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * constructor followed by
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   113
     * {@code setCipherSuites(cipherSuites); setProtocols(protocols);}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public SSLParameters(String[] cipherSuites, String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        setProtocols(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static String[] clone(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return (s == null) ? null : s.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns 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
     * @return a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public String[] getCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Sets the array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void setCipherSuites(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.cipherSuites = clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns 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
     * @return a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public String[] getProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Sets the array of protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void setProtocols(String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this.protocols = clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Returns whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Sets whether client authentication should be requested. Calling
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   178
     * this method clears the {@code needClientAuth} flag.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param wantClientAuth whether client authentication should be requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void setWantClientAuth(boolean wantClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        this.wantClientAuth = wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this.needClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Returns whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Sets whether client authentication should be required. Calling
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   198
     * this method clears the {@code wantClientAuth} flag.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param needClientAuth whether client authentication should be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public void setNeedClientAuth(boolean needClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this.wantClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.needClientAuth = needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
7043
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
     * Returns the cryptographic algorithm constraints.
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
     * @return the cryptographic algorithm constraints, or null if the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   211
     *     constraints have not been set
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   212
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   213
     * @see #setAlgorithmConstraints(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
     * @since 1.7
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
    public AlgorithmConstraints getAlgorithmConstraints() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   218
        return algorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   219
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   220
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   221
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   222
     * Sets the cryptographic algorithm constraints, which will be used
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   223
     * in addition to any configured by the runtime environment.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   224
     * <p>
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   225
     * If the {@code constraints} parameter is non-null, every
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   226
     * cryptographic algorithm, key and algorithm parameters used in the
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   227
     * SSL/TLS/DTLS handshake must be permitted by the constraints.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   228
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   229
     * @param constraints the algorithm constraints (or null)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   230
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   231
     * @since 1.7
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
    public void setAlgorithmConstraints(AlgorithmConstraints constraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   234
        // the constraints object is immutable
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   235
        this.algorithmConstraints = constraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   236
    }
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
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   239
     * Gets the endpoint identification algorithm.
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
     * @return the endpoint identification algorithm, or null if none
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   242
     * has been set.
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
     * @see X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   245
     * @see #setEndpointIdentificationAlgorithm(String)
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
     * @since 1.7
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
    public String getEndpointIdentificationAlgorithm() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   250
        return identificationAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   251
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   252
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   253
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   254
     * Sets the endpoint identification algorithm.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   255
     * <p>
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   256
     * If the {@code algorithm} parameter is non-null or non-empty, the
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   257
     * endpoint identification/verification procedures must be handled during
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   258
     * SSL/TLS/DTLS handshaking.  This is to prevent man-in-the-middle attacks.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   259
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   260
     * @param algorithm The standard string name of the endpoint
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   261
     *     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
   262
     *   "{@docRoot}/../technotes/guides/security/crypto/CryptoSpec.html#AppA">
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   263
     *     Java Cryptography Architecture API Specification &amp; Reference </a>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   264
     *     for information about standard algorithm names.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   265
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   266
     * @see X509ExtendedTrustManager
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
     * @since 1.7
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
    public void setEndpointIdentificationAlgorithm(String algorithm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   271
        this.identificationAlgorithm = algorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   272
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   273
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   274
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   275
     * 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
   276
     * Indication (SNI) parameter.
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
     * 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
   279
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   280
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   281
     * 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
   282
     * to protect against subsequent modification.
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
     * @param  serverNames
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   285
     *         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
   286
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   287
     * @throws NullPointerException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   288
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   289
     * @throws IllegalArgumentException if the {@code serverNames}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   290
     *         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
   291
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   292
     * @see SNIServerName
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   293
     * @see #getServerNames()
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   294
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   295
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   296
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   297
    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
   298
        if (serverNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   299
            if (!serverNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   300
                sniNames = new LinkedHashMap<>(serverNames.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   301
                for (SNIServerName serverName : serverNames) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   302
                    if (sniNames.put(serverName.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   303
                                                serverName) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   304
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   305
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   306
                                    serverName.getType());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   307
                    }
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 = Collections.<Integer, SNIServerName>emptyMap();
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
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   313
            sniNames = null;
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
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   316
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   317
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   318
     * 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
   319
     * 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
   320
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   321
     * 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
   322
     * operating in client mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   323
     * <P>
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   324
     * For SSL/TLS/DTLS connections, the underlying SSL/TLS/DTLS provider
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   325
     * 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
   326
     * 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
   327
     * 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
   328
     * by a supported server name type.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   329
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   330
     * 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
   331
     * 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
   332
     * 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
   333
     * 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
   334
     * hostname "www.example.com" and type
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   335
     * {@link StandardConstants#SNI_HOST_NAME}.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   336
     *
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
     *     Socket socket =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   339
     *         sslSocketFactory.createSocket("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
     * or
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
     *     SSLEngine engine =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   344
     *         sslContext.createSSLEngine("www.example.com", 443);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   345
     * </pre>
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
     * @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
   348
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   349
     * @see List
14663
49b7de969579 8001751: Javadoc warnings in JSSE code
xuelei
parents: 14514
diff changeset
   350
     * @see #setServerNames(List)
14194
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
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   353
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   354
    public final List<SNIServerName> getServerNames() {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   355
        if (sniNames != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   356
            if (!sniNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   357
                return Collections.<SNIServerName>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   358
                                        new ArrayList<>(sniNames.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   359
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   360
                return Collections.<SNIServerName>emptyList();
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
        return null;
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
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   367
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   368
     * 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
   369
     * parameter.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   370
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   371
     * 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
   372
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   373
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   374
     * 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
   375
     * against subsequent modification.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   376
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   377
     * @param  matchers
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   378
     *         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
   379
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   380
     * @throws NullPointerException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   381
     *         contains {@code null} element
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   382
     * @throws IllegalArgumentException if the {@code matchers}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   383
     *         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
   384
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   385
     * @see Collection
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   386
     * @see SNIMatcher
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   387
     * @see #getSNIMatchers()
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
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   390
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   391
    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
   392
        if (matchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   393
            if (!matchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   394
                sniMatchers = new HashMap<>(matchers.size());
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   395
                for (SNIMatcher matcher : matchers) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   396
                    if (sniMatchers.put(matcher.getType(),
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   397
                                                matcher) != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   398
                        throw new IllegalArgumentException(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   399
                                    "Duplicated server name of type " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   400
                                    matcher.getType());
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
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   403
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   404
                sniMatchers = Collections.<Integer, SNIMatcher>emptyMap();
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
        } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   407
            sniMatchers = null;
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
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   411
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   412
     * 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
   413
     * 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
   414
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   415
     * 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
   416
     * operating in server mode.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   417
     * <P>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   418
     * 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
   419
     * 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
   420
     * extension and continue the handshake.
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
     * @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
   423
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   424
     * @see SNIMatcher
14663
49b7de969579 8001751: Javadoc warnings in JSSE code
xuelei
parents: 14514
diff changeset
   425
     * @see #setSNIMatchers(Collection)
14194
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
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   428
     */
14196
1ebcd181a423 8000954: Add final keyword to new method in SSLParameters
xuelei
parents: 14194
diff changeset
   429
    public final Collection<SNIMatcher> getSNIMatchers() {
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   430
        if (sniMatchers != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   431
            if (!sniMatchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   432
                return Collections.<SNIMatcher>unmodifiableList(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   433
                                        new ArrayList<>(sniMatchers.values()));
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   434
            } else {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   435
                return Collections.<SNIMatcher>emptyList();
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
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   438
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   439
        return null;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   440
    }
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   441
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   442
    /**
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   443
     * Sets whether the local cipher suites preference should be honored.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   444
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   445
     * @param honorOrder whether local cipher suites order in
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   446
     *        {@code #getCipherSuites} should be honored during
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   447
     *        SSL/TLS/DTLS handshaking.
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   448
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   449
     * @see #getUseCipherSuitesOrder()
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   450
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   451
     * @since 1.8
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   452
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   453
    public final void setUseCipherSuitesOrder(boolean honorOrder) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   454
        this.preferLocalCipherSuites = honorOrder;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   455
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   456
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   457
    /**
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   458
     * Returns whether the local cipher suites preference should be honored.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   459
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   460
     * @return whether local cipher suites order in {@code #getCipherSuites}
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   461
     *         should be honored during SSL/TLS/DTLS handshaking.
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   462
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   463
     * @see #setUseCipherSuitesOrder(boolean)
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   464
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   465
     * @since 1.8
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   466
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   467
    public final boolean getUseCipherSuitesOrder() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   468
        return preferLocalCipherSuites;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 14663
diff changeset
   469
    }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   470
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   471
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   472
     * Sets whether DTLS handshake retransmissions should be enabled.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   473
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   474
     * This method only applies to DTLS.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   475
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   476
     * @param   enableRetransmissions
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   477
     *          {@code true} indicates that DTLS handshake retransmissions
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   478
     *          should be enabled; {@code false} indicates that DTLS handshake
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   479
     *          retransmissions should be disabled
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   480
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   481
     * @see     #getEnableRetransmissions()
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   482
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   483
     * @since 1.9
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   484
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   485
    public void setEnableRetransmissions(boolean enableRetransmissions) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   486
        this.enableRetransmissions = enableRetransmissions;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   487
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   488
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   489
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   490
     * Returns whether DTLS handshake retransmissions should be enabled.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   491
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   492
     * This method only applies to DTLS.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   493
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   494
     * @return  true, if DTLS handshake retransmissions should be enabled
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   495
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   496
     * @see     #setEnableRetransmissions(boolean)
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   497
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   498
     * @since 1.9
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   499
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   500
    public boolean getEnableRetransmissions() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   501
        return enableRetransmissions;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   502
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   503
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   504
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   505
     * Sets the maximum expected network packet size in bytes for
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   506
     * SSL/TLS/DTLS records.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   507
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   508
     * @apiNote  It is recommended that if possible, the maximum packet size
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   509
     *           should not be less than 256 bytes so that small handshake
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   510
     *           messages, such as HelloVerifyRequests, are not fragmented.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   511
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   512
     * @implNote If the maximum packet size is too small to hold a minimal
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   513
     *           record, an implementation may attempt to generate as minimal
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   514
     *           records as possible.  However, this may cause a generated
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   515
     *           packet to be larger than the maximum packet size.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   516
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   517
     * @param   maximumPacketSize
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   518
     *          the maximum expected network packet size in bytes, or
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   519
     *          {@code 0} to use the implicit size that is automatically
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   520
     *          specified by the underlying implementation.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   521
     * @throws  IllegalArgumentException
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   522
     *          if {@code maximumPacketSize} is negative.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   523
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   524
     * @see     #getMaximumPacketSize()
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   525
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   526
     * @since 1.9
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   527
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   528
    public void setMaximumPacketSize(int maximumPacketSize) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   529
        if (maximumPacketSize < 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   530
            throw new IllegalArgumentException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   531
                "The maximum packet size cannot be negative");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   532
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   533
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   534
        this.maximumPacketSize = maximumPacketSize;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   535
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   536
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   537
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   538
     * Returns the maximum expected network packet size in bytes for
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   539
     * SSL/TLS/DTLS records.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   540
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   541
     * @apiNote  The implicit size may not be a fixed value, especially
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   542
     *           for a DTLS protocols implementation.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   543
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   544
     * @implNote For SSL/TLS/DTLS connections, the underlying provider
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   545
     *           should calculate and specify the implicit value of the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   546
     *           maximum expected network packet size if it is not
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   547
     *           configured explicitly.  For any connection populated
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   548
     *           object, this method should never return {@code 0} so
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   549
     *           that applications can retrieve the actual implicit size
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   550
     *           of the underlying implementation.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   551
     *           <P>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   552
     *           An implementation should attempt to comply with the maximum
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   553
     *           packet size configuration.  However, if the maximum packet
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   554
     *           size is too small to hold a minimal record, an implementation
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   555
     *           may try to generate as minimal records as possible.  This
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   556
     *           may cause a generated packet to be larger than the maximum
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   557
     *           packet size.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   558
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   559
     * @return   the maximum expected network packet size, or {@code 0} if
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   560
     *           use the implicit size that is automatically specified by
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   561
     *           the underlying implementation and this object has not been
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   562
     *           populated by any connection.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   563
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   564
     * @see      #setMaximumPacketSize(int)
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   565
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   566
     * @since 1.9
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   567
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   568
    public int getMaximumPacketSize() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   569
        return maximumPacketSize;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   570
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29492
diff changeset
   571
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
}
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 11838
diff changeset
   573