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