jdk/test/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java
author xuelei
Wed, 05 Mar 2014 07:24:34 +0000
changeset 23052 241885315119
parent 17185 jdk/test/sun/security/ssl/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java@510e5f180f31
child 30820 0d4717a011d3
permissions -rw-r--r--
8032473: Restructure JSSE regression test hierarchy in jdk test Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     1
/*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     4
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    10
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    15
 * accompanied this code).
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    16
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    20
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    23
 * questions.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    24
 */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    25
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    26
//
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    27
// SunJSSE does not support dynamic system properties, no way to re-use
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    28
// system properties in samevm/agentvm mode.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    29
//
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    30
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    31
/*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    32
 * @test
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    33
 * @bug 7030966
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    34
 * @summary Support AEAD CipherSuites
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    35
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    36
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_RSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    37
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    38
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_DH_anon_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    39
 */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    40
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    41
/*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    42
 * Need additional key materials to run the following cases.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    43
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    44
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    45
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    46
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    47
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    48
 * Need unlimited JCE Unlimited Strength Jurisdiction Policy to run the
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    49
 * following cases.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    50
 *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    51
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    52
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    53
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    54
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    55
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_RSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    56
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    57
 * @run main/othervm ShortRSAKeyGCM PKIX TLS_DH_anon_WITH_AES_256_GCM_SHA384
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    58
 */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    59
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    60
import java.net.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    61
import java.util.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    62
import java.io.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    63
import javax.net.ssl.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    64
import java.security.Security;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    65
import java.security.KeyStore;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    66
import java.security.KeyFactory;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    67
import java.security.cert.Certificate;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    68
import java.security.cert.CertificateFactory;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    69
import java.security.spec.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    70
import java.security.interfaces.*;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    71
import sun.misc.BASE64Decoder;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    72
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    73
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    74
public class ShortRSAKeyGCM {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    75
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    76
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    77
     * =============================================================
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    78
     * Set the various variables needed for the tests, then
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    79
     * specify what tests to run on each side.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    80
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    81
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    82
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    83
     * Should we run the client or server in a separate thread?
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    84
     * Both sides can throw exceptions, but do you have a preference
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    85
     * as to which side should be the main thread.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    86
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    87
    static boolean separateServerThread = true;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    88
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    89
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    90
     * Where do we find the keystores?
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    91
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    92
    // Certificates and key used in the test.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    93
    static String trustedCertStr =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    94
        "-----BEGIN CERTIFICATE-----\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    95
        "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    96
        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    97
        "MTEwODE5MDE1MjE5WhcNMzIwNzI5MDE1MjE5WjA7MQswCQYDVQQGEwJVUzENMAsG\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    98
        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
    99
        "KoZIhvcNAQEBBQADgY0AMIGJAoGBAM8orG08DtF98TMSscjGsidd1ZoN4jiDpi8U\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   100
        "ICz+9dMm1qM1d7O2T+KH3/mxyox7Rc2ZVSCaUD0a3CkhPMnlAx8V4u0H+E9sqso6\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   101
        "iDW3JpOyzMExvZiRgRG/3nvp55RMIUV4vEHOZ1QbhuqG4ebN0Vz2DkRft7+flthf\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   102
        "vDld6f5JAgMBAAGjgaUwgaIwHQYDVR0OBBYEFLl81dnfp0wDrv0OJ1sxlWzH83Xh\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   103
        "MGMGA1UdIwRcMFqAFLl81dnfp0wDrv0OJ1sxlWzH83XhoT+kPTA7MQswCQYDVQQG\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   104
        "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   105
        "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEE\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   106
        "BQADgYEALlgaH1gWtoBZ84EW8Hu6YtGLQ/L9zIFmHonUPZwn3Pr//icR9Sqhc3/l\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   107
        "pVTxOINuFHLRz4BBtEylzRIOPzK3tg8XwuLb1zd0db90x3KBCiAL6E6cklGEPwLe\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   108
        "XYMHDn9eDsaq861Tzn6ZwzMgw04zotPMoZN0mVd/3Qca8UJFucE=\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   109
        "-----END CERTIFICATE-----";
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   110
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   111
    static String targetCertStr =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   112
        "-----BEGIN CERTIFICATE-----\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   113
        "MIICNDCCAZ2gAwIBAgIBDDANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   114
        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   115
        "MTExMTA3MTM1NTUyWhcNMzEwNzI1MTM1NTUyWjBPMQswCQYDVQQGEwJVUzENMAsG\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   116
        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEjAQBgNV\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   117
        "BAMTCWxvY2FsaG9zdDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC3Pb49OSPfOD2G\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   118
        "HSXFCFx1GJEZfqG9ZUf7xuIi/ra5dLjPGAaoY5QF2QOa8VnOriQCXDfyXHxsuRnE\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   119
        "OomxL7EVAgMBAAGjeDB2MAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQUXNCJK3/dtCIc\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   120
        "xb+zlA/JINlvs/MwHwYDVR0jBBgwFoAUuXzV2d+nTAOu/Q4nWzGVbMfzdeEwJwYD\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   121
        "VR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAzANBgkqhkiG9w0B\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   122
        "AQQFAAOBgQB2qIDUxA2caMPpGtUACZAPRUtrGssCINIfItETXJZCx/cRuZ5sP4D9\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   123
        "N1acoNDn0hCULe3lhXAeTC9NZ97680yJzregQMV5wATjo1FGsKY30Ma+sc/nfzQW\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   124
        "+h/7RhYtoG0OTsiaDCvyhI6swkNJzSzrAccPY4+ZgU8HiDLzZTmM3Q==\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   125
        "-----END CERTIFICATE-----";
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   126
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   127
    // Private key in the format of PKCS#8, key size is 512 bits.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   128
    static String targetPrivateKey =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   129
        "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAtz2+PTkj3zg9hh0l\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   130
        "xQhcdRiRGX6hvWVH+8biIv62uXS4zxgGqGOUBdkDmvFZzq4kAlw38lx8bLkZxDqJ\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   131
        "sS+xFQIDAQABAkByx/5Oo2hQ/w2q4L8z+NTRlJ3vdl8iIDtC/4XPnfYfnGptnpG6\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   132
        "ZThQRvbMZiai0xHQPQMszvAHjZVme1eDl3EBAiEA3aKJHynPVCEJhpfCLWuMwX5J\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   133
        "1LntwJO7NTOyU5m8rPECIQDTpzn5X44r2rzWBDna/Sx7HW9IWCxNgUD2Eyi2nA7W\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   134
        "ZQIgJerEorw4aCAuzQPxiGu57PB6GRamAihEAtoRTBQlH0ECIQDN08FgTtnesgCU\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   135
        "DFYLLcw1CiHvc7fZw4neBDHCrC8NtQIgA8TOUkGnpCZlQ0KaI8KfKWI+vxFcgFnH\n" +
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   136
        "3fnqsTgaUs4=";
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   137
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   138
    static char passphrase[] = "passphrase".toCharArray();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   139
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   140
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   141
     * Is the server ready to serve?
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   142
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   143
    volatile static boolean serverReady = false;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   144
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   145
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   146
     * Turn on SSL debugging?
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   147
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   148
    static boolean debug = false;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   149
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   150
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   151
     * Define the server side of the test.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   152
     *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   153
     * If the server prematurely exits, serverReady will be set to true
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   154
     * to avoid infinite hangs.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   155
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   156
    void doServerSide() throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   157
        SSLContext context = generateSSLContext(null, targetCertStr,
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   158
                                            targetPrivateKey);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   159
        SSLServerSocketFactory sslssf = context.getServerSocketFactory();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   160
        SSLServerSocket sslServerSocket =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   161
            (SSLServerSocket)sslssf.createServerSocket(serverPort);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   162
        serverPort = sslServerSocket.getLocalPort();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   163
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   164
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   165
         * Signal Client, we're ready for his connect.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   166
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   167
        serverReady = true;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   168
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   169
        SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   170
        sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   171
        InputStream sslIS = sslSocket.getInputStream();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   172
        OutputStream sslOS = sslSocket.getOutputStream();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   173
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   174
        sslIS.read();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   175
        sslOS.write('A');
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   176
        sslOS.flush();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   177
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   178
        sslSocket.close();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   179
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   180
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   181
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   182
     * Define the client side of the test.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   183
     *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   184
     * If the server prematurely exits, serverReady will be set to true
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   185
     * to avoid infinite hangs.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   186
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   187
    void doClientSide() throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   188
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   189
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   190
         * Wait for server to get started.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   191
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   192
        while (!serverReady) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   193
            Thread.sleep(50);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   194
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   195
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   196
        SSLContext context = generateSSLContext(trustedCertStr, null, null);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   197
        SSLSocketFactory sslsf = context.getSocketFactory();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   198
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   199
        SSLSocket sslSocket =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   200
            (SSLSocket)sslsf.createSocket("localhost", serverPort);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   201
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   202
        // enable TLSv1.2 only
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   203
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.2"});
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   204
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   205
        // enable a block cipher
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   206
        sslSocket.setEnabledCipherSuites(new String[] {cipherSuite});
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   207
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   208
        InputStream sslIS = sslSocket.getInputStream();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   209
        OutputStream sslOS = sslSocket.getOutputStream();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   210
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   211
        sslOS.write('B');
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   212
        sslOS.flush();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   213
        sslIS.read();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   214
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   215
        sslSocket.close();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   216
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   217
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   218
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   219
     * =============================================================
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   220
     * The remainder is just support stuff
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   221
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   222
    private static String tmAlgorithm;        // trust manager
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   223
    private static String cipherSuite;        // cipher suite
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   224
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   225
    private static void parseArguments(String[] args) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   226
        tmAlgorithm = args[0];
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   227
        cipherSuite = args[1];
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   228
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   229
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   230
    private static SSLContext generateSSLContext(String trustedCertStr,
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   231
            String keyCertStr, String keySpecStr) throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   232
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   233
        // generate certificate from cert string
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   234
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   235
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   236
        // create a key store
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   237
        KeyStore ks = KeyStore.getInstance("JKS");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   238
        ks.load(null, null);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   239
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   240
        // import the trused cert
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   241
        Certificate trusedCert = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   242
        ByteArrayInputStream is = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   243
        if (trustedCertStr != null) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   244
            is = new ByteArrayInputStream(trustedCertStr.getBytes());
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   245
            trusedCert = cf.generateCertificate(is);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   246
            is.close();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   247
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   248
            ks.setCertificateEntry("RSA Export Signer", trusedCert);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   249
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   250
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   251
        if (keyCertStr != null) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   252
            // generate the private key.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   253
            PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   254
                                new BASE64Decoder().decodeBuffer(keySpecStr));
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   255
            KeyFactory kf = KeyFactory.getInstance("RSA");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   256
            RSAPrivateKey priKey =
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   257
                    (RSAPrivateKey)kf.generatePrivate(priKeySpec);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   258
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   259
            // generate certificate chain
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   260
            is = new ByteArrayInputStream(keyCertStr.getBytes());
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   261
            Certificate keyCert = cf.generateCertificate(is);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   262
            is.close();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   263
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   264
            Certificate[] chain = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   265
            if (trusedCert != null) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   266
                chain = new Certificate[2];
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   267
                chain[0] = keyCert;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   268
                chain[1] = trusedCert;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   269
            } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   270
                chain = new Certificate[1];
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   271
                chain[0] = keyCert;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   272
            }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   273
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   274
            // import the key entry.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   275
            ks.setKeyEntry("Whatever", priKey, passphrase, chain);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   276
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   277
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   278
        // create SSL context
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   279
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   280
        tmf.init(ks);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   281
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   282
        SSLContext ctx = SSLContext.getInstance("TLS");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   283
        if (keyCertStr != null && !keyCertStr.isEmpty()) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   284
            KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   285
            kmf.init(ks, passphrase);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   286
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   287
            ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   288
            ks = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   289
        } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   290
            ctx.init(null, tmf.getTrustManagers(), null);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   291
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   292
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   293
        return ctx;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   294
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   295
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   296
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   297
    // use any free port by default
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   298
    volatile int serverPort = 0;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   299
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   300
    volatile Exception serverException = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   301
    volatile Exception clientException = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   302
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   303
    public static void main(String[] args) throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   304
        // reset the security property to make sure that the algorithms
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   305
        // and keys used in this test are not disabled.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   306
        Security.setProperty("jdk.certpath.disabledAlgorithms", "MD2");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   307
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   308
        if (debug) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   309
            System.setProperty("javax.net.debug", "all");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   310
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   311
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   312
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   313
         * Get the customized arguments.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   314
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   315
        parseArguments(args);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   316
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   317
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   318
         * Start the tests.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   319
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   320
        new ShortRSAKeyGCM();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   321
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   322
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   323
    Thread clientThread = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   324
    Thread serverThread = null;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   325
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   326
    /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   327
     * Primary constructor, used to drive remainder of the test.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   328
     *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   329
     * Fork off the other side, then do your work.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   330
     */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   331
    ShortRSAKeyGCM() throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   332
        try {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   333
            if (separateServerThread) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   334
                startServer(true);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   335
                startClient(false);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   336
            } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   337
                startClient(true);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   338
                startServer(false);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   339
            }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   340
        } catch (Exception e) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   341
            // swallow for now.  Show later
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   342
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   343
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   344
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   345
         * Wait for other side to close down.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   346
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   347
        if (separateServerThread) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   348
            serverThread.join();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   349
        } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   350
            clientThread.join();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   351
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   352
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   353
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   354
         * When we get here, the test is pretty much over.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   355
         * Which side threw the error?
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   356
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   357
        Exception local;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   358
        Exception remote;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   359
        String whichRemote;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   360
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   361
        if (separateServerThread) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   362
            remote = serverException;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   363
            local = clientException;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   364
            whichRemote = "server";
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   365
        } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   366
            remote = clientException;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   367
            local = serverException;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   368
            whichRemote = "client";
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   369
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   370
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   371
        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   372
         * If both failed, return the curthread's exception, but also
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   373
         * print the remote side Exception
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   374
         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   375
        if ((local != null) && (remote != null)) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   376
            System.out.println(whichRemote + " also threw:");
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   377
            remote.printStackTrace();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   378
            System.out.println();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   379
            throw local;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   380
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   381
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   382
        if (remote != null) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   383
            throw remote;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   384
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   385
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   386
        if (local != null) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   387
            throw local;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   388
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   389
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   390
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   391
    void startServer(boolean newThread) throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   392
        if (newThread) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   393
            serverThread = new Thread() {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   394
                public void run() {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   395
                    try {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   396
                        doServerSide();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   397
                    } catch (Exception e) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   398
                        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   399
                         * Our server thread just died.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   400
                         *
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   401
                         * Release the client, if not active already...
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   402
                         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   403
                        System.err.println("Server died..." + e);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   404
                        serverReady = true;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   405
                        serverException = e;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   406
                    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   407
                }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   408
            };
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   409
            serverThread.start();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   410
        } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   411
            try {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   412
                doServerSide();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   413
            } catch (Exception e) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   414
                serverException = e;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   415
            } finally {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   416
                serverReady = true;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   417
            }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   418
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   419
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   420
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   421
    void startClient(boolean newThread) throws Exception {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   422
        if (newThread) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   423
            clientThread = new Thread() {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   424
                public void run() {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   425
                    try {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   426
                        doClientSide();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   427
                    } catch (Exception e) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   428
                        /*
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   429
                         * Our client thread just died.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   430
                         */
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   431
                        System.err.println("Client died..." + e);
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   432
                        clientException = e;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   433
                    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   434
                }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   435
            };
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   436
            clientThread.start();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   437
        } else {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   438
            try {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   439
                doClientSide();
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   440
            } catch (Exception e) {
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   441
                clientException = e;
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   442
            }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   443
        }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   444
    }
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents:
diff changeset
   445
}