jdk/test/javax/net/ssl/SSLEngine/ArgCheck.java
author stefank
Fri, 17 Apr 2015 17:10:38 +0000
changeset 30266 ef82cd1f2db3
parent 23052 241885315119
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2007, 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: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 5019096
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Add scatter/gather APIs for SSLEngine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Check to see if the args are being parsed properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.net.ssl.SSLEngineResult.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class ArgCheck {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 5506
diff changeset
    43
    private static String pathToStores = "../etc";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static void tryNull(SSLEngine ssle, ByteBuffer appData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            ByteBuffer netData) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            ssle.wrap(appData, netData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            ssle.unwrap(netData, appData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static void tryNullArray(SSLEngine ssle, ByteBuffer [] appData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            ByteBuffer netData) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            ssle.wrap(appData, netData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            ssle.unwrap(netData, appData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static void tryNullArrayLen(SSLEngine ssle, ByteBuffer [] appData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            int offset, int len, ByteBuffer netData) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            ssle.wrap(appData, offset, len, netData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            ssle.unwrap(netData, appData, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static void tryReadOnly(SSLEngine ssle, ByteBuffer [] appData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            int offset, int len, ByteBuffer netData) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (netData.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                ssle.wrap(appData, offset, len, netData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch (ReadOnlyBufferException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (!netData.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                ssle.unwrap(netData, appData, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } catch (ReadOnlyBufferException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static void tryOutOfBounds(SSLEngine ssle, ByteBuffer [] appData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            int offset, int len, ByteBuffer netData) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            ssle.wrap(appData, offset, len, netData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } catch (IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            ssle.unwrap(netData, appData, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } catch (IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.out.println("Caught right exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static void trySmallBufs(SSLEngine ssle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            ByteBuffer appBB, ByteBuffer smallNetBB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            ByteBuffer smallAppBB, ByteBuffer netBB) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        SSLEngineResult res = ssle.wrap(appBB, smallNetBB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (res.getStatus() != Status.BUFFER_OVERFLOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // For unwrap(), the BUFFER_OVERFLOW will not be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // until received SSL/TLS application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // Test test/javax/net/ssl/NewAPIs/SSLEngine/LargePacket will check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // BUFFER_OVERFLOW/UNDERFLOW for both wrap() and unwrap().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        //res = ssle.unwrap(netBB, smallAppBB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        //if (res.getStatus() != Status.BUFFER_OVERFLOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        //    throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private static void trySmallBufsArray(SSLEngine ssle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            ByteBuffer [] appBB, ByteBuffer smallNetBB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            ByteBuffer [] smallAppBB, ByteBuffer netBB) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        SSLEngineResult res = ssle.wrap(appBB, 0, appBB.length, smallNetBB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (res.getStatus() != Status.BUFFER_OVERFLOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // For unwrap(), the BUFFER_OVERFLOW will not be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // until received SSL/TLS application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // Test test/javax/net/ssl/NewAPIs/SSLEngine/LargePacket will check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // BUFFER_OVERFLOW/UNDERFLOW for both wrap() and unwrap().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        //res = ssle.unwrap(netBB, smallAppBB, 0, appBB.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        //if (res.getStatus() != Status.BUFFER_OVERFLOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        //    throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static void runTest(SSLEngine ssle) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        ByteBuffer [] bufs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        ByteBuffer roBB = ByteBuffer.allocate(40).asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        ByteBuffer bb1K = ByteBuffer.allocate(1024);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        ByteBuffer bb2K = ByteBuffer.allocate(2048);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        ByteBuffer bb4K = ByteBuffer.allocate(5096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        ByteBuffer bb8K = ByteBuffer.allocate(10192);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        SSLSession ssls = ssle.getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        ByteBuffer netBBMinus1 = ByteBuffer.allocate(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            ssls.getPacketBufferSize() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        ByteBuffer appBBMinus1 = ByteBuffer.allocate(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            ssls.getApplicationBufferSize() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        ByteBuffer bbNet = ByteBuffer.allocate(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            ssls.getPacketBufferSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        ByteBuffer bbApp = ByteBuffer.allocate(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            ssls.getApplicationBufferSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        bufs = new ByteBuffer [] { bb1K, bb2K, bb4K, bb8K};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        tryNull(ssle, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        tryNull(ssle, bb1K, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        tryNull(ssle, null, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        tryNullArray(ssle, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        tryNullArray(ssle, bufs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        tryNullArray(ssle, null, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        tryNullArrayLen(ssle, null, 0, 4, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        tryNullArrayLen(ssle, bufs, 0, 4, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        tryNullArrayLen(ssle, null, 0, 4, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        bufs[2] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        tryNullArray(ssle, bufs, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        bufs[2] = bb4K;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        tryReadOnly(ssle, bufs, 0, 4, roBB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        bufs[2] = roBB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        tryReadOnly(ssle, bufs, 0, 4, bb4K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        bufs[2] = bb4K;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        tryOutOfBounds(ssle, bufs, -1, 0, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        tryOutOfBounds(ssle, bufs, 0, -1, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        tryOutOfBounds(ssle, bufs, 0, bufs.length + 1, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        tryOutOfBounds(ssle, bufs, bufs.length, 1, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        bufs[3].position(bufs[3].limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        trySmallBufs(ssle, bb1K, netBBMinus1, appBBMinus1, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        trySmallBufsArray(ssle, bufs, netBBMinus1, bufs, bb1K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        bufs[3].rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        SSLEngine ssle = createSSLEngine(keyFilename, trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        runTest(ssle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        System.out.println("Test Passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Create an initialized SSLContext to use for this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    static private SSLEngine createSSLEngine(String keyFile, String trustFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        SSLEngine ssle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        KeyStore ks = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        KeyStore ts = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        char[] passphrase = "passphrase".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ks.load(new FileInputStream(keyFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        ts.load(new FileInputStream(trustFile), passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        kmf.init(ks, passphrase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        tmf.init(ts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        SSLContext sslCtx = SSLContext.getInstance("TLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        ssle = sslCtx.createSSLEngine("client", 1001);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        ssle.setUseClientMode(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return ssle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}