jdk/test/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java
author prr
Thu, 18 Dec 2014 10:45:45 -0800
changeset 29908 83e2c403fefd
parent 23052 241885315119
child 29902 dc24eacaae11
permissions -rw-r--r--
8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene
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
/*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    34
 *     TLS_RSA_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA
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.*;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
    38
import java.net.*;
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 {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   198
        // parse the arguments
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   199
        parseArguments(args);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   200
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   201
        String keyFilename =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   202
            System.getProperty("test.src", ".") + "/" + pathToStores +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   203
                "/" + keyStoreFile;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   204
        String trustFilename =
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   205
            System.getProperty("test.src", ".") + "/" + pathToStores +
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   206
                "/" + trustStoreFile;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   207
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   208
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   209
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   210
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   211
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   212
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   213
        if (debug)
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   214
            System.setProperty("javax.net.debug", "all");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   215
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
         * Start the tests.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   218
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   219
        new UseCipherSuitesOrder();
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
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   222
    Thread clientThread = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   223
    Thread serverThread = null;
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
     * 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
   227
     *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   228
     * 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
   229
     */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   230
    UseCipherSuitesOrder() throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   231
        Exception startException = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   232
        try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   233
            if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   234
                startServer(true);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   235
                startClient(false);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   236
            } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   237
                startClient(true);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   238
                startServer(false);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   239
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   240
        } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   241
            startException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   242
        }
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
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   245
         * Wait for other side to close down.
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
        if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   248
            if (serverThread != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   249
                serverThread.join();
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
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   252
            if (clientThread != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   253
                clientThread.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
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   256
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   257
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   258
         * 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
   259
         * Which side threw the error?
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
        Exception local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   262
        Exception remote;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   263
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   264
        if (separateServerThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   265
            remote = serverException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   266
            local = clientException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   267
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   268
            remote = clientException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   269
            local = serverException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   270
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   271
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   272
        Exception exception = null;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   273
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
         * Check various exception conditions.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   276
         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   277
        if ((local != null) && (remote != null)) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   278
            // If both failed, return the curthread's exception.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   279
            local.initCause(remote);
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   280
            exception = local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   281
        } else if (local != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   282
            exception = local;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   283
        } else if (remote != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   284
            exception = remote;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   285
        } else if (startException != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   286
            exception = startException;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   287
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   288
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   289
        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   290
         * If there was an exception *AND* a startException,
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   291
         * output it.
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
        if (exception != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   294
            if (exception != startException && startException != null) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   295
                exception.addSuppressed(startException);
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
            throw exception;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   298
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   299
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   300
        // Fall-through: no exception to throw!
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   301
    }
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
    void startServer(boolean newThread) throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   304
        if (newThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   305
            serverThread = new Thread() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   306
                public void run() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   307
                    try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   308
                        doServerSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   309
                    } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   310
                        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   311
                         * Our server thread just died.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   312
                         *
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   313
                         * Release the client, if not active already...
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
                        System.err.println("Server died...");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   316
                        serverReady = true;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   317
                        serverException = e;
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
                }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   320
            };
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   321
            serverThread.start();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   322
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   323
            try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   324
                doServerSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   325
            } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   326
                serverException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   327
            } finally {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   328
                serverReady = true;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   329
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   330
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   331
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   332
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   333
    void startClient(boolean newThread) throws Exception {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   334
        if (newThread) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   335
            clientThread = new Thread() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   336
                public void run() {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   337
                    try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   338
                        doClientSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   339
                    } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   340
                        /*
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   341
                         * Our client thread just died.
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   342
                         */
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   343
                        System.err.println("Client died...");
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   344
                        clientException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   345
                    }
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
            };
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   348
            clientThread.start();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   349
        } else {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   350
            try {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   351
                doClientSide();
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   352
            } catch (Exception e) {
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   353
                clientException = e;
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   354
            }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   355
        }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   356
    }
f0fd09e20528 7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
diff changeset
   357
}