jdk/test/javax/net/ssl/interop/ClientHelloInterOp.java
author xuelei
Thu, 10 Nov 2016 08:59:34 +0000
changeset 41964 46494c43f5e6
permissions -rw-r--r--
8169362: Interop automated testing with Chrome Reviewed-by: wetmore, jnimeh, asmotrak
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41964
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     1
/*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     4
 *
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     8
 *
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    13
 * accompanied this code).
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    14
 *
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    18
 *
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    21
 * questions.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    22
 */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    23
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    24
import javax.net.ssl.*;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    25
import javax.net.ssl.SSLEngineResult.*;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    26
import java.io.*;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    27
import java.nio.*;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    28
import java.security.KeyStore;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    29
import java.security.PrivateKey;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    30
import java.security.KeyFactory;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    31
import java.security.cert.Certificate;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    32
import java.security.cert.CertificateFactory;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    33
import java.security.spec.*;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    34
import java.util.Base64;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    35
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    36
public abstract class ClientHelloInterOp {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    37
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    38
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    39
     * Certificates and keys used in the test.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    40
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    41
    // Trusted certificates.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    42
    private final static String[] trustedCertStrs = {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    43
        // SHA256withECDSA, curve prime256v1
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    44
        // Validity
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    45
        //     Not Before: Nov  9 03:24:05 2016 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    46
        //     Not After : Oct 20 03:24:05 2037 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    47
        "-----BEGIN CERTIFICATE-----\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    48
        "MIICHDCCAcGgAwIBAgIJAM83C/MVp9F5MAoGCCqGSM49BAMCMDsxCzAJBgNVBAYT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    49
        "AlVTMQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2VyaXZj\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    50
        "ZTAeFw0xNjExMDkwMzI0MDVaFw0zNzEwMjAwMzI0MDVaMDsxCzAJBgNVBAYTAlVT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    51
        "MQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2VyaXZjZTBZ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    52
        "MBMGByqGSM49AgEGCCqGSM49AwEHA0IABGeQXwyeNyU4UAATfwUbMO5zaREI21Wh\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    53
        "bds6WDu+PmfK8SWsTgsgpYxBRui+fZtYqSmbdjkurvAQ3j2fvN++BtWjga0wgaow\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    54
        "HQYDVR0OBBYEFDF/OeJ82qBSRkAm1rdZUPbWfDzyMGsGA1UdIwRkMGKAFDF/OeJ8\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    55
        "2qBSRkAm1rdZUPbWfDzyoT+kPTA7MQswCQYDVQQGEwJVUzENMAsGA1UEChMESmF2\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    56
        "YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2WCCQDPNwvzFafReTAPBgNV\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    57
        "HRMBAf8EBTADAQH/MAsGA1UdDwQEAwIBBjAKBggqhkjOPQQDAgNJADBGAiEAlHQY\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    58
        "QFPlODOsjLVQYSxgeSUvYzMp0vP8naeVB9bfFG8CIQCFfrKZvhq9z3bOtlYKxs2a\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    59
        "EWUjUZ82a1JTqkP+lgHY5A==\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    60
        "-----END CERTIFICATE-----",
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    61
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    62
        // SHA256withRSA, 2048 bits
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    63
        // Validity
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    64
        //     Not Before: Nov  9 03:24:16 2016 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    65
        //     Not After : Oct 20 03:24:16 2037 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    66
        "-----BEGIN CERTIFICATE-----\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    67
        "MIIDpzCCAo+gAwIBAgIJAJAYpR2aIlA1MA0GCSqGSIb3DQEBCwUAMDsxCzAJBgNV\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    68
        "BAYTAlVTMQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2Vy\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    69
        "aXZjZTAeFw0xNjExMDkwMzI0MTZaFw0zNzEwMjAwMzI0MTZaMDsxCzAJBgNVBAYT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    70
        "AlVTMQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2VyaXZj\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    71
        "ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL+F/FTPODYzsU0Pakfp\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    72
        "lsh88YoQWZPjABhCU+HPsCTMYc8UBkaiduUzregwwVBW3D7kmec2K408krGQsxdy\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    73
        "oKJA12GL/XX1YgzDEsyBRk/gvex5lPaBIZiJ5IZlUfjLuRDGxPjtRelBTpZ7SUet\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    74
        "PJVZz6zV6hMPGO6kQzCtbzzET515EE0okIS40LkAmtWoOmVm3gRldomaZTrZ0V2L\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    75
        "MMaJGzrXYqk0SX+PYul8v+2EEHeMuaXG/XpK5xsg9gZvzpKqFQcBOdENoJHB07go\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    76
        "jCmRC328ALqr+bMyktKAuYfB+mhjmN2AU8TQx72WPpvNTXxFDYcwo+8254cCAVKB\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    77
        "e98CAwEAAaOBrTCBqjAdBgNVHQ4EFgQUlJQlQTbi8YIyiNf+SqF7LtH+gicwawYD\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    78
        "VR0jBGQwYoAUlJQlQTbi8YIyiNf+SqF7LtH+giehP6Q9MDsxCzAJBgNVBAYTAlVT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    79
        "MQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2VyaXZjZYIJ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    80
        "AJAYpR2aIlA1MA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    81
        "DQEBCwUAA4IBAQAI0lTY0YAKQ2VdoIQ6dnqolphLVWdNGiC9drHEYSn7+hmAD2r2\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    82
        "v1U/9m752TkcT74a65xKbEVuVtleD/w6i+QjALW2PYt6ivjOnnY0a9Y9a9UCa00j\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    83
        "C9415sCw84Tp9VoKtuYqzhN87bBUeABOw5dsW3z32C2N/YhprkqeF/vdx4JxulPr\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    84
        "PKze5BREXnKLA1ISoDioCPphvNMKrSpkAofb1rTCwtgt5V/WFls283L52ORmpRGO\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    85
        "Ja88ztXOz00ZGu0RQLwlmpN7m8tNgA/5MPrldyYIwegP4RSkkJlF/8+hxvvqfJhK\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    86
        "FFDa0HHQSJfR2b9628Iniw1UHOMMT6qx5EHr\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    87
        "-----END CERTIFICATE-----"
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    88
        };
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    89
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    90
    // End entity certificate.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    91
    private final static String[] endEntityCertStrs = {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    92
        // SHA256withECDSA, curve prime256v1
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    93
        // Validity
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    94
        //     Not Before: Nov  9 03:24:05 2016 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    95
        //     Not After : Jul 27 03:24:05 2036 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    96
        "-----BEGIN CERTIFICATE-----\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    97
        "MIIB1DCCAXmgAwIBAgIJAKVa+4dIUjaLMAoGCCqGSM49BAMCMDsxCzAJBgNVBAYT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    98
        "AlVTMQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2VyaXZj\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
    99
        "ZTAeFw0xNjExMDkwMzI0MDVaFw0zNjA3MjcwMzI0MDVaMFIxCzAJBgNVBAYTAlVT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   100
        "MQ0wCwYDVQQKDARKYXZhMR0wGwYDVQQLDBRTdW5KU1NFIFRlc3QgU2VyaXZjZTEV\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   101
        "MBMGA1UEAwwMSW50ZXJPcCBUZXN0MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   102
        "h4vXNUJzULq4e7fAOvF0WiWU6cllOAMus1GqTFvcnRPOChl8suZsvksO0CpZqL3h\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   103
        "jXmVX9dp1FV/rUBGLo1aG6NPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSO8V5+\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   104
        "bj0ik0T9BtJc4jLJt7m6wjAfBgNVHSMEGDAWgBQxfznifNqgUkZAJta3WVD21nw8\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   105
        "8jAKBggqhkjOPQQDAgNJADBGAiEAk7MF+L9bFRwUsbPsBCbCqH9DMdzBQR+kFDNf\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   106
        "lfn8Rs4CIQD9qWvBXd+EJqwraxiX6cftaFchn+T2HpvMboy+irMFow==\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   107
        "-----END CERTIFICATE-----",
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   108
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   109
        // SHA256withRSA, 2048 bits
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   110
        // Validity
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   111
        //     Not Before: Nov  9 03:24:16 2016 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   112
        //     Not After : Jul 27 03:24:16 2036 GMT
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   113
        "-----BEGIN CERTIFICATE-----\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   114
        "MIIDczCCAlugAwIBAgIJAPhM2oUKx0aJMA0GCSqGSIb3DQEBCwUAMDsxCzAJBgNV\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   115
        "BAYTAlVTMQ0wCwYDVQQKEwRKYXZhMR0wGwYDVQQLExRTdW5KU1NFIFRlc3QgU2Vy\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   116
        "aXZjZTAeFw0xNjExMDkwMzI0MTZaFw0zNjA3MjcwMzI0MTZaMFIxCzAJBgNVBAYT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   117
        "AlVTMQ0wCwYDVQQKDARKYXZhMR0wGwYDVQQLDBRTdW5KU1NFIFRlc3QgU2VyaXZj\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   118
        "ZTEVMBMGA1UEAwwMSW50ZXJPcCBUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   119
        "MIIBCgKCAQEA36tJaXfJ2B/AFvES+tnueyQPSNABVu9nfMdU+NEPamJ+FH7cEF8Z\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   120
        "1Spr1vlQgNzCpDUVrfnmT75rCapgz5ldA9+y+3hdfUyHjZBzzfx+6GHXLB4u6eU2\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   121
        "NATa7vqSLNbcLcfZ7/QmkFqg4JRJbX4F42kKkRJrWdKZ8UoCYC8WXWvDaZ3nUs05\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   122
        "XHe+mBJ8qMNPTbYST1jpzXPyH5CljlFGYi2mKJDTImDhwht7mu2+zvwvbJ81Gj2X\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   123
        "JUSTSf9fu0zxFcCk6RmJPw9nSVqePVlOwtNNBodfKN+k4yr+gOz1v8NmMtmEtklV\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   124
        "Sulr/J4QxI+E2Zar/C+4XjxkvstIS+PNKQIDAQABo2MwYTALBgNVHQ8EBAMCA+gw\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   125
        "HQYDVR0OBBYEFHt19CItAz0VOF0WKGWwaT4DtEsSMB8GA1UdIwQYMBaAFJSUJUE2\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   126
        "4vGCMojX/kqhey7R/oInMBIGA1UdEQEB/wQIMAaHBH8AAAEwDQYJKoZIhvcNAQEL\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   127
        "BQADggEBACKYZWvo9B9IEpCCdBba2sNo4X1NI/VEY3fyUx1lkw+Kna+1d2Ab+RCZ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   128
        "cf3Y85fcwv03hNE///wNBp+Nde4NQRDK/oiQARzWwWslfinm5d83eQwzC3cpSzt+\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   129
        "7ts6M5UlOblGsLXZI7THWO1tkgoEra9p+zezxLMmf/2MpNyZMZlVoJPM2YGxU9cN\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   130
        "ws0AyeY1gpBEdT21vjsBPdxxj6qklXVMnzS3zF8YwXyOndDYQWdjmFEknRK/qmQ2\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   131
        "gkLHrzpSpyCziecna5mGuDRdCU2dpsWiq1npEPXTq+PQGwWYcoaFTtXF8DDqhfPC\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   132
        "4Abe8gPm6MfzerdmS3RFTj9b/DIIENM=\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   133
        "-----END CERTIFICATE-----"
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   134
        };
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   135
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   136
    // Private key in the format of PKCS#8.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   137
    private final static String[] endEntityPrivateKeys = {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   138
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   139
        // EC private key related to cert endEntityCertStrs[0].
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   140
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   141
        "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgA3pmS+OrIjGyUv2F\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   142
        "K/PkyayJIePM2RTFYxNoQqmJGnihRANCAASHi9c1QnNQurh7t8A68XRaJZTpyWU4\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   143
        "Ay6zUapMW9ydE84KGXyy5my+Sw7QKlmoveGNeZVf12nUVX+tQEYujVob",
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   144
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   145
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   146
        // RSA private key related to cert endEntityCertStrs[1].
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   147
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   148
        "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDfq0lpd8nYH8AW\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   149
        "8RL62e57JA9I0AFW72d8x1T40Q9qYn4UftwQXxnVKmvW+VCA3MKkNRWt+eZPvmsJ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   150
        "qmDPmV0D37L7eF19TIeNkHPN/H7oYdcsHi7p5TY0BNru+pIs1twtx9nv9CaQWqDg\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   151
        "lEltfgXjaQqREmtZ0pnxSgJgLxZda8NpnedSzTlcd76YEnyow09NthJPWOnNc/If\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   152
        "kKWOUUZiLaYokNMiYOHCG3ua7b7O/C9snzUaPZclRJNJ/1+7TPEVwKTpGYk/D2dJ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   153
        "Wp49WU7C000Gh18o36TjKv6A7PW/w2Yy2YS2SVVK6Wv8nhDEj4TZlqv8L7hePGS+\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   154
        "y0hL480pAgMBAAECggEBAJyP1zk+IkloIBtu7+wrdCU6HoDHKMjjlzrehHoOTI4Z\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   155
        "F0vdaMkE6J4vrYCyz0kEPjKW/e/jxvT2wxHm8xEdtuApS61+mWJFmXTcMlNzdJnR\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   156
        "Mr6s+gW67fAHngA94OgGFeTtyX2PFxdgeM/6vFMqLZD7S+w0SnR7WEpvla4iB7On\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   157
        "lXqhJKVQeVc+IpByg/S4MmJb91jck73GltCaCL/b6BTrsz+zc/AY5tb8JInxjMZ9\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   158
        "jmjmA+s6l7tnBrFQfJHlF9a374lxCOtZTxyxVJjD7tQcGpsUpSHXZGdpDcT34qYT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   159
        "UGh0yp2Mc/1PfWni5gS/6UGLrYmT57RRCn5YJBJTEkkCgYEA/XPCNehFaOMSxOZh\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   160
        "OGBVhQ+eRAmdpJfMhSUsDdEdQLZyWGmZsMTHjZZrwevBX/D0dxQYDv/sAl0GZomJ\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   161
        "d6iRCHlscycwx5Q0U/EpacsgRlYHz1nMRzXqS3Ry+8O8qQlliqCLUM7SfVgzdI5/\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   162
        "ll9JMrng9NnRl8ccjEdOGK8g/MMCgYEA4eriKMfRslGY4uOQoTPbuEJSMMwQ2X4k\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   163
        "lPj1p+xSQfU9QBaWJake67oBj3vpCxqN7/VkvCIeC6LCjhLpWHCn4EkdGiqkEdWz\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   164
        "m5CHzpzVIgznzWnbt0rCVL2KdL+ihgY8KPDdsZ6tZrABHuYhsWkAu10wyvuQYM88\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   165
        "3u6yOIQn36MCgYEAk5qR1UEzAxWTPbaJkgKQa5Cf9DHBbDS3eCcg098f8SsPxquh\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   166
        "RRAkwzGCCgqZsJ0sUhkStdGXifzRGHAq7dPuuwe0ABAn2WNXYjeFjcYtQqkhnUFH\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   167
        "tYURsOXdfQAOZEdDqos691GrxjHSraO7bECL6Y3VE+Oyq3jbCFsSgU+kn28CgYBT\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   168
        "mrXZO6FJqVK33FlAns1YEgsSjeJKapklHEDkxNroF9Zz6ifkhgKwX6SGMefbORd/\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   169
        "zsNZsBKIYdI3+52pIf+uS8BeV5tiEkCmeEUZ3AYv1LDP3rX1zc++xmn/rI97o8EN\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   170
        "sZ2JRtyK3OV9RtL/MYmYzPLqm1Ah02+GXLVNnvKWmwKBgE8Ble8CzrXYuuPdGxXz\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   171
        "BZU6HnXQrmTUcgeze0tj8SDHzCfsGsaG6pHrVNkT7CKsRuCHTZLM0kXmUijLFKuP\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   172
        "5xyE257z4IbbEbs+tcbB3p28n4/47MzZkSR3kt8+FrsEMZq5oOHbFTGzgp9dhZCC\n" +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   173
        "dKUqlw5BPHdbxoWB/JpSHGCV"
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   174
        };
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   175
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   176
    // Private key names of endEntityPrivateKeys.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   177
    private final static String[] endEntityPrivateKeyNames = {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   178
        "EC",
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   179
        "RSA"
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   180
        };
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   181
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   182
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   183
     * Run the test case.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   184
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   185
    public void run() throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   186
        SSLEngine serverEngine = createServerEngine();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   187
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   188
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   189
        // Create and size the buffers appropriately.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   190
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   191
        SSLSession session = serverEngine.getSession();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   192
        ByteBuffer serverAppInbound =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   193
            ByteBuffer.allocate(session.getApplicationBufferSize());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   194
        ByteBuffer clientHello =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   195
            ByteBuffer.allocate(session.getPacketBufferSize());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   196
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   197
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   198
        // Generate a ClientHello message, and check if the server
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   199
        // engine can read it or not.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   200
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   201
        clientHello.put(createClientHelloMessage());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   202
        clientHello.flip();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   203
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   204
        SSLEngineResult serverResult =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   205
                serverEngine.unwrap(clientHello, serverAppInbound);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   206
        log("Server unwrap: ", serverResult);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   207
        runDelegatedTasks(serverResult, serverEngine);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   208
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   209
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   210
        // Generate server responses to the ClientHello request.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   211
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   212
        ByteBuffer clientNetInbound =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   213
            ByteBuffer.allocate(session.getPacketBufferSize());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   214
        ByteBuffer clientAppInbound =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   215
            ByteBuffer.wrap("Hello Client, I'm Server".getBytes());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   216
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   217
        serverResult = serverEngine.wrap(clientAppInbound, clientNetInbound);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   218
        log("Server wrap: ", serverResult);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   219
        runDelegatedTasks(serverResult, serverEngine);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   220
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   221
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   222
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   223
     * Create a ClientHello message.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   224
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   225
    abstract protected byte[] createClientHelloMessage();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   226
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   227
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   228
     * Create an instance of SSLContext for client use.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   229
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   230
    protected SSLContext createClientSSLContext() throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   231
        return createSSLContext(trustedCertStrs, null, null, null);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   232
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   233
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   234
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   235
     * Create an instance of SSLContext for server use.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   236
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   237
    protected SSLContext createServerSSLContext() throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   238
        return createSSLContext(null,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   239
                endEntityCertStrs, endEntityPrivateKeys,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   240
                endEntityPrivateKeyNames);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   241
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   242
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   243
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   244
     * Create an instance of SSLContext with the specified trust/key materials.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   245
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   246
    protected SSLContext createSSLContext(
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   247
            String[] trustedMaterials,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   248
            String[] keyMaterialCerts,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   249
            String[] keyMaterialKeys,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   250
            String[] keyMaterialKeyAlgs) throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   251
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   252
        KeyStore ts = null;     // trust store
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   253
        KeyStore ks = null;     // key store
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   254
        char passphrase[] = "passphrase".toCharArray();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   255
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   256
        // Generate certificate from cert string.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   257
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   258
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   259
        // Import the trused certs.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   260
        ByteArrayInputStream is;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   261
        if (trustedMaterials != null && trustedMaterials.length != 0) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   262
            ts = KeyStore.getInstance("JKS");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   263
            ts.load(null, null);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   264
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   265
            Certificate[] trustedCert =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   266
                    new Certificate[trustedMaterials.length];
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   267
            for (int i = 0; i < trustedMaterials.length; i++) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   268
                String trustedCertStr = trustedMaterials[i];
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   269
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   270
                is = new ByteArrayInputStream(trustedCertStr.getBytes());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   271
                try {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   272
                    trustedCert[i] = cf.generateCertificate(is);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   273
                } finally {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   274
                    is.close();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   275
                }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   276
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   277
                ts.setCertificateEntry("trusted-cert-" + i, trustedCert[i]);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   278
            }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   279
        }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   280
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   281
        // Import the key materials.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   282
        //
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   283
        // Note that certification pathes bigger than one are not supported yet.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   284
        boolean hasKeyMaterials =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   285
            (keyMaterialCerts != null) && (keyMaterialCerts.length != 0) &&
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   286
            (keyMaterialKeys != null) && (keyMaterialKeys.length != 0) &&
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   287
            (keyMaterialKeyAlgs != null) && (keyMaterialKeyAlgs.length != 0) &&
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   288
            (keyMaterialCerts.length == keyMaterialKeys.length) &&
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   289
            (keyMaterialCerts.length == keyMaterialKeyAlgs.length);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   290
        if (hasKeyMaterials) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   291
            ks = KeyStore.getInstance("JKS");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   292
            ks.load(null, null);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   293
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   294
            for (int i = 0; i < keyMaterialCerts.length; i++) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   295
                String keyCertStr = keyMaterialCerts[i];
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   296
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   297
                // generate the private key.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   298
                PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   299
                    Base64.getMimeDecoder().decode(keyMaterialKeys[i]));
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   300
                KeyFactory kf =
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   301
                    KeyFactory.getInstance(keyMaterialKeyAlgs[i]);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   302
                PrivateKey priKey = kf.generatePrivate(priKeySpec);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   303
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   304
                // generate certificate chain
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   305
                is = new ByteArrayInputStream(keyCertStr.getBytes());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   306
                Certificate keyCert = null;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   307
                try {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   308
                    keyCert = cf.generateCertificate(is);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   309
                } finally {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   310
                    is.close();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   311
                }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   312
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   313
                Certificate[] chain = new Certificate[] { keyCert };
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   314
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   315
                // import the key entry.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   316
                ks.setKeyEntry("cert-" + i, priKey, passphrase, chain);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   317
            }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   318
        }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   319
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   320
        // Create an SSLContext object.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   321
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   322
        tmf.init(ts);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   323
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   324
        SSLContext context = SSLContext.getInstance("TLS");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   325
        if (hasKeyMaterials && ks != null) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   326
            KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   327
            kmf.init(ks, passphrase);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   328
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   329
            context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   330
        } else {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   331
            context.init(null, tmf.getTrustManagers(), null);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   332
        }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   333
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   334
        return context;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   335
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   336
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   337
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   338
     * Create an instance of SSLEngine in client mode.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   339
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   340
    protected SSLEngine createClientEngine() throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   341
        return createClientEngine(createClientSSLContext());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   342
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   343
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   344
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   345
     * Create an instance of SSLEngine in client mode with the
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   346
     * specified SSLContext object.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   347
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   348
    protected SSLEngine createClientEngine(
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   349
        SSLContext context) throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   350
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   351
        SSLEngine engine = context.createSSLEngine();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   352
        engine.setUseClientMode(true);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   353
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   354
        /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   355
         * Customize the SSLEngine object.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   356
         */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   357
        // blank
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   358
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   359
        return engine;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   360
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   361
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   362
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   363
     * Create an instance of SSLEngine in server mode.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   364
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   365
    protected SSLEngine createServerEngine() throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   366
        return createServerEngine(createServerSSLContext());
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   367
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   368
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   369
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   370
     * Create an instance of SSLEngine in server mode with the
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   371
     * specified SSLContext object.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   372
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   373
    protected SSLEngine createServerEngine(
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   374
        SSLContext context) throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   375
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   376
        SSLEngine engine = context.createSSLEngine();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   377
        engine.setUseClientMode(false);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   378
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   379
        /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   380
         * Customize the SSLEngine object.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   381
         */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   382
        engine.setNeedClientAuth(false);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   383
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   384
        return engine;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   385
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   386
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   387
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   388
     * Run the delagayed tasks if any.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   389
     *
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   390
     * If the result indicates that we have outstanding tasks to do,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   391
     * go ahead and run them in this thread.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   392
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   393
    protected static void runDelegatedTasks(SSLEngineResult result,
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   394
            SSLEngine engine) throws Exception {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   395
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   396
        if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   397
            Runnable runnable;
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   398
            while ((runnable = engine.getDelegatedTask()) != null) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   399
                log("\trunning delegated task...");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   400
                runnable.run();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   401
            }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   402
            HandshakeStatus hsStatus = engine.getHandshakeStatus();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   403
            if (hsStatus == HandshakeStatus.NEED_TASK) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   404
                throw new Exception(
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   405
                    "handshake shouldn't need additional tasks");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   406
            }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   407
            log("\tnew HandshakeStatus: " + hsStatus);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   408
        }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   409
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   410
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   411
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   412
     * Logging the specificated message and the SSLEngine operation result.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   413
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   414
    protected static void log(String str, SSLEngineResult result) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   415
        HandshakeStatus hsStatus = result.getHandshakeStatus();
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   416
        log(str +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   417
            result.getStatus() + "/" + hsStatus + ", consumed: " +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   418
            result.bytesConsumed() + "/produced: " + result.bytesProduced() +
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   419
            " bytes");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   420
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   421
        if (hsStatus == HandshakeStatus.FINISHED) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   422
            log("\t...ready for application data");
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   423
        }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   424
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   425
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   426
    /*
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   427
     * Logging the specificated message.
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   428
     */
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   429
    protected static void log(String str) {
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   430
        System.out.println(str);
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   431
    }
46494c43f5e6 8169362: Interop automated testing with Chrome
xuelei
parents:
diff changeset
   432
}