test/jdk/sun/security/pkcs11/sslecc/CipherTest.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, 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: 3863
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3863
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3863
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
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Test that all ciphersuites work in all versions and all client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * authentication types. The way this is setup the server is stateless and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * all checking is done on the client side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The test is multithreaded to speed it up, especially on multiprocessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * machines. To simplify debugging, run with -DnumThreads=1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class CipherTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // use any available port for the server socket
29983
244149c6b998 8078348: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java fails with BindException
vinnie
parents: 16913
diff changeset
    47
    static volatile int serverPort = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
    49
    static final int THREADS = Integer.getInteger("numThreads", 4);
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
    50
    static final String TEST_SRC = System.getProperty("test.src", ".");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // assume that if we do not read anything for 20 seconds, something
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // has gone wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    final static int TIMEOUT = 20 * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static KeyStore trustStore, keyStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static X509ExtendedKeyManager keyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static X509TrustManager trustManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static SecureRandom secureRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static PeerFactory peerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
43106
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
    63
    static final CountDownLatch clientCondition = new CountDownLatch(1);
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
    64
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static abstract class Server implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        final CipherTest cipherTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        Server(CipherTest cipherTest) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            this.cipherTest = cipherTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
    73
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public abstract void run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        void handleRequest(InputStream in, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            boolean newline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                int ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                if (ch < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    throw new EOFException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                sb.append((char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                if (ch == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                } else if (ch == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    if (newline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        // 2nd newline in a row, end of request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    newline = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    newline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            String request = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            if (request.startsWith("GET / HTTP/1.") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                throw new IOException("Invalid request: " + request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            out.write("HTTP/1.0 200 OK\r\n\r\n".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
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
    public static class TestParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   108
        CipherSuite cipherSuite;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   109
        Protocol protocol;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        String clientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   112
        TestParameters(CipherSuite cipherSuite, Protocol protocol,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                String clientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            this.cipherSuite = cipherSuite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            this.protocol = protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            this.clientAuth = clientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        boolean isEnabled() {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   120
            return cipherSuite.supportedByProtocol(protocol);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   123
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            String s = cipherSuite + " in " + protocol + " mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (clientAuth != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                s += " with " + clientAuth + " client authentication";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private List<TestParameters> tests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private Iterator<TestParameters> testIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private SSLSocketFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private boolean failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private CipherTest(PeerFactory peerFactory) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        SSLSocket socket = (SSLSocket)factory.createSocket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        String[] cipherSuites = socket.getSupportedCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        String[] protocols = socket.getSupportedProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        String[] clientAuths = {null, "RSA", "DSA", "ECDSA"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        tests = new ArrayList<TestParameters>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            cipherSuites.length * protocols.length * clientAuths.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        for (int i = 0; i < cipherSuites.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            String cipherSuite = cipherSuites[i];
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            for (int j = 0; j < protocols.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                String protocol = protocols[j];
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   151
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   152
                if (!peerFactory.isSupported(cipherSuite, protocol)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   155
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                for (int k = 0; k < clientAuths.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    String clientAuth = clientAuths[k];
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   158
                    // no client with anonymous cipher suites.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   159
                    // TLS_EMPTY_RENEGOTIATION_INFO_SCSV always be skipped.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   160
                    // TLS 1.3 is skipped due to the signature algorithm,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   161
                    // exactly MD5withRSA, in the certificates is not allowed.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   162
                    if ((clientAuth != null && cipherSuite.contains("DH_anon")
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   163
                            || cipherSuite.equals(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   164
                                    CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV.name())
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   165
                            || "TLSv1.3".equals(protocol))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    }
8991
7df5283fd3b8 7027797: take care of ECDH_anon/DH_anon server key exchange for TLS 1.2
xuelei
parents: 7039
diff changeset
   168
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   169
                    tests.add(new TestParameters(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   170
                            CipherSuite.cipherSuite(cipherSuite),
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   171
                            Protocol.protocol(protocol),
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   172
                            clientAuth));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
8991
7df5283fd3b8 7027797: take care of ECDH_anon/DH_anon server key exchange for TLS 1.2
xuelei
parents: 7039
diff changeset
   176
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        testIterator = tests.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    synchronized void setFailed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void run() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Thread[] threads = new Thread[THREADS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        for (int i = 0; i < THREADS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                threads[i] = new Thread(peerFactory.newClient(this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    "Client " + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            threads[i].start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
43106
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   196
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   197
        // The client threads are ready.
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   198
        clientCondition.countDown();
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            for (int i = 0; i < THREADS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                threads[i].join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            setFailed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new Exception("*** Test '" + peerFactory.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                "' failed ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            System.out.println("Test '" + peerFactory.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                "' completed successfully");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    synchronized TestParameters getTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (testIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return (TestParameters)testIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    SSLSocketFactory getFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    static abstract class Client implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        final CipherTest cipherTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        Client(CipherTest cipherTest) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            this.cipherTest = cipherTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   239
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        public final void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                TestParameters params = cipherTest.getTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    // no more tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (params.isEnabled() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    System.out.println("Skipping disabled test " + params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    runTest(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    System.out.println("Passed " + params);
43106
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   254
                } catch (SocketTimeoutException ste) {
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   255
                    System.out.println("The client connects to the server timeout, "
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   256
                            + "so ignore the test.");
4a7670d316ee 8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
fyuan
parents: 35379
diff changeset
   257
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    cipherTest.setFailed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    System.out.println("** Failed " + params + "**");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        abstract void runTest(TestParameters params) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        void sendRequest(InputStream in, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            out.write("GET / HTTP/1.0\r\n\r\n".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                int ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                if (ch < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                sb.append((char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            String response = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (response.startsWith("HTTP/1.0 200 ") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                throw new IOException("Invalid response: " + response);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // for some reason, ${test.src} has a different value when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // test is called from the script and when it is called directly...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    static String pathToStores = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    static String pathToStoresSH = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    static char[] passwd = "passphrase".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    static File PATH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private static KeyStore readKeyStore(String name) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        File file = new File(PATH, name);
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   299
        KeyStore ks;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   300
        try (InputStream in = new FileInputStream(file)) {
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   301
            ks = KeyStore.getInstance("JKS");
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   302
            ks.load(in, passwd);
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   303
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return ks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public static void main(PeerFactory peerFactory, String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        String relPath;
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 2
diff changeset
   311
        if ((args != null) && (args.length > 0) && args[0].equals("sh")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            relPath = pathToStoresSH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            relPath = pathToStores;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   316
        PATH = new File(TEST_SRC, relPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        CipherTest.peerFactory = peerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        System.out.print(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            "Initializing test '" + peerFactory.getName() + "'...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        secureRandom = new SecureRandom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        secureRandom.nextInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        trustStore = readKeyStore(trustStoreFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        keyStore = readKeyStore(keyStoreFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        KeyManagerFactory keyFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            KeyManagerFactory.getInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                KeyManagerFactory.getDefaultAlgorithm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        keyFactory.init(keyStore, passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        keyManager = (X509ExtendedKeyManager)keyFactory.getKeyManagers()[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        trustManager = new AlwaysTrustManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        CipherTest cipherTest = new CipherTest(peerFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        Thread serverThread = new Thread(peerFactory.newServer(cipherTest),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            "Server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        serverThread.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        System.out.println("Done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        cipherTest.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        time = System.currentTimeMillis() - time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        System.out.println("Done. (" + time + " ms)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    static abstract class PeerFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        abstract String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        abstract Client newClient(CipherTest cipherTest) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        abstract Server newServer(CipherTest cipherTest) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   350
        boolean isSupported(String cipherSuite, String protocol) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   351
            // skip kerberos cipher suites
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   352
            if (cipherSuite.startsWith("TLS_KRB5")) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   353
                System.out.println("Skipping unsupported test for " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   354
                                    cipherSuite + " of " + protocol);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   355
                return false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   356
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   357
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   358
            // skip SSLv2Hello protocol
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   359
            if (protocol.equals("SSLv2Hello")) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   360
                System.out.println("Skipping unsupported test for " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   361
                                    cipherSuite + " of " + protocol);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   362
                return false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   363
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   364
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   365
            // ignore exportable cipher suite for TLSv1.1
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   366
            if (protocol.equals("TLSv1.1")) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   367
                if (cipherSuite.indexOf("_EXPORT_WITH") != -1) {
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   368
                    System.out.println("Skipping obsoleted test for " +
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   369
                                        cipherSuite + " of " + protocol);
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   370
                    return false;
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   371
                }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   372
            }
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 6856
diff changeset
   373
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
// we currently don't do any chain verification. we assume that works ok
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
// and we can speed up the test. we could also just add a plain certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
// chain comparision with our trusted certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
class AlwaysTrustManager implements X509TrustManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public AlwaysTrustManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   389
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void checkClientTrusted(X509Certificate[] chain, String authType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   395
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void checkServerTrusted(X509Certificate[] chain, String authType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   401
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public X509Certificate[] getAcceptedIssuers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return new X509Certificate[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
class MyX509KeyManager extends X509ExtendedKeyManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private final X509ExtendedKeyManager keyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private String authType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    MyX509KeyManager(X509ExtendedKeyManager keyManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        this.keyManager = keyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    void setAuthType(String authType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        this.authType = "ECDSA".equals(authType) ? "EC" : authType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   420
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public String[] getClientAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (authType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return keyManager.getClientAliases(authType, issuers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   428
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public String chooseClientAlias(String[] keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (authType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return keyManager.chooseClientAlias(new String[] {authType},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            issuers, socket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   438
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public String chooseEngineClientAlias(String[] keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            Principal[] issuers, SSLEngine engine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (authType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return keyManager.chooseEngineClientAlias(new String[] {authType},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            issuers, engine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   448
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public String[] getServerAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        throw new UnsupportedOperationException("Servers not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   453
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public String chooseServerAlias(String keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        throw new UnsupportedOperationException("Servers not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   459
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public String chooseEngineServerAlias(String keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            SSLEngine engine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        throw new UnsupportedOperationException("Servers not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   465
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public X509Certificate[] getCertificateChain(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return keyManager.getCertificateChain(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   470
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public PrivateKey getPrivateKey(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return keyManager.getPrivateKey(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
class DaemonThreadFactory implements ThreadFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    final static ThreadFactory INSTANCE = new DaemonThreadFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    private final static ThreadFactory DEFAULT = Executors.defaultThreadFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 29983
diff changeset
   483
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public Thread newThread(Runnable r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        Thread t = DEFAULT.newThread(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        t.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}