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