jdk/test/javax/net/ssl/TLSv11/ExportableBlockCipher.java
author prr
Thu, 18 Dec 2014 10:45:45 -0800
changeset 29908 83e2c403fefd
parent 23052 241885315119
child 30904 ec0224270f90
permissions -rw-r--r--
8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10328
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     4
 *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    10
 *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    15
 * accompanied this code).
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    16
 *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    20
 *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    23
 * questions.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    24
 */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    25
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    26
/*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    27
 * @test
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    28
 * @bug 4873188
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    29
 * @summary Support TLS 1.1
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 7039
diff changeset
    30
 * @run main/othervm ExportableBlockCipher
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 7039
diff changeset
    31
 *
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 7039
diff changeset
    32
 *     SunJSSE does not support dynamic system properties, no way to re-use
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 7039
diff changeset
    33
 *     system properties in samevm/agentvm mode.
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    34
 *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    35
 * @author Xuelei Fan
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    36
 */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    37
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    38
import java.io.*;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    39
import java.net.*;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    40
import javax.net.ssl.*;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    41
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    42
public class ExportableBlockCipher {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    43
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    44
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    45
     * =============================================================
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    46
     * Set the various variables needed for the tests, then
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    47
     * specify what tests to run on each side.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    48
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    49
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    50
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    51
     * Should we run the client or server in a separate thread?
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    52
     * Both sides can throw exceptions, but do you have a preference
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    53
     * as to which side should be the main thread.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    54
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    55
    static boolean separateServerThread = false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    56
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    57
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    58
     * Where do we find the keystores?
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    59
     */
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 14342
diff changeset
    60
    static String pathToStores = "../etc";
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    61
    static String keyStoreFile = "keystore";
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    62
    static String trustStoreFile = "truststore";
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    63
    static String passwd = "passphrase";
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    64
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    65
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    66
     * Is the server ready to serve?
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    67
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    68
    volatile static boolean serverReady = false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    69
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    70
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    71
     * Turn on SSL debugging?
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    72
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    73
    static boolean debug = false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    74
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    75
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    76
     * If the client or server is doing some kind of object creation
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    77
     * that the other side depends on, and that thread prematurely
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    78
     * exits, you may experience a hang.  The test harness will
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    79
     * terminate all hung threads after its timeout has expired,
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    80
     * currently 3 minutes by default, but you might try to be
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    81
     * smart about it....
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    82
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    83
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    84
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    85
     * Define the server side of the test.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    86
     *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    87
     * If the server prematurely exits, serverReady will be set to true
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    88
     * to avoid infinite hangs.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    89
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    90
    void doServerSide() throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    91
        SSLServerSocketFactory sslssf =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    92
            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    93
        SSLServerSocket sslServerSocket =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    94
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    95
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    96
        serverPort = sslServerSocket.getLocalPort();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    97
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    98
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
    99
         * Signal Client, we're ready for his connect.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   100
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   101
        serverReady = true;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   102
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   103
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   104
        InputStream sslIS = sslSocket.getInputStream();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   105
        OutputStream sslOS = sslSocket.getOutputStream();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   106
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   107
        boolean interrupted = false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   108
        try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   109
            sslIS.read();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   110
            sslOS.write('A');
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   111
            sslOS.flush();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   112
        } catch (SSLException ssle) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   113
            // get the expected exception
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   114
            interrupted = true;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   115
        } finally {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   116
            sslSocket.close();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   117
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   118
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   119
        if (!interrupted) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   120
            throw new SSLHandshakeException(
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   121
                "A weak cipher suite is negotiated, " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   122
                "TLSv1.1 must not negotiate the exportable cipher suites.");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   123
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   124
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   125
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   126
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   127
     * Define the client side of the test.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   128
     *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   129
     * If the server prematurely exits, serverReady will be set to true
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   130
     * to avoid infinite hangs.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   131
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   132
    void doClientSide() throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   133
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   134
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   135
         * Wait for server to get started.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   136
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   137
        while (!serverReady) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   138
            Thread.sleep(50);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   139
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   140
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   141
        SSLSocketFactory sslsf =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   142
            (SSLSocketFactory) SSLSocketFactory.getDefault();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   143
        SSLSocket sslSocket = (SSLSocket)
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   144
            sslsf.createSocket("localhost", serverPort);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   145
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   146
        // enable TLSv1.1 only
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   147
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   148
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   149
        // enable a exportable block cipher
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   150
        sslSocket.setEnabledCipherSuites(
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   151
            new String[] {"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA"});
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   152
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   153
        InputStream sslIS = sslSocket.getInputStream();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   154
        OutputStream sslOS = sslSocket.getOutputStream();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   155
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   156
        boolean interrupted = false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   157
        try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   158
            sslOS.write('B');
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   159
            sslOS.flush();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   160
            sslIS.read();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   161
        } catch (SSLException ssle) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   162
            // get the expected exception
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   163
            interrupted = true;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   164
        } finally {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   165
            sslSocket.close();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   166
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   167
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   168
        if (!interrupted) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   169
            throw new SSLHandshakeException(
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   170
                "A weak cipher suite is negotiated, " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   171
                "TLSv1.1 must not negotiate the exportable cipher suites.");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   172
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   173
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   174
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   175
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   176
     * =============================================================
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   177
     * The remainder is just support stuff
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   178
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   179
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   180
    // use any free port by default
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   181
    volatile int serverPort = 0;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   182
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   183
    volatile Exception serverException = null;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   184
    volatile Exception clientException = null;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   185
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   186
    public static void main(String[] args) throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   187
        String keyFilename =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   188
            System.getProperty("test.src", ".") + "/" + pathToStores +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   189
                "/" + keyStoreFile;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   190
        String trustFilename =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   191
            System.getProperty("test.src", ".") + "/" + pathToStores +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   192
                "/" + trustStoreFile;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   193
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   194
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   195
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   196
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   197
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   198
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   199
        if (debug)
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   200
            System.setProperty("javax.net.debug", "all");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   201
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   202
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   203
         * Start the tests.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   204
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   205
        new ExportableBlockCipher();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   206
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   207
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   208
    Thread clientThread = null;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   209
    Thread serverThread = null;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   210
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   211
    /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   212
     * Primary constructor, used to drive remainder of the test.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   213
     *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   214
     * Fork off the other side, then do your work.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   215
     */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   216
    ExportableBlockCipher() throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   217
        try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   218
            if (separateServerThread) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   219
                startServer(true);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   220
                startClient(false);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   221
            } else {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   222
                startClient(true);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   223
                startServer(false);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   224
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   225
        } catch (Exception e) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   226
            // swallow for now.  Show later
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   227
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   228
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   229
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   230
         * Wait for other side to close down.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   231
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   232
        if (separateServerThread) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   233
            serverThread.join();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   234
        } else {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   235
            clientThread.join();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   236
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   237
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   238
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   239
         * When we get here, the test is pretty much over.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   240
         * Which side threw the error?
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   241
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   242
        Exception local;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   243
        Exception remote;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   244
        String whichRemote;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   245
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   246
        if (separateServerThread) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   247
            remote = serverException;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   248
            local = clientException;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   249
            whichRemote = "server";
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   250
        } else {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   251
            remote = clientException;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   252
            local = serverException;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   253
            whichRemote = "client";
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   254
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   255
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   256
        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   257
         * If both failed, return the curthread's exception, but also
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   258
         * print the remote side Exception
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   259
         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   260
        if ((local != null) && (remote != null)) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   261
            System.out.println(whichRemote + " also threw:");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   262
            remote.printStackTrace();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   263
            System.out.println();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   264
            throw local;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   265
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   266
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   267
        if (remote != null) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   268
            throw remote;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   269
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   270
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   271
        if (local != null) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   272
            throw local;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   273
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   274
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   275
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   276
    void startServer(boolean newThread) throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   277
        if (newThread) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   278
            serverThread = new Thread() {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   279
                public void run() {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   280
                    try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   281
                        doServerSide();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   282
                    } catch (Exception e) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   283
                        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   284
                         * Our server thread just died.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   285
                         *
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   286
                         * Release the client, if not active already...
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   287
                         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   288
                        System.err.println("Server died...");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   289
                        serverReady = true;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   290
                        serverException = e;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   291
                    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   292
                }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   293
            };
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   294
            serverThread.start();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   295
        } else {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   296
            try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   297
                doServerSide();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   298
            } catch (Exception e) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   299
                serverException = e;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   300
            } finally {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   301
                serverReady = true;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   302
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   303
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   304
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   305
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   306
    void startClient(boolean newThread) throws Exception {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   307
        if (newThread) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   308
            clientThread = new Thread() {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   309
                public void run() {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   310
                    try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   311
                        doClientSide();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   312
                    } catch (Exception e) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   313
                        /*
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   314
                         * Our client thread just died.
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   315
                         */
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   316
                        System.err.println("Client died...");
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   317
                        clientException = e;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   318
                    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   319
                }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   320
            };
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   321
            clientThread.start();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   322
        } else {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   323
            try {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   324
                doClientSide();
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   325
            } catch (Exception e) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   326
                clientException = e;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   327
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   328
        }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   329
    }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents:
diff changeset
   330
}