jdk/test/javax/net/ssl/TLS/TestJSSE.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 39140 86f21a96d0ab
child 45028 b0ea3c0bfb81
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
     1
/*
35301
12dabfdd1997 8133085: Avoid creating instances of security providers when possible
bgopularam
parents: 31818
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     4
 *
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it under
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     6
 * the terms of the GNU General Public License version 2 only, as published by
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     7
 * the Free Software Foundation.
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     8
 *
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT ANY
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    10
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    11
 * A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    12
 * details (a copy is included in the LICENSE file that accompanied this code).
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    13
 *
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version 2
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    15
 * along with this work; if not, write to the Free Software Foundation, Inc., 51
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    16
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    17
 *
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    19
 * visit www.oracle.com if you need additional information or have any
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    20
 * questions.
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    21
 */
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    22
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    23
import java.security.Provider;
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    24
import java.security.Security;
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    25
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    26
public class TestJSSE {
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    27
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    28
    private static final String LOCAL_IP = "127.0.0.1";
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    29
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    30
    public static void main(String... args) throws Exception {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 26337
diff changeset
    31
        // reset the security property to make sure that the algorithms
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 26337
diff changeset
    32
        // and keys used in this test are not disabled.
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 26337
diff changeset
    33
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 26337
diff changeset
    34
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    35
        // enable debug output
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    36
        System.setProperty("javax.net.debug", "ssl,record");
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    37
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    38
        String srvProtocol = System.getProperty("SERVER_PROTOCOL");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    39
        String clnProtocol = System.getProperty("CLIENT_PROTOCOL");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    40
        String cipher = System.getProperty("CIPHER");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    41
        if (srvProtocol == null || clnProtocol == null || cipher == null) {
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    42
            throw new IllegalArgumentException("Incorrect parameters");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    43
        }
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    44
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    45
        System.out.println("ServerProtocol = " + srvProtocol);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    46
        System.out.println("ClientProtocol = " + clnProtocol);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    47
        System.out.println("Cipher         = " + cipher);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    48
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    49
        try (CipherTestUtils.Server srv = server(srvProtocol, cipher, args)) {
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    50
            client(srv.getPort(), clnProtocol, cipher, args);
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    51
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    52
    }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    53
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    54
    public static void client(int port, String protocols, String cipher,
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    55
            String... exceptions) throws Exception {
38430
e8d1995c38fa 8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents: 35301
diff changeset
    56
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    57
        String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    58
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    59
        System.out.println("This is client");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    60
        System.out.println("Testing protocol: " + protocols);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    61
        System.out.println("Testing cipher  : " + cipher);
38430
e8d1995c38fa 8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents: 35301
diff changeset
    62
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    63
        CipherTestUtils.mainClient(
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    64
            new JSSEFactory(LOCAL_IP, protocols, cipher, "Client JSSE"),
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    65
            port, expectedExcp);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    66
    }
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    67
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    68
    public static CipherTestUtils.Server server(String protocol,
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    69
                String cipher, String... exceptions) throws Exception {
38430
e8d1995c38fa 8134267: javax/net/ssl/TLS/TestJSSE.java fails intermittently with BindException: Address already in use
asmotrak
parents: 35301
diff changeset
    70
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    71
        String expectedExcp = exceptions.length >= 1 ? exceptions[0] : null;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    72
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    73
        System.out.println("This is server");
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    74
        System.out.println("Testing protocol: " + protocol);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    75
        System.out.println("Testing cipher  : " + cipher);
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    76
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    77
        return CipherTestUtils.mainServer(
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    78
            new JSSEFactory(null, protocol, cipher, "Server JSSE"),
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    79
            expectedExcp);
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    80
    }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    81
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    82
    private static class JSSEFactory extends CipherTestUtils.PeerFactory {
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    83
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    84
        private final String cipher;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    85
        private final String protocol;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    86
        private final String host;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    87
        private final String name;
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    88
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    89
        JSSEFactory(String host, String protocol, String cipher, String name) {
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    90
            this.cipher = cipher;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    91
            this.protocol = protocol;
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
    92
            this.host = host;
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    93
            this.name = name;
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    94
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    95
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    96
        @Override
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    97
        String getName() {
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    98
            return name;
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
    99
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   100
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   101
        @Override
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   102
        String getTestedCipher() {
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   103
            return cipher;
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   104
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   105
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   106
        @Override
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   107
        String getTestedProtocol() {
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   108
            return protocol;
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   109
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   110
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   111
        @Override
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   112
        CipherTestUtils.Client newClient(CipherTestUtils cipherTest, int port)
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   113
                throws Exception {
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   114
            return new JSSEClient(cipherTest, host, port, protocol, cipher);
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   115
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   116
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   117
        @Override
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   118
        CipherTestUtils.Server newServer(CipherTestUtils cipherTest, int port)
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   119
                throws Exception {
39140
86f21a96d0ab 8152745: javax/net/ssl/TLS/TestJSSE.java fails intermittently: Unsupported or unrecognized SSL message
asmotrak
parents: 38430
diff changeset
   120
            return new JSSEServer(cipherTest, port, protocol, cipher);
26337
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   121
        }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   122
    }
39f3ee5364e5 8049429: Tests for java client server communications with various TLS/SSL combinations.
xuelei
parents:
diff changeset
   123
}