jdk/test/javax/net/ssl/SSLEngine/CheckStatus.java
author stefank
Fri, 17 Apr 2015 17:10:38 +0000
changeset 30266 ef82cd1f2db3
parent 23052 241885315119
child 29902 dc24eacaae11
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 6856
diff changeset
     2
 * Copyright (c) 2003, 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
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("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        log("Client Cert");
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("Key Exchange");
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_TASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        runDelegatedTasks(ssle2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
             Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
             Status.OK, HandshakeStatus.NEED_UNWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        log("Finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
             Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
             Status.OK, HandshakeStatus.NEED_WRAP, result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        log("CCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            Status.OK, HandshakeStatus.NEED_UNWRAP, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        log("FINISHED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            Status.OK, HandshakeStatus.FINISHED, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            Status.OK, HandshakeStatus.FINISHED, result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        log("Check Session/Ciphers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        suite = ssle1.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (!suite.equals(suite2[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                suite2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        suite = ssle2.getSession().getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (!suite.equals(suite2[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            throw new Exception("suites not equal: " + suite + "/" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                suite2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        log("DATA USING NEW SESSION");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            appOut1.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            appOut2.capacity(), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        result3 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        checkResult(twoToOne, appIn1, result3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            result2.bytesProduced(), result2.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        result4 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        checkResult(oneToTwo, appIn2, result4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            Status.OK, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            result1.bytesProduced(), result1.bytesConsumed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        appIn1.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        appIn2.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        log("CN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        if (isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            throw new Exception("ssle2 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        ssle2.closeOutbound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (!isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            throw new Exception("ssle1 IS NOT handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        appOut1.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        appOut2.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (ssle1.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        result1 = ssle1.unwrap(twoToOne, appIn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        checkResult(twoToOne, appIn1, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            Status.CLOSED, HandshakeStatus.NEED_WRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            result2.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        twoToOne.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (!ssle1.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (!isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            throw new Exception("ssle1 IS NOT handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        result2 = ssle2.wrap(appOut2, twoToOne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        checkResult(appOut2, twoToOne, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        twoToOne.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        log("======================================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        log("CN response");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (ssle1.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            throw new Exception("ssle1 outboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        result1 = ssle1.wrap(appOut1, oneToTwo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        checkResult(appOut1, oneToTwo, result1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
             Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (!ssle1.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            throw new Exception("ssle1 outboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (isHandshaking(ssle1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        oneToTwo.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (!ssle2.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw new Exception("ssle1 outboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (ssle2.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            throw new Exception("ssle1 inboundDone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        result2 = ssle2.unwrap(oneToTwo, appIn2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        checkResult(oneToTwo, appIn2, result2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
             Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
             result1.bytesProduced(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (!ssle2.isOutboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            throw new Exception("ssle1 outboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (!ssle2.isInboundDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            throw new Exception("ssle1 inboundDone is NOT done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (isHandshaking(ssle2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            throw new Exception("ssle1 IS handshaking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        oneToTwo.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        CheckStatus cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        cs = new CheckStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        cs.createSSLEngines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        cs.test();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        System.out.println("Test Passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * **********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Majority of the test case is above, below is just setup stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * **********************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public CheckStatus() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        sslc = getSSLContext(keyFilename, trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Create an initialized SSLContext to use for this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private SSLContext getSSLContext(String keyFile, String trustFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        KeyStore ks = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        KeyStore ts = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        char[] passphrase = "passphrase".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        ks.load(new FileInputStream(keyFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        ts.load(new FileInputStream(trustFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        kmf.init(ks, passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        tmf.init(ts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        SSLContext sslCtx = SSLContext.getInstance("TLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        return sslCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    private void createBuffers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // Size the buffers as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        SSLSession session = ssle1.getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        int appBufferMax = session.getApplicationBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        int netBufferMax = session.getPacketBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        appIn1 = ByteBuffer.allocateDirect(appBufferMax + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        appIn2 = ByteBuffer.allocateDirect(appBufferMax + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        oneToTwo = ByteBuffer.allocateDirect(netBufferMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        twoToOne = ByteBuffer.allocateDirect(netBufferMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        appOut1 = ByteBuffer.wrap("Hi Engine2, I'm SSLEngine1".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        appOut2 = ByteBuffer.wrap("Hello Engine1, I'm SSLEngine2".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        log("AppOut1 = " + appOut1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        log("AppOut2 = " + appOut2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        log("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    private static void runDelegatedTasks(SSLEngine engine) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        Runnable runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        while ((runnable = engine.getDelegatedTask()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            log("running delegated task...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    private static void checkTransfer(ByteBuffer a, ByteBuffer b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        a.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        if (!a.equals(b)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            throw new Exception("Data didn't transfer cleanly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            log("Data transferred cleanly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        a.position(a.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        b.position(b.limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        a.limit(a.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        b.limit(b.capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    private static void log(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            System.out.println(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
}