jdk/src/java.base/share/classes/sun/security/ssl/ServerHandshaker.java
author redestad
Thu, 21 Apr 2016 13:39:53 +0200
changeset 37593 824750ada3d6
parent 37361 a790f7bc3878
child 37781 71ed5645f17c
permissions -rw-r--r--
8154231: Simplify access to System properties from JDK code Reviewed-by: rriggs, chegar, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36132
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 35298
diff changeset
     2
 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5182
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: 5182
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: 5182
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5182
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5182
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    31
import java.util.concurrent.TimeUnit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.interfaces.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.ECParameterSpec;
31712
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
    36
import java.math.BigInteger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    41
import sun.security.action.GetLongAction;
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
    42
import sun.security.util.KeyUtil;
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
    43
import sun.security.util.LegacyAlgorithmConstraints;
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
    44
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.ssl.HandshakeMessage.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.security.ssl.CipherSuite.*;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    47
import sun.security.ssl.SignatureAndHashAlgorithm.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import static sun.security.ssl.CipherSuite.KeyExchange.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * ServerHandshaker does the protocol handshaking from the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of view of a server.  It is driven asychronously by handshake messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * as delivered by the parent Handshaker class, and also uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * common functionality (e.g. key generation) that is provided there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
final class ServerHandshaker extends Handshaker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    60
    // The default number of milliseconds the handshaker will wait for
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    61
    // revocation status responses.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    62
    private static final long DEFAULT_STATUS_RESP_DELAY = 5000;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
    63
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // is the server going to require the client to authenticate?
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
    65
    private ClientAuthType      doClientAuth;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // our authentication info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private X509Certificate[]   certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private PrivateKey          privateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
17189
9f2ae085280b 8005523: Unbound krb5 for TLS
weijun
parents: 16100
diff changeset
    71
    private Object              serviceCreds;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // flag to check for clientCertificateVerify message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private boolean             needClientVerify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * For exportable ciphersuites using non-exportable key sizes, we use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * ephemeral RSA keys. We could also do anonymous RSA in the same way
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * but there are no such ciphersuites currently defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private PrivateKey          tempPrivateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private PublicKey           tempPublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * For anonymous and ephemeral Diffie-Hellman key exchange, we use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * ephemeral Diffie-Hellman keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private DHCrypt dh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // Helper for ECDH based key exchanges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private ECDHCrypt ecdh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // version request by the client in its ClientHello
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // we remember it for the RSA premaster secret version check
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private ProtocolVersion clientRequestedVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private SupportedEllipticCurvesExtension supportedCurves;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    99
    // the preferable signature algorithm used by ServerKeyExchange message
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   100
    SignatureAndHashAlgorithm preferableSignatureAlgorithm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   101
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   102
    // Flag to use smart ephemeral DH key which size matches the corresponding
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   103
    // authentication key
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   104
    private static final boolean useSmartEphemeralDHKeys;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   105
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   106
    // Flag to use legacy ephemeral DH key which size is 512 bits for
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   107
    // exportable cipher suites, and 768 bits for others
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   108
    private static final boolean useLegacyEphemeralDHKeys;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   109
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   110
    // The customized ephemeral DH key size for non-exportable cipher suites.
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   111
    private static final int customizedDHKeySize;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   112
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   113
    // legacy algorithm constraints
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   114
    private static final AlgorithmConstraints legacyAlgorithmConstraints =
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   115
            new LegacyAlgorithmConstraints(
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   116
                    LegacyAlgorithmConstraints.PROPERTY_TLS_LEGACY_ALGS,
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   117
                    new SSLAlgorithmDecomposer());
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
   118
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   119
    private long statusRespTimeout;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   120
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   121
    static {
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 37361
diff changeset
   122
        String property =
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 37361
diff changeset
   123
                GetPropertyAction.getProperty("jdk.tls.ephemeralDHKeySize");
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   124
        if (property == null || property.length() == 0) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   125
            useLegacyEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   126
            useSmartEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   127
            customizedDHKeySize = -1;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   128
        } else if ("matched".equals(property)) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   129
            useLegacyEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   130
            useSmartEphemeralDHKeys = true;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   131
            customizedDHKeySize = -1;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   132
        } else if ("legacy".equals(property)) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   133
            useLegacyEphemeralDHKeys = true;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   134
            useSmartEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   135
            customizedDHKeySize = -1;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   136
        } else {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   137
            useLegacyEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   138
            useSmartEphemeralDHKeys = false;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   139
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   140
            try {
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   141
                // DH parameter generation can be extremely slow, best to
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   142
                // use one of the supported pre-computed DH parameters
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   143
                // (see DHCrypt class).
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   144
                customizedDHKeySize = Integer.parseUnsignedInt(property);
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   145
                if (customizedDHKeySize < 1024 || customizedDHKeySize > 8192 ||
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   146
                        (customizedDHKeySize & 0x3f) != 0) {
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   147
                    throw new IllegalArgumentException(
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   148
                        "Unsupported customized DH key size: " +
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   149
                        customizedDHKeySize + ". " +
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   150
                        "The key size must be multiple of 64, " +
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
   151
                        "and can only range from 1024 to 8192 (inclusive)");
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   152
                }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   153
            } catch (NumberFormatException nfe) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   154
                throw new IllegalArgumentException(
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   155
                        "Invalid system property jdk.tls.ephemeralDHKeySize");
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   156
            }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   157
        }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   158
    }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
   159
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Constructor ... use the keys found in the auth context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    ServerHandshaker(SSLSocketImpl socket, SSLContextImpl context,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   164
            ProtocolList enabledProtocols, ClientAuthType clientAuth,
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   165
            ProtocolVersion activeProtocolVersion, boolean isInitialHandshake,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   166
            boolean secureRenegotiation,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   167
            byte[] clientVerifyData, byte[] serverVerifyData) {
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        super(socket, context, enabledProtocols,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   170
                (clientAuth != ClientAuthType.CLIENT_AUTH_NONE), false,
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   171
                activeProtocolVersion, isInitialHandshake, secureRenegotiation,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   172
                clientVerifyData, serverVerifyData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        doClientAuth = clientAuth;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   174
        statusRespTimeout = AccessController.doPrivileged(
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   175
                    new GetLongAction("jdk.tls.stapling.responseTimeout",
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   176
                        DEFAULT_STATUS_RESP_DELAY));
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   177
        statusRespTimeout = statusRespTimeout >= 0 ? statusRespTimeout :
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   178
                DEFAULT_STATUS_RESP_DELAY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Constructor ... use the keys found in the auth context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    ServerHandshaker(SSLEngineImpl engine, SSLContextImpl context,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   185
            ProtocolList enabledProtocols, ClientAuthType clientAuth,
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   186
            ProtocolVersion activeProtocolVersion,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   187
            boolean isInitialHandshake, boolean secureRenegotiation,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   188
            byte[] clientVerifyData, byte[] serverVerifyData,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   189
            boolean isDTLS) {
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        super(engine, context, enabledProtocols,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   192
                (clientAuth != ClientAuthType.CLIENT_AUTH_NONE), false,
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   193
                activeProtocolVersion, isInitialHandshake, secureRenegotiation,
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   194
                clientVerifyData, serverVerifyData, isDTLS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        doClientAuth = clientAuth;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   196
        statusRespTimeout = AccessController.doPrivileged(
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   197
                    new GetLongAction("jdk.tls.stapling.responseTimeout",
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   198
                        DEFAULT_STATUS_RESP_DELAY));
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   199
        statusRespTimeout = statusRespTimeout >= 0 ? statusRespTimeout :
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   200
                DEFAULT_STATUS_RESP_DELAY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * As long as handshaking has not started, we can change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * whether client authentication is required.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * we will need to wait for the next handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   208
    void setClientAuth(ClientAuthType clientAuth) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        doClientAuth = clientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * This routine handles all the server side handshake messages, one at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * a time.  Given the message type (and in some cases the pending cipher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * spec) it parses the type-specific message.  Then it calls a function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * that handles that specific message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * It updates the state machine as each message is processed, and writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * responses as needed using the connection in the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   221
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    void processMessage(byte type, int message_len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throws IOException {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   224
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   225
        // check the handshake state
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   226
        handshakeState.check(type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            case HandshakeMessage.ht_client_hello:
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   230
                ClientHello ch = new ClientHello(input, message_len, isDTLS);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   231
                handshakeState.update(ch, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   232
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                 * send it off for processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                this.clientHello(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            case HandshakeMessage.ht_certificate:
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   240
                if (doClientAuth == ClientAuthType.CLIENT_AUTH_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    fatalSE(Alerts.alert_unexpected_message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                "client sent unsolicited cert chain");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    // NOTREACHED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   245
                CertificateMsg certificateMsg = new CertificateMsg(input);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   246
                handshakeState.update(certificateMsg, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   247
                this.clientCertificate(certificateMsg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            case HandshakeMessage.ht_client_key_exchange:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                SecretKey preMasterSecret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                switch (keyExchange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                case K_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                case K_RSA_EXPORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                     * The client's pre-master secret is decrypted using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                     * either the server's normal private RSA key, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                     * temporary one used for non-export or signing-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                     * certificates/keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                     */
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   261
                    RSAClientKeyExchange pms = new RSAClientKeyExchange(
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   262
                            protocolVersion, clientRequestedVersion,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   263
                            sslContext.getSecureRandom(), input,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   264
                            message_len, privateKey);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   265
                    handshakeState.update(pms, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    preMasterSecret = this.clientKeyExchange(pms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                case K_DHE_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                case K_DHE_DSS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                case K_DH_ANON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                     * The pre-master secret is derived using the normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                     * Diffie-Hellman calculation.   Note that the main
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                     * protocol difference in these five flavors is in how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                     * the ServerKeyExchange message was constructed!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   277
                    DHClientKeyExchange dhcke = new DHClientKeyExchange(input);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   278
                    handshakeState.update(dhcke, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   279
                    preMasterSecret = this.clientKeyExchange(dhcke);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                case K_ECDH_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                case K_ECDH_ECDSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                case K_ECDHE_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                case K_ECDHE_ECDSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                case K_ECDH_ANON:
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   286
                    ECDHClientKeyExchange ecdhcke =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   287
                                    new ECDHClientKeyExchange(input);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   288
                    handshakeState.update(ecdhcke, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   289
                    preMasterSecret = this.clientKeyExchange(ecdhcke);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                default:
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   292
                    ClientKeyExchangeService p =
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   293
                            ClientKeyExchangeService.find(keyExchange.name);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   294
                    if (p == null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   295
                        throw new SSLProtocolException
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   296
                                ("Unrecognized key exchange: " + keyExchange);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   297
                    }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   298
                    byte[] encodedTicket = input.getBytes16();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   299
                    input.getBytes16();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   300
                    byte[] secret = input.getBytes16();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   301
                    ClientKeyExchange cke = p.createServerExchange(protocolVersion,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   302
                            clientRequestedVersion,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   303
                            sslContext.getSecureRandom(),
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   304
                            encodedTicket,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   305
                            secret,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   306
                            this.getAccSE(), serviceCreds);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   307
                    handshakeState.update(cke, resumingSession);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   308
                    preMasterSecret = this.clientKeyExchange(cke);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   309
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                // All keys are calculated from the premaster secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                // and the exchanged nonces in the same way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                calculateKeys(preMasterSecret, clientRequestedVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            case HandshakeMessage.ht_certificate_verify:
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   320
                CertificateVerify cvm =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   321
                        new CertificateVerify(input,
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
   322
                            getLocalSupportedSignAlgs(), protocolVersion);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   323
                handshakeState.update(cvm, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   324
                this.clientCertificateVerify(cvm);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   325
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            case HandshakeMessage.ht_finished:
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   329
                Finished cfm =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   330
                    new Finished(protocolVersion, input, cipherSuite);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   331
                handshakeState.update(cfm, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   332
                this.clientFinished(cfm);
28550
003089aca6b9 8057555: Less cryptic cipher suite management
ascarpino
parents: 28059
diff changeset
   333
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                throw new SSLProtocolException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        "Illegal server handshake msg, " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * ClientHello presents the server with a bunch of options, to which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * server replies with a ServerHello listing the ones which this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * will use.  If needed, it also writes its Certificate plus in some cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * a ServerKeyExchange message.  It may also write a CertificateRequest,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * to elicit a client certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * All these messages are terminated by a ServerHelloDone message.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * most cases, all this can be sent in a single Record.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private void clientHello(ClientHello mesg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   358
18283
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   359
        // Reject client initiated renegotiation?
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   360
        //
18570
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   361
        // If server side should reject client-initiated renegotiation,
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   362
        // send an alert_handshake_failure fatal alert, not a no_renegotiation
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   363
        // warning alert (no_renegotiation must be a warning: RFC 2246).
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   364
        // no_renegotiation might seem more natural at first, but warnings
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   365
        // are not appropriate because the sending party does not know how
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   366
        // the receiving party will behave.  This state must be treated as
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   367
        // a fatal server condition.
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   368
        //
9078dc28a187 8019359: To comment why not use no_renegotiation to reject client initiated renegotiation
xuelei
parents: 18283
diff changeset
   369
        // This will not have any impact on server initiated renegotiation.
18283
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   370
        if (rejectClientInitiatedRenego && !isInitialHandshake &&
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   371
                !serverHelloRequested) {
18283
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   372
            fatalSE(Alerts.alert_handshake_failure,
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   373
                "Client initiated renegotiation is not allowed");
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   374
        }
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   375
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   376
        // check the server name indication if required
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   377
        ServerNameExtension clientHelloSNIExt = (ServerNameExtension)
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   378
                    mesg.extensions.get(ExtensionType.EXT_SERVER_NAME);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   379
        if (!sniMatchers.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   380
            // we do not reject client without SNI extension
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   381
            if (clientHelloSNIExt != null &&
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   382
                        !clientHelloSNIExt.isMatched(sniMatchers)) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   383
                fatalSE(Alerts.alert_unrecognized_name,
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   384
                    "Unrecognized server name indication");
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   385
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   386
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   387
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   388
        // Does the message include security renegotiation indication?
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   389
        boolean renegotiationIndicated = false;
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   390
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   391
        // check the TLS_EMPTY_RENEGOTIATION_INFO_SCSV
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   392
        CipherSuiteList cipherSuites = mesg.getCipherSuites();
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   393
        if (cipherSuites.contains(CipherSuite.C_SCSV)) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   394
            renegotiationIndicated = true;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   395
            if (isInitialHandshake) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   396
                secureRenegotiation = true;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   397
            } else {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   398
                // abort the handshake with a fatal handshake_failure alert
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   399
                if (secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   400
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   401
                        "The SCSV is present in a secure renegotiation");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   402
                } else {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   403
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   404
                        "The SCSV is present in a insecure renegotiation");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   405
                }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   406
            }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   407
        }
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   408
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   409
        // check the "renegotiation_info" extension
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   410
        RenegotiationInfoExtension clientHelloRI = (RenegotiationInfoExtension)
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   411
                    mesg.extensions.get(ExtensionType.EXT_RENEGOTIATION_INFO);
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   412
        if (clientHelloRI != null) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   413
            renegotiationIndicated = true;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   414
            if (isInitialHandshake) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   415
                // verify the length of the "renegotiated_connection" field
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   416
                if (!clientHelloRI.isEmpty()) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   417
                    // abort the handshake with a fatal handshake_failure alert
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   418
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   419
                        "The renegotiation_info field is not empty");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   420
                }
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   421
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   422
                secureRenegotiation = true;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   423
            } else {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   424
                if (!secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   425
                    // unexpected RI extension for insecure renegotiation,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   426
                    // abort the handshake with a fatal handshake_failure alert
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   427
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   428
                        "The renegotiation_info is present in a insecure " +
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   429
                        "renegotiation");
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   430
                }
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   431
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   432
                // verify the client_verify_data value
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 31689
diff changeset
   433
                if (!MessageDigest.isEqual(clientVerifyData,
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   434
                                clientHelloRI.getRenegotiatedConnection())) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   435
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   436
                        "Incorrect verify data in ClientHello " +
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   437
                        "renegotiation_info message");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   438
                }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   439
            }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   440
        } else if (!isInitialHandshake && secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   441
           // if the connection's "secure_renegotiation" flag is set to TRUE
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   442
           // and the "renegotiation_info" extension is not present, abort
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   443
           // the handshake.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   444
            fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   445
                        "Inconsistent secure renegotiation indication");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   446
        }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   447
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   448
        // if there is no security renegotiation indication or the previous
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   449
        // handshake is insecure.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   450
        if (!renegotiationIndicated || !secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   451
            if (isInitialHandshake) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   452
                if (!allowLegacyHelloMessages) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   453
                    // abort the handshake with a fatal handshake_failure alert
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   454
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   455
                        "Failed to negotiate the use of secure renegotiation");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   456
                }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   457
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   458
                // continue with legacy ClientHello
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   459
                if (debug != null && Debug.isOn("handshake")) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   460
                    System.out.println("Warning: No renegotiation " +
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   461
                        "indication in ClientHello, allow legacy ClientHello");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   462
                }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   463
            } else if (!allowUnsafeRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   464
                // abort the handshake
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   465
                if (activeProtocolVersion.useTLS10PlusSpec()) {
18283
f842a42076b9 7188658: Add possibility to disable client initiated renegotiation
xuelei
parents: 17189
diff changeset
   466
                    // respond with a no_renegotiation warning
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   467
                    warningSE(Alerts.alert_no_renegotiation);
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   468
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   469
                    // invalidate the handshake so that the caller can
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   470
                    // dispose this object.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   471
                    invalidated = true;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   472
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   473
                    // If there is still unread block in the handshake
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   474
                    // input stream, it would be truncated with the disposal
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   475
                    // and the next handshake message will become incomplete.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   476
                    //
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   477
                    // However, according to SSL/TLS specifications, no more
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   478
                    // handshake message could immediately follow ClientHello
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   479
                    // or HelloRequest. But in case of any improper messages,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   480
                    // we'd better check to ensure there is no remaining bytes
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   481
                    // in the handshake input stream.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   482
                    if (input.available() > 0) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   483
                        fatalSE(Alerts.alert_unexpected_message,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   484
                            "ClientHello followed by an unexpected  " +
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   485
                            "handshake message");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   486
                    }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   487
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   488
                    return;
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   489
                } else {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   490
                    // For SSLv3, send the handshake_failure fatal error.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   491
                    // Note that SSLv3 does not define a no_renegotiation
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   492
                    // alert like TLSv1. However we cannot ignore the message
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   493
                    // simply, otherwise the other side was waiting for a
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   494
                    // response that would never come.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   495
                    fatalSE(Alerts.alert_handshake_failure,
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   496
                        "Renegotiation is not allowed");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   497
                }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   498
            } else {   // !isInitialHandshake && allowUnsafeRenegotiation
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   499
                // continue with unsafe renegotiation.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   500
                if (debug != null && Debug.isOn("handshake")) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   501
                    System.out.println(
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   502
                            "Warning: continue with insecure renegotiation");
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   503
                }
5182
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   504
            }
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   505
        }
62836694baeb 6898739: TLS renegotiation issue
xuelei
parents: 4236
diff changeset
   506
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   507
        // check the "max_fragment_length" extension
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   508
        MaxFragmentLengthExtension maxFragLenExt = (MaxFragmentLengthExtension)
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   509
                    mesg.extensions.get(ExtensionType.EXT_MAX_FRAGMENT_LENGTH);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   510
        if ((maxFragLenExt != null) && (maximumPacketSize != 0)) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   511
            // Not yet consider the impact of IV/MAC/padding.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   512
            int estimatedMaxFragSize = maximumPacketSize;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   513
            if (isDTLS) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   514
                estimatedMaxFragSize -= DTLSRecord.headerSize;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   515
            } else {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   516
                estimatedMaxFragSize -= SSLRecord.headerSize;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   517
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   518
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   519
            if (maxFragLenExt.getMaxFragLen() > estimatedMaxFragSize) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   520
                // For better interoperability, abort the maximum fragment
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   521
                // length negotiation, rather than terminate the connection
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   522
                // with a fatal alert.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   523
                maxFragLenExt = null;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   524
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   525
                // fatalSE(Alerts.alert_illegal_parameter,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   526
                //         "Not an allowed max_fragment_length value");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   527
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   528
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   529
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   530
        // check the ALPN extension
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   531
        ALPNExtension clientHelloALPN = (ALPNExtension)
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   532
            mesg.extensions.get(ExtensionType.EXT_ALPN);
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   533
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   534
        if ((clientHelloALPN != null) && (localApl.length > 0)) {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   535
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   536
            // Intersect the requested and the locally supported,
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   537
            // and save for later.
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   538
            String negotiatedValue = null;
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   539
            List<String> protocols = clientHelloALPN.getPeerAPs();
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   540
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   541
            // Use server preference order
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   542
            for (String ap : localApl) {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   543
                if (protocols.contains(ap)) {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   544
                    negotiatedValue = ap;
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   545
                    break;
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   546
                }
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   547
            }
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   548
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   549
            if (negotiatedValue == null) {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   550
                fatalSE(Alerts.alert_no_application_protocol,
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   551
                    new SSLHandshakeException(
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   552
                        "No matching ALPN values"));
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   553
            }
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   554
            applicationProtocol = negotiatedValue;
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   555
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   556
        } else {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   557
            applicationProtocol = "";
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   558
        }
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   559
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   560
        // cookie exchange
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   561
        if (isDTLS) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   562
             HelloCookieManager hcMgr = sslContext.getHelloCookieManager();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   563
             if ((mesg.cookie == null) || (mesg.cookie.length == 0) ||
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   564
                    (!hcMgr.isValid(mesg))) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   565
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   566
                //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   567
                // Perform cookie exchange for DTLS handshaking if no cookie
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   568
                // or the cookie is invalid in the ClientHello message.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   569
                //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   570
                HelloVerifyRequest m0 = new HelloVerifyRequest(hcMgr, mesg);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   571
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   572
                if (debug != null && Debug.isOn("handshake")) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   573
                    m0.print(System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   574
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   575
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   576
                m0.write(output);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   577
                handshakeState.update(m0, resumingSession);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   578
                output.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   579
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   580
                return;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   581
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   582
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * FIRST, construct the ServerHello using the options and priorities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         * from the ClientHello.  Update the (pending) cipher spec as we do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         * so, and save the client's version to protect against rollback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * attacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * There are a bunch of minor tasks here, and one major one: deciding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * if the short or the full handshake sequence will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        ServerHello m1 = new ServerHello();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        clientRequestedVersion = mesg.protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   597
        // select a proper protocol version.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   598
        ProtocolVersion selectedVersion =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   599
               selectProtocolVersion(clientRequestedVersion);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   600
        if (selectedVersion == null ||
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   601
                selectedVersion.v == ProtocolVersion.SSL20Hello.v) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            fatalSE(Alerts.alert_handshake_failure,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                "Client requested protocol " + clientRequestedVersion +
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   604
                " not enabled or not supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   606
7804
c59149ba3780 6996367: improve HandshakeHash
weijun
parents: 7043
diff changeset
   607
        handshakeHash.protocolDetermined(selectedVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        setVersion(selectedVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        m1.protocolVersion = protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        // random ... save client and server values for later use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        // in computing the master secret (from pre-master secret)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        // and thence the other crypto keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        // NOTE:  this use of three inputs to generating _each_ set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // of ciphers slows things down, but it does increase the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // security since each connection in the session can hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // its own authenticated (and strong) keys.  One could make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // creation of a session a rare thing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        clnt_random = mesg.clnt_random;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        svr_random = new RandomCookie(sslContext.getSecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        m1.svr_random = svr_random;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        session = null; // forget about the current session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // Here we go down either of two paths:  (a) the fast one, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // the client's asked to rejoin an existing session, and the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        // permits this; (b) the other one, where a new session is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (mesg.sessionId.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            // client is trying to resume a session, let's see...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            SSLSessionImpl previous = ((SSLSessionContextImpl)sslContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        .engineGetServerSessionContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        .get(mesg.sessionId.getId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            // Check if we can use the fast path, resuming a session.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            // can do so iff we have a valid record for that session, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            // the cipher suite for that session was on the list which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            // client requested, and if we're not forgetting any needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            // authentication on the part of the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            if (previous != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                resumingSession = previous.isRejoinable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    ProtocolVersion oldVersion = previous.getProtocolVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    // cannot resume session with different version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    if (oldVersion != protocolVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        resumingSession = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   657
                // cannot resume session with different server name indication
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   658
                if (resumingSession) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   659
                    List<SNIServerName> oldServerNames =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   660
                            previous.getRequestedServerNames();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   661
                    if (clientHelloSNIExt != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   662
                        if (!clientHelloSNIExt.isIdentical(oldServerNames)) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   663
                            resumingSession = false;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   664
                        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   665
                    } else if (!oldServerNames.isEmpty()) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   666
                        resumingSession = false;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   667
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   668
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   669
                    if (!resumingSession &&
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   670
                            debug != null && Debug.isOn("handshake")) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   671
                        System.out.println(
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   672
                            "The requested server name indication " +
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   673
                            "is not identical to the previous one");
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   674
                    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   675
                }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   676
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                if (resumingSession &&
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   678
                        (doClientAuth == ClientAuthType.CLIENT_AUTH_REQUIRED)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                        previous.getPeerPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    } catch (SSLPeerUnverifiedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        resumingSession = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                // validate subject identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    CipherSuite suite = previous.getSuite();
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   689
                    ClientKeyExchangeService p =
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   690
                            ClientKeyExchangeService.find(suite.keyExchange.name);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   691
                    if (p != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        Principal localPrincipal = previous.getLocalPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   694
                        if (p.isRelated(
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   695
                                false, getAccSE(), localPrincipal)) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   696
                            if (debug != null && Debug.isOn("session"))
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   697
                                System.out.println("Subject can" +
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   698
                                        " provide creds for princ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                            resumingSession = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                            if (debug != null && Debug.isOn("session"))
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   702
                                System.out.println("Subject cannot" +
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   703
                                        " provide creds for princ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    CipherSuite suite = previous.getSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                    // verify that the ciphersuite from the cached session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    // is in the list of client requested ciphersuites and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    // we have it enabled
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   713
                    if ((isNegotiable(suite) == false) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                            (mesg.getCipherSuites().contains(suite) == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                        resumingSession = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                        // everything looks ok, set the ciphersuite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        // this should be done last when we are sure we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                        // will resume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                        setCipherSuite(suite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    session = previous;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    if (debug != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                        (Debug.isOn("handshake") || Debug.isOn("session"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                        System.out.println("%% Resuming " + session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   732
        }   // else client did not try to resume
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        // If client hasn't specified a session we can resume, start a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        // new one and choose its cipher suite and compression options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        // Unless new session creation is disabled for this connection!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (session == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if (!enableNewSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                throw new SSLException("Client did not resume a session");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   743
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   744
            supportedCurves = (SupportedEllipticCurvesExtension)
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   745
                        mesg.extensions.get(ExtensionType.EXT_ELLIPTIC_CURVES);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   746
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   747
            // We only need to handle the "signature_algorithm" extension
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   748
            // for full handshakes and TLS 1.2 or later.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   749
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   750
                SignatureAlgorithmsExtension signAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   751
                    (SignatureAlgorithmsExtension)mesg.extensions.get(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   752
                                    ExtensionType.EXT_SIGNATURE_ALGORITHMS);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   753
                if (signAlgs != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   754
                    Collection<SignatureAndHashAlgorithm> peerSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   755
                                            signAlgs.getSignAlgorithms();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   756
                    if (peerSignAlgs == null || peerSignAlgs.isEmpty()) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   757
                        throw new SSLHandshakeException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   758
                            "No peer supported signature algorithms");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   759
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   760
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   761
                    Collection<SignatureAndHashAlgorithm>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   762
                        supportedPeerSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   763
                            SignatureAndHashAlgorithm.getSupportedAlgorithms(
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
   764
                                algorithmConstraints, peerSignAlgs);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   765
                    if (supportedPeerSignAlgs.isEmpty()) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   766
                        throw new SSLHandshakeException(
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
   767
                            "No signature and hash algorithm in common");
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   768
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   769
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   770
                    setPeerSupportedSignAlgs(supportedPeerSignAlgs);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   771
                } // else, need to use peer implicit supported signature algs
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   772
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   773
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   774
            session = new SSLSessionImpl(protocolVersion, CipherSuite.C_NULL,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   775
                        getLocalSupportedSignAlgs(),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   776
                        sslContext.getSecureRandom(),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   777
                        getHostAddressSE(), getPortSE());
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   778
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   779
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   780
                if (peerSupportedSignAlgs != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   781
                    session.setPeerSupportedSignatureAlgorithms(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   782
                            peerSupportedSignAlgs);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   783
                }   // else, we will set the implicit peer supported signature
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   784
                    // algorithms in chooseCipherSuite()
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   785
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   786
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   787
            // set the server name indication in the session
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   788
            List<SNIServerName> clientHelloSNI =
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   789
                    Collections.<SNIServerName>emptyList();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   790
            if (clientHelloSNIExt != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   791
                clientHelloSNI = clientHelloSNIExt.getServerNames();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   792
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   793
            session.setRequestedServerNames(clientHelloSNI);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   794
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   795
            // set the handshake session
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   796
            setHandshakeSessionSE(session);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   797
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   798
            // choose cipher suite and corresponding private key
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            chooseCipherSuite(mesg);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   800
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   801
            session.setSuite(cipherSuite);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            session.setLocalPrivateKey(privateKey);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   803
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            // chooseCompression(mesg);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   805
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   806
            // set the negotiated maximum fragment in the session
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   807
            //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   808
            // The protocol version and cipher suite have been negotiated
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   809
            // in previous processes.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   810
            if (maxFragLenExt != null) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   811
                int maxFragLen = maxFragLenExt.getMaxFragLen();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   812
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   813
                // More check of the requested "max_fragment_length" extension.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   814
                if (maximumPacketSize != 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   815
                    int estimatedMaxFragSize = cipherSuite.calculatePacketSize(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   816
                            maxFragLen, protocolVersion, isDTLS);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   817
                    if (estimatedMaxFragSize > maximumPacketSize) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   818
                        // For better interoperability, abort the maximum
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   819
                        // fragment length negotiation, rather than terminate
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   820
                        // the connection with a fatal alert.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   821
                        maxFragLenExt = null;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   822
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   823
                        // fatalSE(Alerts.alert_illegal_parameter,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   824
                        //         "Not an allowed max_fragment_length value");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   825
                    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   826
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   827
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   828
                if (maxFragLenExt != null) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   829
                    session.setNegotiatedMaxFragSize(maxFragLen);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   830
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   831
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   832
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   833
            session.setMaximumPacketSize(maximumPacketSize);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   834
        } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   835
            // set the handshake session
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   836
            setHandshakeSessionSE(session);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   837
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   838
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   839
        if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
   840
            handshakeHash.setFinishedAlg(cipherSuite.prfAlg.getPRFHashAlg());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        m1.cipherSuite = cipherSuite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        m1.sessionId = session.getSessionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        m1.compression_method = session.getCompression();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   847
        if (secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   848
            // For ServerHellos that are initial handshakes, then the
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   849
            // "renegotiated_connection" field in "renegotiation_info"
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   850
            // extension is of zero length.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   851
            //
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   852
            // For ServerHellos that are renegotiating, this field contains
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   853
            // the concatenation of client_verify_data and server_verify_data.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   854
            //
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   855
            // Note that for initial handshakes, both the clientVerifyData
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   856
            // variable and serverVerifyData variable are of zero length.
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   857
            HelloExtension serverHelloRI = new RenegotiationInfoExtension(
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   858
                                        clientVerifyData, serverVerifyData);
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   859
            m1.extensions.add(serverHelloRI);
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   860
        }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
   861
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   862
        if (!sniMatchers.isEmpty() && clientHelloSNIExt != null) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   863
            // When resuming a session, the server MUST NOT include a
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   864
            // server_name extension in the server hello.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   865
            if (!resumingSession) {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   866
                ServerNameExtension serverHelloSNI = new ServerNameExtension();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   867
                m1.extensions.add(serverHelloSNI);
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   868
            }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   869
        }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 12874
diff changeset
   870
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   871
        if ((maxFragLenExt != null) && !resumingSession) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   872
            // When resuming a session, the server MUST NOT include a
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   873
            // max_fragment_length extension in the server hello.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   874
            //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   875
            // Otherwise, use the same value as the requested extension.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   876
            m1.extensions.add(maxFragLenExt);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   877
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   878
36442
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   879
        StaplingParameters staplingParams = processStapling(mesg);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   880
        if (staplingParams != null) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   881
            // We now can safely assert status_request[_v2] in our
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   882
            // ServerHello, and know for certain that we can provide
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   883
            // responses back to this client for this connection.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   884
            if (staplingParams.statusRespExt ==
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   885
                    ExtensionType.EXT_STATUS_REQUEST) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   886
                m1.extensions.add(new CertStatusReqExtension());
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   887
            } else if (staplingParams.statusRespExt ==
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   888
                    ExtensionType.EXT_STATUS_REQUEST_V2) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   889
                m1.extensions.add(new CertStatusReqListV2Extension());
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   890
            }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   891
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   892
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   893
        // Prepare the ALPN response
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   894
        if (applicationProtocol != null && !applicationProtocol.isEmpty()) {
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   895
            m1.extensions.add(new ALPNExtension(applicationProtocol));
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   896
        }
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 34354
diff changeset
   897
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            m1.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            System.out.println("Cipher suite:  " + session.getSuite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        m1.write(output);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   903
        handshakeState.update(m1, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // If we are resuming a session, we finish writing handshake
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        // messages right now and then finish.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            calculateConnectionKeys(session.getMasterSecret());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            sendChangeCipherAndFinish(false);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   912
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   913
            // expecting the final ChangeCipherSpec and Finished messages
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   914
            expectingFinishFlightSE();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   915
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
         * SECOND, write the server Certificate(s) if we need to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
         * NOTE:  while an "anonymous RSA" mode is explicitly allowed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
         * the protocol, we can't support it since all of the SSL flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
         * defined in the protocol spec are explicitly stated to require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         * using RSA certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         */
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   928
        if (ClientKeyExchangeService.find(cipherSuite.keyExchange.name) != null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   929
            // No external key exchange provider needs a cert now.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        } else if ((keyExchange != K_DH_ANON) && (keyExchange != K_ECDH_ANON)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            if (certs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                throw new RuntimeException("no certificates");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            CertificateMsg m2 = new CertificateMsg(certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
             * Set local certs in the SSLSession, output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
             * debug info, and then actually write to the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            session.setLocalCertificates(certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                m2.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            m2.write(output);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
   946
            handshakeState.update(m2, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            // XXX has some side effects with OS TCP buffering,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            // leave it out for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            // let client verify chain in the meantime...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            // output.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            if (certs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                throw new RuntimeException("anonymous keyexchange with certs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   959
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   960
         * The CertificateStatus message ... only if it is needed.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   961
         * This would only be needed if we've established that this handshake
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   962
         * supports status stapling and there is at least one response to
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   963
         * return to the client.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   964
         */
36442
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   965
        if (staplingParams != null) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   966
            CertificateStatus csMsg = new CertificateStatus(
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   967
                    staplingParams.statReqType, certs,
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   968
                    staplingParams.responseMap);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   969
            if (debug != null && Debug.isOn("handshake")) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   970
                csMsg.print(System.out);
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   971
            }
36442
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   972
            csMsg.write(output);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
   973
            handshakeState.update(csMsg, resumingSession);
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   974
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31712
diff changeset
   975
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
         * THIRD, the ServerKeyExchange message ... iff it's needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
         * It's usually needed unless there's an encryption-capable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
         * RSA cert, or a D-H cert.  The notable exception is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
         * exportable ciphers used with big RSA keys need to downgrade
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
         * to use short RSA keys, even when the key/cert encrypts OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        ServerKeyExchange m3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        switch (keyExchange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        case K_RSA:
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
   988
            // no server key exchange for RSA ciphersuites
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            m3 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        case K_RSA_EXPORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            if (JsseJce.getRSAKeyLength(certs[0].getPublicKey()) > 512) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    m3 = new RSA_ServerKeyExchange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                        tempPublicKey, privateKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                        clnt_random, svr_random,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                        sslContext.getSecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    privateKey = tempPrivateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                    m3 = null; // make compiler happy
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1001
                    throw new SSLException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1002
                            "Error generating RSA server key exchange", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                // RSA_EXPORT with short key, don't need ServerKeyExchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                m3 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        case K_DHE_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        case K_DHE_DSS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                m3 = new DH_ServerKeyExchange(dh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    privateKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                    clnt_random.random_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                    svr_random.random_bytes,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1016
                    sslContext.getSecureRandom(),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1017
                    preferableSignatureAlgorithm,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1018
                    protocolVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                m3 = null; // make compiler happy
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1021
                throw new SSLException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1022
                        "Error generating DH server key exchange", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        case K_DH_ANON:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1026
            m3 = new DH_ServerKeyExchange(dh, protocolVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        case K_ECDHE_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        case K_ECDHE_ECDSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        case K_ECDH_ANON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                m3 = new ECDH_ServerKeyExchange(ecdh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    privateKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    clnt_random.random_bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    svr_random.random_bytes,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1036
                    sslContext.getSecureRandom(),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1037
                    preferableSignatureAlgorithm,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1038
                    protocolVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                m3 = null; // make compiler happy
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1041
                throw new SSLException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1042
                        "Error generating ECDH server key exchange", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        case K_ECDH_RSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        case K_ECDH_ECDSA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            // ServerKeyExchange not used for fixed ECDH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            m3 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        default:
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1051
            ClientKeyExchangeService p =
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1052
                    ClientKeyExchangeService.find(keyExchange.name);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1053
            if (p != null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1054
                // No external key exchange provider needs a cert now.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1055
                m3 = null;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1056
                break;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1057
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            throw new RuntimeException("internal error: " + keyExchange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        if (m3 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                m3.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            m3.write(output);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1065
            handshakeState.update(m3, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        // FOURTH, the CertificateRequest message.  The details of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        // the message can be affected by the key exchange algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        // in use.  For example, certs with fixed Diffie-Hellman keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // are only useful with the DH_DSS and DH_RSA key exchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        // algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        // Needed only if server requires client to authenticate self.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        // Illegal for anonymous flavors, so we need to check that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        //
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1078
        // No external key exchange provider needs a cert now.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1079
        if (doClientAuth != ClientAuthType.CLIENT_AUTH_NONE &&
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1080
                keyExchange != K_DH_ANON && keyExchange != K_ECDH_ANON &&
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1081
                ClientKeyExchangeService.find(keyExchange.name) == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            CertificateRequest m4;
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30905
diff changeset
  1084
            X509Certificate[] caCerts;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1086
            Collection<SignatureAndHashAlgorithm> localSignAlgs = null;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1087
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1088
                // We currently use all local upported signature and hash
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1089
                // algorithms. However, to minimize the computation cost
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1090
                // of requested hash algorithms, we may use a restricted
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1091
                // set of signature algorithms in the future.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1092
                localSignAlgs = getLocalSupportedSignAlgs();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1093
                if (localSignAlgs.isEmpty()) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1094
                    throw new SSLHandshakeException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1095
                            "No supported signature algorithm");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1096
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1097
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1098
                Set<String> localHashAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1099
                    SignatureAndHashAlgorithm.getHashAlgorithmNames(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1100
                        localSignAlgs);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1101
                if (localHashAlgs.isEmpty()) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1102
                    throw new SSLHandshakeException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1103
                            "No supported signature algorithm");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1104
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1105
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            caCerts = sslContext.getX509TrustManager().getAcceptedIssuers();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1108
            m4 = new CertificateRequest(caCerts, keyExchange,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1109
                                            localSignAlgs, protocolVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                m4.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            m4.write(output);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1115
            handshakeState.update(m4, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         * FIFTH, say ServerHelloDone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        ServerHelloDone m5 = new ServerHelloDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            m5.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        m5.write(output);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1127
        handshakeState.update(m5, resumingSession);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
         * Flush any buffered messages so the client will see them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
         * Ideally, all the messages above go in a single network level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
         * message to the client.  Without big Certificate chains, it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
         * going to be the common case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        output.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * Choose cipher suite from among those supported by client. Sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * the cipherSuite and keyExchange variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    private void chooseCipherSuite(ClientHello mesg) throws IOException {
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1143
        CipherSuiteList prefered;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1144
        CipherSuiteList proposed;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1145
        if (preferLocalCipherSuites) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1146
            prefered = getActiveCipherSuites();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1147
            proposed = mesg.getCipherSuites();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1148
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1149
            prefered = mesg.getCipherSuites();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1150
            proposed = getActiveCipherSuites();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1151
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1152
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1153
        List<CipherSuite> legacySuites = new ArrayList<>();
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1154
        for (CipherSuite suite : prefered.collection()) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1155
            if (isNegotiable(proposed, suite) == false) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1158
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1159
            if (doClientAuth == ClientAuthType.CLIENT_AUTH_REQUIRED) {
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1160
                if ((suite.keyExchange == K_DH_ANON) ||
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1161
                    (suite.keyExchange == K_ECDH_ANON)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1165
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1166
            if (!legacyAlgorithmConstraints.permits(null, suite.name, null)) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1167
                legacySuites.add(suite);
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1168
                continue;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1169
            }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1170
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if (trySetCipherSuite(suite) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1176
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1177
        for (CipherSuite suite : legacySuites) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1178
            if (trySetCipherSuite(suite)) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1179
                return;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1180
            }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1181
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents: 31538
diff changeset
  1182
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents: 18570
diff changeset
  1183
        fatalSE(Alerts.alert_handshake_failure, "no cipher suites in common");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * Set the given CipherSuite, if possible. Return the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * The call succeeds if the CipherSuite is available and we have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * the necessary certificates to complete the handshake. We don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * check if the CipherSuite is actually enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * If successful, this method also generates ephemeral keys if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * required for this ciphersuite. This may take some time, so this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * method should only be called if you really want to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * CipherSuite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
  1197
     * This method is called from chooseCipherSuite() in this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    boolean trySetCipherSuite(CipherSuite suite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
         * If we're resuming a session we know we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
         * support this key exchange algorithm and in fact
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
         * have already cached the result of it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
         * the session state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        if (resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1210
        if (suite.isNegotiable() == false) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1214
        // must not negotiate the obsoleted weak cipher suites.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1215
        if (protocolVersion.obsoletes(suite)) {
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
  1216
            return false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
  1217
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
  1218
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1219
        // must not negotiate unsupported cipher suites.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1220
        if (!protocolVersion.supports(suite)) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1221
            return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1222
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        KeyExchange keyExchange = suite.keyExchange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        // null out any existing references
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        privateKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        certs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        dh = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        tempPrivateKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        tempPublicKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1233
        Collection<SignatureAndHashAlgorithm> supportedSignAlgs = null;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1234
        if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1235
            if (peerSupportedSignAlgs != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1236
                supportedSignAlgs = peerSupportedSignAlgs;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1237
            } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1238
                SignatureAndHashAlgorithm algorithm = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1239
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1240
                // we may optimize the performance
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1241
                switch (keyExchange) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1242
                    // If the negotiated key exchange algorithm is one of
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1243
                    // (RSA, DHE_RSA, DH_RSA, RSA_PSK, ECDH_RSA, ECDHE_RSA),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1244
                    // behave as if client had sent the value {sha1,rsa}.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1245
                    case K_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1246
                    case K_DHE_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1247
                    case K_DH_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1248
                    // case K_RSA_PSK:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1249
                    case K_ECDH_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1250
                    case K_ECDHE_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1251
                        algorithm = SignatureAndHashAlgorithm.valueOf(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1252
                                HashAlgorithm.SHA1.value,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1253
                                SignatureAlgorithm.RSA.value, 0);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1254
                        break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1255
                    // If the negotiated key exchange algorithm is one of
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1256
                    // (DHE_DSS, DH_DSS), behave as if the client had
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1257
                    // sent the value {sha1,dsa}.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1258
                    case K_DHE_DSS:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1259
                    case K_DH_DSS:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1260
                        algorithm = SignatureAndHashAlgorithm.valueOf(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1261
                                HashAlgorithm.SHA1.value,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1262
                                SignatureAlgorithm.DSA.value, 0);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1263
                        break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1264
                    // If the negotiated key exchange algorithm is one of
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1265
                    // (ECDH_ECDSA, ECDHE_ECDSA), behave as if the client
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1266
                    // had sent value {sha1,ecdsa}.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1267
                    case K_ECDH_ECDSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1268
                    case K_ECDHE_ECDSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1269
                        algorithm = SignatureAndHashAlgorithm.valueOf(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1270
                                HashAlgorithm.SHA1.value,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1271
                                SignatureAlgorithm.ECDSA.value, 0);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1272
                        break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1273
                    default:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1274
                        // no peer supported signature algorithms
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1275
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1276
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1277
                if (algorithm == null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1278
                    supportedSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1279
                        Collections.<SignatureAndHashAlgorithm>emptySet();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1280
                } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1281
                    supportedSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1282
                        new ArrayList<SignatureAndHashAlgorithm>(1);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1283
                    supportedSignAlgs.add(algorithm);
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1284
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1285
                    supportedSignAlgs =
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1286
                            SignatureAndHashAlgorithm.getSupportedAlgorithms(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1287
                                algorithmConstraints, supportedSignAlgs);
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1288
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1289
                    // May be no default activated signature algorithm, but
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1290
                    // let the following process make the final decision.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1291
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1292
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1293
                // Sets the peer supported signature algorithm to use in KM
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1294
                // temporarily.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1295
                session.setPeerSupportedSignatureAlgorithms(supportedSignAlgs);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1296
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1297
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1298
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        switch (keyExchange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        case K_RSA:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1301
            // need RSA certs for authentication
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1302
            if (setupPrivateKeyAndChain("RSA") == false) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1303
                return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1304
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1305
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        case K_RSA_EXPORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            // need RSA certs for authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            if (setupPrivateKeyAndChain("RSA") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1312
            try {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1313
               if (JsseJce.getRSAKeyLength(certs[0].getPublicKey()) > 512) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1314
                    if (!setupEphemeralRSAKeys(suite.exportable)) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1315
                        return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1316
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1317
               }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1318
            } catch (RuntimeException e) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1319
                // could not determine keylength, ignore key
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1320
                return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1321
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1322
            break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1323
        case K_DHE_RSA:
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1324
            // need RSA certs for authentication
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1325
            if (setupPrivateKeyAndChain("RSA") == false) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1326
                return false;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1327
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1328
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1329
            // get preferable peer signature algorithm for server key exchange
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1330
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1331
                preferableSignatureAlgorithm =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1332
                    SignatureAndHashAlgorithm.getPreferableAlgorithm(
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1333
                                        supportedSignAlgs, "RSA", privateKey);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1334
                if (preferableSignatureAlgorithm == null) {
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1335
                    if ((debug != null) && Debug.isOn("handshake")) {
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1336
                        System.out.println(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1337
                                "No signature and hash algorithm for cipher " +
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1338
                                suite);
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1339
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1342
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1343
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1344
            setupEphemeralDHKeys(suite.exportable, privateKey);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1345
            break;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1346
        case K_ECDHE_RSA:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1347
            // need RSA certs for authentication
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1348
            if (setupPrivateKeyAndChain("RSA") == false) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1349
                return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1350
            }
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1351
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1352
            // get preferable peer signature algorithm for server key exchange
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1353
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1354
                preferableSignatureAlgorithm =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1355
                    SignatureAndHashAlgorithm.getPreferableAlgorithm(
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 9499
diff changeset
  1356
                                        supportedSignAlgs, "RSA", privateKey);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1357
                if (preferableSignatureAlgorithm == null) {
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1358
                    if ((debug != null) && Debug.isOn("handshake")) {
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1359
                        System.out.println(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1360
                                "No signature and hash algorithm for cipher " +
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1361
                                suite);
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1362
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1365
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1366
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1367
            if (setupEphemeralECDHKeys() == false) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1368
                return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1369
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        case K_DHE_DSS:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1372
            // get preferable peer signature algorithm for server key exchange
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1373
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1374
                preferableSignatureAlgorithm =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1375
                    SignatureAndHashAlgorithm.getPreferableAlgorithm(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1376
                                                supportedSignAlgs, "DSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1377
                if (preferableSignatureAlgorithm == null) {
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1378
                    if ((debug != null) && Debug.isOn("handshake")) {
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1379
                        System.out.println(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1380
                                "No signature and hash algorithm for cipher " +
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1381
                                suite);
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1382
                    }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1383
                    return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1384
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1385
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            // need DSS certs for authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            if (setupPrivateKeyAndChain("DSA") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            }
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1391
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1392
            setupEphemeralDHKeys(suite.exportable, privateKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        case K_ECDHE_ECDSA:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1395
            // get preferable peer signature algorithm for server key exchange
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1396
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1397
                preferableSignatureAlgorithm =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1398
                    SignatureAndHashAlgorithm.getPreferableAlgorithm(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1399
                                            supportedSignAlgs, "ECDSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1400
                if (preferableSignatureAlgorithm == null) {
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1401
                    if ((debug != null) && Debug.isOn("handshake")) {
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1402
                        System.out.println(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1403
                                "No signature and hash algorithm for cipher " +
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1404
                                suite);
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1405
                    }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1406
                    return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1407
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1408
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1409
34354
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1410
            // need EC cert
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1411
            if (setupPrivateKeyAndChain("EC") == false) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            if (setupEphemeralECDHKeys() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        case K_ECDH_RSA:
34354
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1419
            // need EC cert
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1420
            if (setupPrivateKeyAndChain("EC") == false) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            setupStaticECDHKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        case K_ECDH_ECDSA:
34354
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1426
            // need EC cert
1599006b7f3a 8136442: Don't tie Certificate signature algorithms to ciphersuites
xuelei
parents: 32649
diff changeset
  1427
            if (setupPrivateKeyAndChain("EC") == false) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            setupStaticECDHKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        case K_DH_ANON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            // no certs needed for anonymous
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1434
            setupEphemeralDHKeys(suite.exportable, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        case K_ECDH_ANON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            // no certs needed for anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            if (setupEphemeralECDHKeys() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        default:
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1443
            ClientKeyExchangeService p =
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1444
                    ClientKeyExchangeService.find(keyExchange.name);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1445
            if (p == null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1446
                // internal error, unknown key exchange
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1447
                throw new RuntimeException(
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 34380
diff changeset
  1448
                        "Unrecognized cipherSuite: " + suite);
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1449
            }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1450
            // need service creds
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1451
            if (serviceCreds == null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1452
                AccessControlContext acc = getAccSE();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1453
                serviceCreds = p.getServiceCreds(acc);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1454
                if (serviceCreds != null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1455
                    if (debug != null && Debug.isOn("handshake")) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1456
                        System.out.println("Using serviceCreds");
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1457
                    }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1458
                }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1459
                if (serviceCreds == null) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1460
                    return false;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1461
                }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1462
            }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1463
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        setCipherSuite(suite);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1466
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1467
        // set the peer implicit supported signature algorithms
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1468
        if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1469
            if (peerSupportedSignAlgs == null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1470
                setPeerSupportedSignAlgs(supportedSignAlgs);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1471
                // we had alreay update the session
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1472
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1473
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * Get some "ephemeral" RSA keys for this context. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * generating them if it's not already been done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * Note that we currently do not implement any ciphersuites that use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * strong ephemeral RSA. (We do not support the EXPORT1024 ciphersuites
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * and standard RSA ciphersuites prohibit ephemeral mode for some reason)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * This means that export is always true and 512 bit keys are generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    private boolean setupEphemeralRSAKeys(boolean export) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        KeyPair kp = sslContext.getEphemeralKeyManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                        getRSAKeyPair(export, sslContext.getSecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        if (kp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            tempPublicKey = kp.getPublic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            tempPrivateKey = kp.getPrivate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * Acquire some "ephemeral" Diffie-Hellman  keys for this handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * We don't reuse these, for improved forward secrecy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     */
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1502
    private void setupEphemeralDHKeys(boolean export, Key key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        /*
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1504
         * 768 bits ephemeral DH private keys were used to be used in
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1505
         * ServerKeyExchange except that exportable ciphers max out at 512
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1506
         * bits modulus values. We still adhere to this behavior in legacy
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1507
         * mode (system property "jdk.tls.ephemeralDHKeySize" is defined
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1508
         * as "legacy").
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1509
         *
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1510
         * Old JDK (JDK 7 and previous) releases don't support DH keys bigger
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1511
         * than 1024 bits. We have to consider the compatibility requirement.
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1512
         * 1024 bits DH key is always used for non-exportable cipher suites
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1513
         * in default mode (system property "jdk.tls.ephemeralDHKeySize"
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1514
         * is not defined).
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1515
         *
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1516
         * However, if applications want more stronger strength, setting
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1517
         * system property "jdk.tls.ephemeralDHKeySize" to "matched"
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1518
         * is a workaround to use ephemeral DH key which size matches the
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1519
         * corresponding authentication key. For example, if the public key
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1520
         * size of an authentication certificate is 2048 bits, then the
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1521
         * ephemeral DH key size should be 2048 bits accordingly unless
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1522
         * the cipher suite is exportable.  This key sizing scheme keeps
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1523
         * the cryptographic strength consistent between authentication
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1524
         * keys and key-exchange keys.
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1525
         *
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1526
         * Applications may also want to customize the ephemeral DH key size
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1527
         * to a fixed length for non-exportable cipher suites. This can be
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1528
         * approached by setting system property "jdk.tls.ephemeralDHKeySize"
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1529
         * to a valid positive integer between 1024 and 8192 bits, inclusive.
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1530
         *
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1531
         * Note that the minimum acceptable key size is 1024 bits except
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1532
         * exportable cipher suites or legacy mode.
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1533
         *
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1534
         * Note that per RFC 2246, the key size limit of DH is 512 bits for
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1535
         * exportable cipher suites.  Because of the weakness, exportable
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1536
         * cipher suites are deprecated since TLS v1.1 and they are not
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1537
         * enabled by default in Oracle provider. The legacy behavior is
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1538
         * reserved and 512 bits DH key is always used for exportable
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1539
         * cipher suites.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
         */
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1541
        int keySize = export ? 512 : 1024;           // default mode
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1542
        if (!export) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1543
            if (useLegacyEphemeralDHKeys) {          // legacy mode
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1544
                keySize = 768;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1545
            } else if (useSmartEphemeralDHKeys) {    // matched mode
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1546
                if (key != null) {
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1547
                    int ks = KeyUtil.getKeySize(key);
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1548
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1549
                    // DH parameter generation can be extremely slow, make
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1550
                    // sure to use one of the supported pre-computed DH
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1551
                    // parameters (see DHCrypt class).
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1552
                    //
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1553
                    // Old deployed applications may not be ready to support
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1554
                    // DH key sizes bigger than 2048 bits.  Please DON'T use
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1555
                    // value other than 1024 and 2048 at present.  May improve
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1556
                    // the underlying providers and key size limit in the
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1557
                    // future when the compatibility and interoperability
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents: 36442
diff changeset
  1558
                    // impact is limited.
20539
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1559
                    //
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1560
                    // keySize = ks <= 1024 ? 1024 : (ks >= 2048 ? 2048 : ks);
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1561
                    keySize = ks <= 1024 ? 1024 : 2048;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1562
                } // Otherwise, anonymous cipher suites, 1024-bit is used.
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1563
            } else if (customizedDHKeySize > 0) {    // customized mode
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1564
                keySize = customizedDHKeySize;
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1565
            }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1566
        }
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1567
cbff16f695c6 6956398: make ephemeral DH key match the length of the certificate key
xuelei
parents: 19823
diff changeset
  1568
        dh = new DHCrypt(keySize, sslContext.getSecureRandom());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    // Setup the ephemeral ECDH parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    // If we cannot continue because we do not support any of the curves that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    // the client requested, return false. Otherwise (all is well), return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    private boolean setupEphemeralECDHKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        int index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        if (supportedCurves != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            // if the client sent the supported curves extension, pick the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            // first one that we support;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            for (int curveId : supportedCurves.curveIds()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                if (SupportedEllipticCurvesExtension.isSupported(curveId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                    index = curveId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            if (index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                // no match found, cannot use this ciphersuite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            // pick our preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            index = SupportedEllipticCurvesExtension.DEFAULT.curveIds()[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        String oid = SupportedEllipticCurvesExtension.getCurveOid(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        ecdh = new ECDHCrypt(oid, sslContext.getSecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    private void setupStaticECDHKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        // don't need to check whether the curve is supported, already done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        // in setupPrivateKeyAndChain().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        ecdh = new ECDHCrypt(privateKey, certs[0].getPublicKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * Retrieve the server key and certificate for the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * from the KeyManager and set the instance variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * @return true if successful, false if not available or invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    private boolean setupPrivateKeyAndChain(String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        X509ExtendedKeyManager km = sslContext.getX509KeyManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        String alias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        if (conn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            alias = km.chooseServerAlias(algorithm, null, conn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            alias = km.chooseEngineServerAlias(algorithm, null, engine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        if (alias == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        PrivateKey tempPrivateKey = km.getPrivateKey(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        if (tempPrivateKey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        X509Certificate[] tempCerts = km.getCertificateChain(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        if ((tempCerts == null) || (tempCerts.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        String keyAlgorithm = algorithm.split("_")[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        PublicKey publicKey = tempCerts[0].getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        if ((tempPrivateKey.getAlgorithm().equals(keyAlgorithm) == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                || (publicKey.getAlgorithm().equals(keyAlgorithm) == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        // For ECC certs, check whether we support the EC domain parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        // If the client sent a SupportedEllipticCurves ClientHello extension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        // check against that too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        if (keyAlgorithm.equals("EC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            if (publicKey instanceof ECPublicKey == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            ECParameterSpec params = ((ECPublicKey)publicKey).getParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            int index = SupportedEllipticCurvesExtension.getCurveIndex(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            if (SupportedEllipticCurvesExtension.isSupported(index) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            if ((supportedCurves != null) && !supportedCurves.contains(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        this.privateKey = tempPrivateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        this.certs = tempCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1656
    /*
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1657
     * Returns premaster secret for external key exchange services.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     */
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1659
    private SecretKey clientKeyExchange(ClientKeyExchange mesg)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        // Record the principals involved in exchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        session.setPeerPrincipal(mesg.getPeerPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        session.setLocalPrincipal(mesg.getLocalPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1670
        return mesg.clientKeyExchange();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     * Diffie Hellman key exchange is used when the server presented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * D-H parameters in its certificate (signed using RSA or DSS/DSA),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * or else the server presented no certificate but sent D-H params
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * in a ServerKeyExchange message.  Use of D-H is specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     * cipher suite chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     * The message optionally contains the client's D-H public key (if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     * it wasn't not sent in a client certificate).  As always with D-H,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     * if a client and a server have each other's D-H public keys and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     * they use common algorithm parameters, they have a shared key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
     * that's derived via the D-H calculation.  That key becomes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
     * pre-master secret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    private SecretKey clientKeyExchange(DHClientKeyExchange mesg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        }
31712
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1693
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1694
        BigInteger publicKeyValue = mesg.getClientPublicKey();
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1695
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1696
        // check algorithm constraints
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1697
        dh.checkConstraints(algorithmConstraints, publicKeyValue);
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1698
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1699
        return dh.getAgreedSecret(publicKeyValue, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    private SecretKey clientKeyExchange(ECDHClientKeyExchange mesg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        }
31712
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1708
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1709
        byte[] publicPoint = mesg.getEncodedPoint();
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1710
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1711
        // check algorithm constraints
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1712
        ecdh.checkConstraints(algorithmConstraints, publicPoint);
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1713
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 31695
diff changeset
  1714
        return ecdh.getAgreedSecret(publicPoint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * Client wrote a message to verify the certificate it sent earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * Note that this certificate isn't involved in key exchange.  Client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * authentication messages are included in the checksums used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * validate the handshake (e.g. Finished messages).  Other than that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * the _exact_ identity of the client is less fundamental to protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * security than its role in selecting keys via the pre-master secret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    private void clientCertificateVerify(CertificateVerify mesg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1733
        if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1734
            SignatureAndHashAlgorithm signAlg =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1735
                mesg.getPreferableSignatureAlgorithm();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1736
            if (signAlg == null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1737
                throw new SSLHandshakeException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1738
                        "Illegal CertificateVerify message");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1739
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1740
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1741
            String hashAlg =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1742
                SignatureAndHashAlgorithm.getHashAlgorithmName(signAlg);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1743
            if (hashAlg == null || hashAlg.length() == 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1744
                throw new SSLHandshakeException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1745
                        "No supported hash algorithm");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1746
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1747
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1748
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            PublicKey publicKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                session.getPeerCertificates()[0].getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            boolean valid = mesg.verify(protocolVersion, handshakeHash,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                                        publicKey, session.getMasterSecret());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            if (valid == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                fatalSE(Alerts.alert_bad_certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                            "certificate verify message signature error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            fatalSE(Alerts.alert_bad_certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                "certificate verify format error", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        // reset the flag for clientCertificateVerify message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        needClientVerify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * Client writes "finished" at the end of its handshake, after cipher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * spec is changed.   We verify it and then send ours.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * When we're resuming a session, we'll have already sent our own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * Finished message so just the verification is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    private void clientFinished(Finished mesg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
         * Verify if client did send the certificate when client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
         * authentication was required, otherwise server should not proceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
         */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1785
        if (doClientAuth == ClientAuthType.CLIENT_AUTH_REQUIRED) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
           // get X500Principal of the end-entity certificate for X509-based
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents: 30904
diff changeset
  1787
           // ciphersuites, or Kerberos principal for Kerberos ciphersuites, etc
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
           session.getPeerPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
         * Verify if client did send clientCertificateVerify message following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
         * the client Certificate, otherwise server should not proceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        if (needClientVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                fatalSE(Alerts.alert_handshake_failure,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                        "client did not send certificate verify message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
         * Verify the client's message with the "before" digest of messages,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
         * and forget about continuing to use that digest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
         */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1804
        boolean verified = mesg.verify(handshakeHash, Finished.CLIENT,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1805
            session.getMasterSecret());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        if (!verified) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            fatalSE(Alerts.alert_handshake_failure,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                        "client 'finished' message doesn't verify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            // NOTREACHED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        /*
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1814
         * save client verify data for secure renegotiation
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1815
         */
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1816
        if (secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1817
            clientVerifyData = mesg.getVerifyData();
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1818
        }
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1819
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1820
        /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
         * OK, it verified.  If we're doing the full handshake, add that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
         * "Finished" message to the hash of handshake messages, then send
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
         * the change_cipher_spec and Finished message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        if (!resumingSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            sendChangeCipherAndFinish(true);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1827
        } else {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1828
            handshakeFinished = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
         * Update the session cache only after the handshake completed, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
         * we're open to an attack against a partially completed handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        session.setLastAccessedTime(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        if (!resumingSession && session.isRejoinable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            ((SSLSessionContextImpl)sslContext.engineGetServerSessionContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                .put(session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            if (debug != null && Debug.isOn("session")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                    "%% Cached server session: " + session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        } else if (!resumingSession &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                debug != null && Debug.isOn("session")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                "%% Didn't cache non-resumable server session: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                + session);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * Compute finished message with the "server" digest (and then forget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * about that digest, it can't be used again).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    private void sendChangeCipherAndFinish(boolean finishedTag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1858
        // Reload if this message has been reserved.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1859
        handshakeHash.reload();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        Finished mesg = new Finished(protocolVersion, handshakeHash,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1862
            Finished.SERVER, session.getMasterSecret(), cipherSuite);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
         * Send the change_cipher_spec record; then our Finished handshake
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
         * message will be the last handshake message.  Flush, and now we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
         * are ready for application data!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        sendChangeCipherSpec(mesg, finishedTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        /*
6856
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1872
         * save server verify data for secure renegotiation
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1873
         */
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1874
        if (secureRenegotiation) {
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1875
            serverVerifyData = mesg.getVerifyData();
533f4ad71f88 6914943: Implement final TLS renegotiation fix
xuelei
parents: 5506
diff changeset
  1876
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * Returns a HelloRequest message to kickstart renegotiations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1883
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    HandshakeMessage getKickstartMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        return new HelloRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * Fault detected during handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1892
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    void handshakeAlert(byte description) throws SSLProtocolException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        String message = Alerts.alertDescription(description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            System.out.println("SSL -- handshake alert:  "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
         * It's ok to get a no_certificate alert from a client of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
         * we *requested* authentication information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
         * However, if we *required* it, then this is not acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
         * Anyone calling getPeerCertificates() on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
         * session will get an SSLPeerUnverifiedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        if ((description == Alerts.alert_no_certificate) &&
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1911
                (doClientAuth == ClientAuthType.CLIENT_AUTH_REQUESTED)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        throw new SSLProtocolException("handshake alert: " + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * RSA key exchange is normally used.  The client encrypts a "pre-master
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * secret" with the server's public key, from the Certificate (or else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * ServerKeyExchange) message that was sent to it by the server.  That's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * decrypted using the private key before we get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1924
    private SecretKey clientKeyExchange(RSAClientKeyExchange mesg)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1925
            throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        return mesg.preMaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * Verify the certificate sent by the client. We'll only get one if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * sent a CertificateRequest to request client authentication. If we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * are in TLS mode, the client may send a message with no certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * to indicate it does not have an appropriate chain. (In SSLv3 mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * it would send a no certificate alert).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    private void clientCertificate(CertificateMsg mesg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        if (debug != null && Debug.isOn("handshake")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            mesg.print(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        X509Certificate[] peerCerts = mesg.getCertificateChain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        if (peerCerts.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
             * If the client authentication is only *REQUESTED* (e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
             * not *REQUIRED*, this is an acceptable condition.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
             */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28550
diff changeset
  1952
            if (doClientAuth == ClientAuthType.CLIENT_AUTH_REQUESTED) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                fatalSE(Alerts.alert_bad_certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                    "null cert chain");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        // ask the trust manager to verify the chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        X509TrustManager tm = sslContext.getX509TrustManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            // find out the types of client authentication used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            PublicKey key = peerCerts[0].getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            String keyAlgorithm = key.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            String authType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            if (keyAlgorithm.equals("RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                authType = "RSA";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            } else if (keyAlgorithm.equals("DSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                authType = "DSA";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            } else if (keyAlgorithm.equals("EC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                authType = "EC";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                // unknown public key type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                authType = "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            if (tm instanceof X509ExtendedTrustManager) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1980
                if (conn != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1981
                    ((X509ExtendedTrustManager)tm).checkClientTrusted(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1982
                        peerCerts.clone(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                        authType,
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1984
                        conn);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1985
                } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1986
                    ((X509ExtendedTrustManager)tm).checkClientTrusted(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1987
                        peerCerts.clone(),
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1988
                        authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1989
                        engine);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1990
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            } else {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1992
                // Unlikely to happen, because we have wrapped the old
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1993
                // X509TrustManager with the new X509ExtendedTrustManager.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1994
                throw new CertificateException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
  1995
                    "Improper X509TrustManager implementation");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            // This will throw an exception, so include the original error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            fatalSE(Alerts.alert_certificate_unknown, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        // set the flag for clientCertificateVerify message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        needClientVerify = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        session.setPeerCertificates(peerCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    }
36442
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2006
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2007
    private StaplingParameters processStapling(ClientHello mesg) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2008
        StaplingParameters params = null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2009
        ExtensionType ext;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2010
        StatusRequestType type = null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2011
        StatusRequest req = null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2012
        Map<X509Certificate, byte[]> responses;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2013
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2014
        // If this feature has not been enabled, then no more processing
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2015
        // is necessary.  Also we will only staple if we're doing a full
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2016
        // handshake.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2017
        if (!sslContext.isStaplingEnabled(false) || resumingSession) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2018
            return null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2019
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2020
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2021
        // Check if the client has asserted the status_request[_v2] extension(s)
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2022
        CertStatusReqExtension statReqExt = (CertStatusReqExtension)
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2023
                    mesg.extensions.get(ExtensionType.EXT_STATUS_REQUEST);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2024
        CertStatusReqListV2Extension statReqExtV2 =
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2025
                (CertStatusReqListV2Extension)mesg.extensions.get(
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2026
                        ExtensionType.EXT_STATUS_REQUEST_V2);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2027
        // Keep processing only if either status_request or status_request_v2
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2028
        // has been sent in the ClientHello.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2029
        if (statReqExt == null && statReqExtV2 == null) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2030
            return null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2031
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2032
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2033
        // Determine which type of stapling we are doing and assert the
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2034
        // proper extension in the server hello.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2035
        // Favor status_request_v2 over status_request and ocsp_multi
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2036
        // over ocsp.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2037
        // If multiple ocsp or ocsp_multi types exist, select the first
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2038
        // instance of a given type
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2039
        ext = ExtensionType.EXT_STATUS_REQUEST;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2040
        if (statReqExtV2 != null) {             // RFC 6961 stapling
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2041
            ext = ExtensionType.EXT_STATUS_REQUEST_V2;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2042
            List<CertStatusReqItemV2> reqItems =
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2043
                    statReqExtV2.getRequestItems();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2044
            int ocspIdx = -1;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2045
            int ocspMultiIdx = -1;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2046
            for (int pos = 0; pos < reqItems.size(); pos++) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2047
                CertStatusReqItemV2 item = reqItems.get(pos);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2048
                if (ocspIdx < 0 && item.getType() ==
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2049
                        StatusRequestType.OCSP) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2050
                    ocspIdx = pos;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2051
                } else if (ocspMultiIdx < 0 && item.getType() ==
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2052
                        StatusRequestType.OCSP_MULTI) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2053
                    ocspMultiIdx = pos;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2054
                }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2055
            }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2056
            if (ocspMultiIdx >= 0) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2057
                type = reqItems.get(ocspMultiIdx).getType();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2058
                req = reqItems.get(ocspMultiIdx).getRequest();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2059
            } else if (ocspIdx >= 0) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2060
                type = reqItems.get(ocspIdx).getType();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2061
                req = reqItems.get(ocspIdx).getRequest();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2062
            }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2063
        } else {                                // RFC 6066 stapling
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2064
            type = StatusRequestType.OCSP;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2065
            req = statReqExt.getRequest();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2066
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2067
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2068
        // If, after walking through the extensions we were unable to
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2069
        // find a suitable StatusRequest, then stapling is disabled.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2070
        // Both statReqType and statReqData must have been set to continue.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2071
        if (type == null || req == null) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2072
            return null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2073
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2074
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2075
        // Get the OCSP responses from the StatusResponseManager
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2076
        StatusResponseManager statRespMgr =
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2077
                sslContext.getStatusResponseManager();
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2078
        if (statRespMgr != null) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2079
            responses = statRespMgr.get(type, req, certs, statusRespTimeout,
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2080
                    TimeUnit.MILLISECONDS);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2081
            if (!responses.isEmpty()) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2082
                // If this RFC 6066-style stapling (SSL cert only) then the
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2083
                // response cannot be zero length
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2084
                if (type == StatusRequestType.OCSP) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2085
                    byte[] respDER = responses.get(certs[0]);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2086
                    if (respDER == null || respDER.length <= 0) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2087
                        return null;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2088
                    }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2089
                }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2090
                params = new StaplingParameters(ext, type, req, responses);
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2091
            }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2092
        } else {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2093
            // This should not happen, but if lazy initialization of the
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2094
            // StatusResponseManager doesn't occur we should turn off stapling.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2095
            if (debug != null && Debug.isOn("handshake")) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2096
                System.out.println("Warning: lazy initialization " +
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2097
                        "of the StatusResponseManager failed.  " +
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2098
                        "Stapling has been disabled.");
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2099
            }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2100
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2101
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2102
        return params;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2103
    }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2104
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2105
    /**
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2106
     * Inner class used to hold stapling parameters needed by the handshaker
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2107
     * when stapling is active.
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2108
     */
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2109
    private class StaplingParameters {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2110
        private final ExtensionType statusRespExt;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2111
        private final StatusRequestType statReqType;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2112
        private final StatusRequest statReqData;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2113
        private final Map<X509Certificate, byte[]> responseMap;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2114
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2115
        StaplingParameters(ExtensionType ext, StatusRequestType type,
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2116
                StatusRequest req, Map<X509Certificate, byte[]> responses) {
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2117
            statusRespExt = ext;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2118
            statReqType = type;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2119
            statReqData = req;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2120
            responseMap = responses;
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2121
        }
ce858cc19004 8132942: ServerHandshaker should not throw SSLHandshakeException when CertificateStatus constructor is called with invalid arguments
jnimeh
parents: 36132
diff changeset
  2122
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
}