jdk/test/javax/net/ssl/SSLEngine/CheckStatus.java
author joehw
Wed, 16 Aug 2017 11:28:39 -0700
changeset 46175 52634f4b683b
parent 30904 ec0224270f90
permissions -rw-r--r--
8186208: closed/javax/xml/jaxp/transform/cr6657673/CR6657673Test.java: test result: Error. failed to clean up files after test Reviewed-by: dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29902
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
     2
 * Copyright (c) 2003, 2015, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4948079
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary SSLEngineResult needs updating [none yet]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This is a simple hack to test a bunch of conditions and check
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * their return codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 6856
diff changeset
    32
 * @run main/othervm -Djsse.enableCBCProtection=false CheckStatus
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 6856
diff changeset
    33
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @author Brad Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.net.ssl.SSLEngineResult.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class CheckStatus {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static boolean debug = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private SSLContext sslc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private SSLEngine ssle1;    // client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private SSLEngine ssle2;    // server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 10915
diff changeset
    51
    private static String pathToStores = "../etc";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private ByteBuffer appOut1;         // write side of ssle1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private ByteBuffer appIn1;          // read side of ssle1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private ByteBuffer appOut2;         // write side of ssle2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private ByteBuffer appIn2;          // read side of ssle2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private ByteBuffer oneToTwo;        // "reliable" transport ssle1->ssle2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private ByteBuffer twoToOne;        // "reliable" transport ssle2->ssle1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Majority of the test case is here, setup is done below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private void createSSLEngines() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        ssle1 = sslc.createSSLEngine("client", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        ssle1.setUseClientMode(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ssle2 = sslc.createSSLEngine("server", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        ssle2.setUseClientMode(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private boolean isHandshaking(SSLEngine e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return (e.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private void checkResult(ByteBuffer bbIn, ByteBuffer bbOut,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            SSLEngineResult result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            Status status, HandshakeStatus hsStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            int consumed, int produced)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if ((status != null) && (result.getStatus() != status)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new Exception("Unexpected Status: need = " + status +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                " got = " + result.getStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if ((hsStatus != null) && (result.getHandshakeStatus() != hsStatus)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new Exception("Unexpected hsStatus: need = " + hsStatus +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                " got = " + result.getHandshakeStatus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if ((consumed != -1) && (consumed != result.bytesConsumed())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new Exception("Unexpected consumed: need = " + consumed +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                " got = " + result.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if ((produced != -1) && (produced != result.bytesProduced())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new Exception("Unexpected produced: need = " + produced +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                " got = " + result.bytesProduced());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if ((consumed != -1) && (bbIn.position() != result.bytesConsumed())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            throw new Exception("Consumed " + bbIn.position() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                " != " + consumed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if ((produced != -1) && (bbOut.position() != result.bytesProduced())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new Exception("produced " + bbOut.position() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                " != " + produced);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private void test() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        createSSLEngines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        createBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        SSLEngineResult result1;        // ssle1's results from last operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        SSLEngineResult result2;        // ssle2's results from last operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        String [] suite1 = new String [] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            "SSL_RSA_WITH_RC4_128_MD5" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        String [] suite2 = new String [] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        ssle1.setEnabledCipherSuites(suite1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        ssle2.setEnabledCipherSuites(suite1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        log("================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        log("unexpected empty unwrap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        twoToOne.limit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            Status.OK, HandshakeStatus.NEED_WRAP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        twoToOne.limit(twoToOne.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        log("client hello");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
             Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        runDelegatedTasks(ssle2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        log("Check for unwrap when wrap needed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            Status.OK, HandshakeStatus.NEED_WRAP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        log("ServerHello");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            Status.OK, HandshakeStatus.NEED_TASK, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        runDelegatedTasks(ssle1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        log("Key Exchange");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        runDelegatedTasks(ssle2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
             Status.OK, HandshakeStatus.NEED_UNWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        log("Finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
             Status.OK, HandshakeStatus.NEED_WRAP, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Status.OK, HandshakeStatus.NEED_UNWRAP, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        log("FINISHED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            Status.OK, HandshakeStatus.FINISHED, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Status.OK, HandshakeStatus.FINISHED, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        log("Check Session/Ciphers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        String suite = ssle1.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (!suite.equals(suite1[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                suite1[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        suite = ssle2.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (!suite.equals(suite1[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                suite1[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        log("DATA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            appOut1.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            appOut2.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        SSLEngineResult result3 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        checkResult(twoToOne, appIn1, result3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            result2.bytesProduced(), result2.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        SSLEngineResult result4 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        checkResult(oneToTwo, appIn2, result4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            result1.bytesProduced(), result1.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        appIn1.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        appIn2.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        log("RENEGOTIATE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        ssle2.getSession().invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        ssle2.setNeedClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        ssle1.setEnabledCipherSuites(suite2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        ssle2.setEnabledCipherSuites(suite2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        ssle2.beginHandshake();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        log("HelloRequest");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            Status.OK, HandshakeStatus.NEED_TASK, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        runDelegatedTasks(ssle1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        log("ClientHello");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
             Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
             Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        runDelegatedTasks(ssle2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        log("CLIENT->SERVER DATA IN MIDDLE OF HANDSHAKE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            Status.OK, HandshakeStatus.NEED_UNWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            appOut1.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        result4 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        checkResult(oneToTwo, appIn2, result4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            Status.OK, HandshakeStatus.NEED_WRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            result1.bytesProduced(), result1.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        appIn2.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        log("ServerHello");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            Status.OK, HandshakeStatus.NEED_TASK, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        runDelegatedTasks(ssle1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        log("SERVER->CLIENT DATA IN MIDDLE OF HANDSHAKE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            Status.OK, HandshakeStatus.NEED_UNWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            appOut2.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        result3 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        checkResult(twoToOne, appIn1, result3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            Status.OK, HandshakeStatus.NEED_WRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            result2.bytesProduced(), result2.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        appIn1.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        log("======================================");
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29902
diff changeset
   394
        log("Client Cert and Key Exchange");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
             Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
             Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        runDelegatedTasks(ssle2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
             Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
             Status.OK, HandshakeStatus.NEED_UNWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        log("Finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
             Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
             Status.OK, HandshakeStatus.NEED_WRAP, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            Status.OK, HandshakeStatus.NEED_UNWRAP, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        log("FINISHED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            Status.OK, HandshakeStatus.FINISHED, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            Status.OK, HandshakeStatus.FINISHED, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        log("Check Session/Ciphers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        suite = ssle1.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (!suite.equals(suite2[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                suite2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        suite = ssle2.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (!suite.equals(suite2[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                suite2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        log("DATA USING NEW SESSION");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            appOut1.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            appOut2.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        result3 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        checkResult(twoToOne, appIn1, result3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            result2.bytesProduced(), result2.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        result4 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        checkResult(oneToTwo, appIn2, result4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            result1.bytesProduced(), result1.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        appIn1.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        appIn2.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        log("CN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            throw new Exception("ssle2 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        ssle2.closeOutbound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (!isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            throw new Exception("ssle1 IS NOT handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        if (ssle1.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            Status.CLOSED, HandshakeStatus.NEED_WRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (!ssle1.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (!isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            throw new Exception("ssle1 IS NOT handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        log("CN response");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (ssle1.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            throw new Exception("ssle1 outboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
             Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (!ssle1.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throw new Exception("ssle1 outboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (!ssle2.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            throw new Exception("ssle1 outboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (ssle2.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
             Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if (!ssle2.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            throw new Exception("ssle1 outboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (!ssle2.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            throw new Exception("ssle1 inboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public static void main(String args[]) throws Exception {
29902
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   609
        // reset the security property to make sure that the algorithms
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   610
        // and keys used in this test are not disabled.
dc24eacaae11 8076221: Disable RC4 cipher suites
asmotrak
parents: 23052
diff changeset
   611
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        CheckStatus cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        cs = new CheckStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        cs.createSSLEngines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        cs.test();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        System.out.println("Test Passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * **********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Majority of the test case is above, below is just setup stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * **********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public CheckStatus() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        sslc = getSSLContext(keyFilename, trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Create an initialized SSLContext to use for this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    private SSLContext getSSLContext(String keyFile, String trustFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        KeyStore ks = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        KeyStore ts = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        char[] passphrase = "passphrase".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        ks.load(new FileInputStream(keyFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        ts.load(new FileInputStream(trustFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        kmf.init(ks, passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        tmf.init(ts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        SSLContext sslCtx = SSLContext.getInstance("TLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return sslCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private void createBuffers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        // Size the buffers as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        SSLSession session = ssle1.getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        int appBufferMax = session.getApplicationBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        int netBufferMax = session.getPacketBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        appIn1 = ByteBuffer.allocateDirect(appBufferMax + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        appIn2 = ByteBuffer.allocateDirect(appBufferMax + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        oneToTwo = ByteBuffer.allocateDirect(netBufferMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        twoToOne = ByteBuffer.allocateDirect(netBufferMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        appOut1 = ByteBuffer.wrap("Hi Engine2, I'm SSLEngine1".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        appOut2 = ByteBuffer.wrap("Hello Engine1, I'm SSLEngine2".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        log("AppOut1 = " + appOut1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        log("AppOut2 = " + appOut2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        log("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    private static void runDelegatedTasks(SSLEngine engine) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        Runnable runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        while ((runnable = engine.getDelegatedTask()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            log("running delegated task...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    private static void checkTransfer(ByteBuffer a, ByteBuffer b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        a.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (!a.equals(b)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            throw new Exception("Data didn't transfer cleanly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            log("Data transferred cleanly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        a.position(a.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        b.position(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        a.limit(a.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        b.limit(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    private static void log(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            System.out.println(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
}