jdk/src/java.base/share/classes/sun/security/ssl/RSAClientKeyExchange.java
author igerasim
Fri, 02 Oct 2015 11:50:20 +0300
changeset 35287 e59d934ce2ba
parent 35279 5afd2941dfb7
child 36661 044bf6a5474a
permissions -rw-r--r--
8134605: Partial rework of the fix for 8081297 Reviewed-by: xuelei, coffeys, valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
35287
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
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.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec;
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 14212
diff changeset
    37
import sun.security.util.KeyUtil;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This is the client key exchange message (CLIENT --> SERVER) used with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * all RSA key exchanges; it holds the RSA-encrypted pre-master secret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The message is encrypted using PKCS #1 block type 02 encryption with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * server's public key.  The padding and resulting message size is a function
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of this server's public key modulus size, but the pre-master secret is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * always exactly 48 bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
final class RSAClientKeyExchange extends HandshakeMessage {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The following field values were encrypted with the server's public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * key (or temp key from server key exchange msg) and are presented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * here in DECRYPTED form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private ProtocolVersion protocolVersion; // preMaster [0,1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    SecretKey preMaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private byte[] encrypted;           // same size as public modulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Client randomly creates a pre-master secret and encrypts it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * using the server's RSA public key; only the server can decrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * it, using its RSA private key.  Result is the same size as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * server's public key, and uses PKCS #1 block format 02.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
27804
4659e70271c4 8066617: Suppress deprecation warnings in java.base module
darcy
parents: 25859
diff changeset
    66
    @SuppressWarnings("deprecation")
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    67
    RSAClientKeyExchange(ProtocolVersion protocolVersion,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    68
            ProtocolVersion maxVersion,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            SecureRandom generator, PublicKey publicKey) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (publicKey.getAlgorithm().equals("RSA") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            throw new SSLKeyException("Public key not of type RSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.protocolVersion = protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 27804
diff changeset
    76
            String s = protocolVersion.useTLS12PlusSpec() ?
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 27804
diff changeset
    77
                "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret";
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 7039
diff changeset
    78
            KeyGenerator kg = JsseJce.getKeyGenerator(s);
23733
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 22309
diff changeset
    79
            kg.init(new TlsRsaPremasterSecretParameterSpec(
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 22309
diff changeset
    80
                    maxVersion.v, protocolVersion.v), generator);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            preMaster = kg.generateKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            cipher.init(Cipher.WRAP_MODE, publicKey, generator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            encrypted = cipher.wrap(preMaster);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw (SSLKeyException)new SSLKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                ("RSA premaster secret error").initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Server gets the PKCS #1 (block format 02) data, decrypts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * it with its private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
27804
4659e70271c4 8066617: Suppress deprecation warnings in java.base module
darcy
parents: 25859
diff changeset
    96
    @SuppressWarnings("deprecation")
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    97
    RSAClientKeyExchange(ProtocolVersion currentVersion,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    98
            ProtocolVersion maxVersion,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    99
            SecureRandom generator, HandshakeInStream input,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            int messageSize, PrivateKey privateKey) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (privateKey.getAlgorithm().equals("RSA") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throw new SSLKeyException("Private key not of type RSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 27804
diff changeset
   106
        if (currentVersion.useTLS10PlusSpec()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            encrypted = input.getBytes16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            encrypted = new byte [messageSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (input.read(encrypted) != messageSize) {
22309
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   111
                throw new SSLProtocolException(
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   112
                        "SSL: read PreMasterSecret: short read");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
35279
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   116
        byte[] encoded = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            Cipher cipher = JsseJce.getCipher(JsseJce.CIPHER_RSA_PKCS1);
35287
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   119
            boolean needFailover = !KeyUtil.isOracleJCEProvider(
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   120
                    cipher.getProvider().getName());
35279
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   121
            if (needFailover) {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   122
                cipher.init(Cipher.DECRYPT_MODE, privateKey);
35287
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   123
                boolean failed = false;
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   124
                try {
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   125
                    encoded = cipher.doFinal(encrypted);
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   126
                } catch (BadPaddingException bpe) {
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   127
                    // Note: encoded == null
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   128
                    failed = true;
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   129
                }
35279
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   130
                encoded = KeyUtil.checkTlsPreMasterSecretKey(
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   131
                                maxVersion.v, currentVersion.v,
35287
e59d934ce2ba 8134605: Partial rework of the fix for 8081297
igerasim
parents: 35279
diff changeset
   132
                                generator, encoded, failed);
35279
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   133
                preMaster = generatePreMasterSecret(
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   134
                                maxVersion.v, currentVersion.v,
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   135
                                encoded, generator);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   136
            } else {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   137
                cipher.init(Cipher.UNWRAP_MODE, privateKey,
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   138
                        new TlsRsaPremasterSecretParameterSpec(
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   139
                                maxVersion.v, currentVersion.v),
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   140
                        generator);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   141
                preMaster = (SecretKey)cipher.unwrap(encrypted,
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   142
                        "TlsRsaPremasterSecret", Cipher.SECRET_KEY);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   143
            }
23733
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 22309
diff changeset
   144
        } catch (InvalidKeyException ibk) {
b9b80421cfa7 8028192: Use of PKCS11-NSS provider in FIPS mode broken
xuelei
parents: 22309
diff changeset
   145
            // the message is too big to process with RSA
22309
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   146
            throw new SSLProtocolException(
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   147
                "Unable to process PreMasterSecret, may be too big");
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   148
        } catch (Exception e) {
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   149
            // unlikely to happen, otherwise, must be a provider exception
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   150
            if (debug != null && Debug.isOn("handshake")) {
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   151
                System.out.println("RSA premaster secret decryption error:");
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   152
                e.printStackTrace(System.out);
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   153
            }
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   154
            throw new RuntimeException("Could not generate dummy secret", e);
1990211a42e5 8023069: Enhance TLS connections
xuelei
parents: 16100
diff changeset
   155
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
35279
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   158
    // generate a premaster secret with the specified version number
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   159
    @SuppressWarnings("deprecation")
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   160
    private static SecretKey generatePreMasterSecret(
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   161
            int clientVersion, int serverVersion,
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   162
            byte[] encodedSecret, SecureRandom generator) {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   163
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   164
        if (debug != null && Debug.isOn("handshake")) {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   165
            System.out.println("Generating a premaster secret");
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   166
        }
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   167
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   168
        try {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   169
            String s = ((clientVersion >= ProtocolVersion.TLS12.v) ?
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   170
                "SunTls12RsaPremasterSecret" : "SunTlsRsaPremasterSecret");
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   171
            KeyGenerator kg = JsseJce.getKeyGenerator(s);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   172
            kg.init(new TlsRsaPremasterSecretParameterSpec(
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   173
                    clientVersion, serverVersion, encodedSecret),
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   174
                    generator);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   175
            return kg.generateKey();
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   176
        } catch (InvalidAlgorithmParameterException |
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   177
                NoSuchAlgorithmException iae) {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   178
            // unlikely to happen, otherwise, must be a provider exception
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   179
            if (debug != null && Debug.isOn("handshake")) {
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   180
                System.out.println("RSA premaster secret generation error:");
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   181
                iae.printStackTrace(System.out);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   182
            }
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   183
            throw new RuntimeException("Could not generate premaster secret", iae);
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   184
        }
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   185
    }
5afd2941dfb7 8081297: SSL Problem with Tomcat
igerasim
parents: 30904
diff changeset
   186
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   187
    @Override
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   188
    int messageType() {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   189
        return ht_client_key_exchange;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   190
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   191
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   192
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    int messageLength() {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 27804
diff changeset
   194
        if (protocolVersion.useTLS10PlusSpec()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return encrypted.length + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return encrypted.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   201
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    void send(HandshakeOutStream s) throws IOException {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 27804
diff changeset
   203
        if (protocolVersion.useTLS10PlusSpec()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            s.putBytes16(encrypted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            s.write(encrypted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   210
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    void print(PrintStream s) throws IOException {
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   212
        s.println("*** ClientKeyExchange, RSA PreMasterSecret, " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   213
                                                        protocolVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
}