jdk/test/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java
author xuelei
Tue, 13 Sep 2016 00:20:17 +0000
changeset 43201 b4c682966e2a
parent 31689 1201792aa3a3
permissions -rw-r--r--
8165071: Expand TLS support Reviewed-by: jnimeh, ahgross, asmotrak
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     1
/*
43201
b4c682966e2a 8165071: Expand TLS support
xuelei
parents: 31689
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     4
 *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     8
 *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    13
 * accompanied this code).
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    14
 *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    18
 *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    21
 * questions.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    22
 */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    23
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    24
//
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    25
// SunJSSE does not support dynamic system properties, no way to re-use
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    26
// system properties in samevm/agentvm mode.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    27
//
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    28
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    29
/*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    30
 * @test
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    31
 * @bug 7188657
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    32
 * @summary There should be a way to reorder the JSSE ciphers
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    33
 * @run main/othervm UseCipherSuitesOrder
43201
b4c682966e2a 8165071: Expand TLS support
xuelei
parents: 31689
diff changeset
    34
 *     TLS_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    35
 */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    36
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    37
import java.io.*;
29902
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
    38
import java.security.Security;
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    39
import javax.net.ssl.*;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    40
import java.util.Arrays;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    41
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    42
public class UseCipherSuitesOrder {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    43
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    44
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    45
     * =============================================================
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    46
     * Set the various variables needed for the tests, then
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    47
     * specify what tests to run on each side.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    48
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    49
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    50
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    51
     * Should we run the client or server in a separate thread?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    52
     * Both sides can throw exceptions, but do you have a preference
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    53
     * as to which side should be the main thread.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    54
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    55
    static boolean separateServerThread = false;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    56
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    57
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    58
     * Where do we find the keystores?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    59
     */
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 19823
diff changeset
    60
    static String pathToStores = "../etc";
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    61
    static String keyStoreFile = "keystore";
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    62
    static String trustStoreFile = "truststore";
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    63
    static String passwd = "passphrase";
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    64
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    65
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    66
     * Is the server ready to serve?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    67
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    68
    volatile static boolean serverReady = false;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    69
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    70
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    71
     * Turn on SSL debugging?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    72
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    73
    static boolean debug = false;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    74
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    75
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    76
     * If the client or server is doing some kind of object creation
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    77
     * that the other side depends on, and that thread prematurely
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    78
     * exits, you may experience a hang.  The test harness will
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    79
     * terminate all hung threads after its timeout has expired,
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    80
     * currently 3 minutes by default, but you might try to be
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    81
     * smart about it....
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    82
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    83
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    84
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    85
     * Define the server side of the test.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    86
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    87
     * If the server prematurely exits, serverReady will be set to true
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    88
     * to avoid infinite hangs.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    89
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    90
    void doServerSide() throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    91
        SSLServerSocketFactory sslssf =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    92
            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    93
        SSLServerSocket sslServerSocket =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    94
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    95
        serverPort = sslServerSocket.getLocalPort();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    96
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    97
        // use local cipher suites preference
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    98
        SSLParameters params = sslServerSocket.getSSLParameters();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    99
        params.setUseCipherSuitesOrder(true);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   100
        params.setCipherSuites(srvEnabledCipherSuites);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   101
        sslServerSocket.setSSLParameters(params);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   102
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   103
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   104
         * Signal Client, we're ready for his connect.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   105
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   106
        serverReady = true;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   107
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   108
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   109
        InputStream sslIS = sslSocket.getInputStream();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   110
        OutputStream sslOS = sslSocket.getOutputStream();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   111
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   112
        sslIS.read();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   113
        sslOS.write(85);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   114
        sslOS.flush();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   115
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   116
        SSLSession session = sslSocket.getSession();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   117
        if (!srvEnabledCipherSuites[0].equals(session.getCipherSuite())) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   118
            throw new Exception(
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   119
                "Expected to negotiate " + srvEnabledCipherSuites[0] +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   120
                " , but not " + session.getCipherSuite());
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   121
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   122
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   123
        sslSocket.close();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   124
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   125
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   126
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   127
     * Define the client side of the test.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   128
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   129
     * If the server prematurely exits, serverReady will be set to true
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   130
     * to avoid infinite hangs.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   131
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   132
    void doClientSide() throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   133
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   134
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   135
         * Wait for server to get started.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   136
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   137
        while (!serverReady) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   138
            Thread.sleep(50);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   139
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   140
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   141
        SSLSocketFactory sslsf =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   142
            (SSLSocketFactory) SSLSocketFactory.getDefault();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   143
        SSLSocket sslSocket = (SSLSocket)
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   144
            sslsf.createSocket("localhost", serverPort);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   145
        sslSocket.setEnabledCipherSuites(cliEnabledCipherSuites);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   146
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   147
        InputStream sslIS = sslSocket.getInputStream();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   148
        OutputStream sslOS = sslSocket.getOutputStream();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   149
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   150
        sslOS.write(280);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   151
        sslOS.flush();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   152
        sslIS.read();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   153
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   154
        sslSocket.close();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   155
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   156
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   157
    // client enabled cipher suites
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   158
    private static String[] cliEnabledCipherSuites;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   159
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   160
    // server enabled cipher suites
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   161
    private static String[] srvEnabledCipherSuites;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   162
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   163
    private static void parseArguments(String[] args) throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   164
        if (args.length != 1) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   165
            System.out.println("Usage: java UseCipherSuitesOrder ciphersuites");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   166
            System.out.println("\tciphersuites: " +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   167
                    "a list of enabled cipher suites, separated with comma");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   168
            throw new Exception("Incorrect usage");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   169
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   170
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   171
        cliEnabledCipherSuites = args[0].split(",");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   172
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   173
        if (cliEnabledCipherSuites.length < 2) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   174
            throw new Exception("Need to enable at least two cipher suites");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   175
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   176
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   177
        // Only need to use 2 cipher suites in server side.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   178
        srvEnabledCipherSuites = Arrays.<String>copyOf(
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   179
                                            cliEnabledCipherSuites, 2);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   180
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   181
        // Reverse the cipher suite preference in server side.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   182
        srvEnabledCipherSuites[0] = cliEnabledCipherSuites[1];
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   183
        srvEnabledCipherSuites[1] = cliEnabledCipherSuites[0];
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   184
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   185
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   186
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   187
     * =============================================================
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   188
     * The remainder is just support stuff
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   189
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   190
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   191
    // use any free port by default
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   192
    volatile int serverPort = 0;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   193
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   194
    volatile Exception serverException = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   195
    volatile Exception clientException = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   196
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   197
    public static void main(String[] args) throws Exception {
29902
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   198
        // reset the security property to make sure that the algorithms
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   199
        // and keys used in this test are not disabled.
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   200
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   201
19823
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   202
        // parse the arguments
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   203
        parseArguments(args);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   204
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   205
        String keyFilename =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   206
            System.getProperty("test.src", ".") + "/" + pathToStores +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   207
                "/" + keyStoreFile;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   208
        String trustFilename =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   209
            System.getProperty("test.src", ".") + "/" + pathToStores +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   210
                "/" + trustStoreFile;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   211
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   212
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   213
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   214
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   215
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   216
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   217
        if (debug)
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   218
            System.setProperty("javax.net.debug", "all");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   219
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   220
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   221
         * Start the tests.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   222
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   223
        new UseCipherSuitesOrder();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   224
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   225
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   226
    Thread clientThread = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   227
    Thread serverThread = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   228
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   229
    /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   230
     * Primary constructor, used to drive remainder of the test.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   231
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   232
     * Fork off the other side, then do your work.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   233
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   234
    UseCipherSuitesOrder() throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   235
        Exception startException = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   236
        try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   237
            if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   238
                startServer(true);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   239
                startClient(false);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   240
            } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   241
                startClient(true);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   242
                startServer(false);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   243
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   244
        } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   245
            startException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   246
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   247
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   248
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   249
         * Wait for other side to close down.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   250
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   251
        if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   252
            if (serverThread != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   253
                serverThread.join();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   254
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   255
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   256
            if (clientThread != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   257
                clientThread.join();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   258
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   259
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   260
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   261
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   262
         * When we get here, the test is pretty much over.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   263
         * Which side threw the error?
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   264
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   265
        Exception local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   266
        Exception remote;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   267
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   268
        if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   269
            remote = serverException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   270
            local = clientException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   271
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   272
            remote = clientException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   273
            local = serverException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   274
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   275
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   276
        Exception exception = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   277
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   278
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   279
         * Check various exception conditions.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   280
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   281
        if ((local != null) && (remote != null)) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   282
            // If both failed, return the curthread's exception.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   283
            local.initCause(remote);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   284
            exception = local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   285
        } else if (local != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   286
            exception = local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   287
        } else if (remote != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   288
            exception = remote;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   289
        } else if (startException != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   290
            exception = startException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   291
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   292
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   293
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   294
         * If there was an exception *AND* a startException,
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   295
         * output it.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   296
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   297
        if (exception != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   298
            if (exception != startException && startException != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   299
                exception.addSuppressed(startException);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   300
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   301
            throw exception;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   302
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   303
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   304
        // Fall-through: no exception to throw!
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   305
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   306
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   307
    void startServer(boolean newThread) throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   308
        if (newThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   309
            serverThread = new Thread() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   310
                public void run() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   311
                    try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   312
                        doServerSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   313
                    } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   314
                        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   315
                         * Our server thread just died.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   316
                         *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   317
                         * Release the client, if not active already...
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   318
                         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   319
                        System.err.println("Server died...");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   320
                        serverReady = true;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   321
                        serverException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   322
                    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   323
                }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   324
            };
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   325
            serverThread.start();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   326
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   327
            try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   328
                doServerSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   329
            } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   330
                serverException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   331
            } finally {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   332
                serverReady = true;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   333
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   334
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   335
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   336
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   337
    void startClient(boolean newThread) throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   338
        if (newThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   339
            clientThread = new Thread() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   340
                public void run() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   341
                    try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   342
                        doClientSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   343
                    } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   344
                        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   345
                         * Our client thread just died.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   346
                         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   347
                        System.err.println("Client died...");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   348
                        clientException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   349
                    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   350
                }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   351
            };
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   352
            clientThread.start();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   353
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   354
            try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   355
                doClientSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   356
            } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   357
                clientException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   358
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   359
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   360
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   361
}