test/jdk/sun/security/ssl/SSLContextImpl/CustomizedServerDefaultProtocols.java
author ascarpino
Fri, 25 May 2018 12:43:45 -0700
branchJDK-8145252-TLS13-branch
changeset 56611 f8f7e604e1f8
permissions -rw-r--r--
added jdk.tls.server.protocols
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56611
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     1
/*
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     4
 *
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     8
 *
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    13
 * accompanied this code).
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    14
 *
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    18
 *
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    21
 * questions.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    22
 */
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    23
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    24
// SunJSSE does not support dynamic system properties, no way to re-use
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    25
// system properties in samevm/agentvm mode.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    26
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    27
/*
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    28
 * @test
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    29
 * @summary Test jdk.tls.server.protocols with TLS
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    30
 * @run main/othervm -Djdk.tls.server.protocols="SSLv3,TLSv1,TLSv1.1"
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    31
 *      CustomizedServerDefaultProtocols
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    32
 */
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    33
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    34
import java.security.Security;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    35
import java.util.Arrays;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    36
import java.util.HashSet;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    37
import java.util.Set;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    38
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    39
import javax.net.SocketFactory;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    40
import javax.net.ssl.SSLContext;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    41
import javax.net.ssl.SSLEngine;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    42
import javax.net.ssl.SSLParameters;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    43
import javax.net.ssl.SSLServerSocket;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    44
import javax.net.ssl.SSLServerSocketFactory;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    45
import javax.net.ssl.SSLSocket;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    46
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    47
public class CustomizedServerDefaultProtocols {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    48
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    49
    final static String[] supportedProtocols = new String[]{
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    50
            "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"};
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    51
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    52
    enum ContextVersion {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    53
        TLS_CV_01("SSL",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    54
                new String[]{"SSLv3", "TLSv1", "TLSv1.1"},
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    55
                new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    56
        TLS_CV_02("TLS",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    57
                new String[]{"SSLv3", "TLSv1", "TLSv1.1"},
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    58
                new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    59
        TLS_CV_03("SSLv3",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    60
                supportedProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    61
                new String[]{"SSLv3", "TLSv1"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    62
        TLS_CV_04("TLSv1",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    63
                supportedProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    64
                new String[]{"SSLv3", "TLSv1"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    65
        TLS_CV_05("TLSv1.1",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    66
                supportedProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    67
                new String[]{"SSLv3", "TLSv1", "TLSv1.1"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    68
        TLS_CV_06("TLSv1.2",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    69
                supportedProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    70
                new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    71
        TLS_CV_07("TLSv1.3",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    72
                supportedProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    73
                new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    74
        TLS_CV_08("Default",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    75
                new String[]{"SSLv3", "TLSv1", "TLSv1.1"},
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    76
                new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"});
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    77
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    78
        final String contextVersion;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    79
        final String[] serverEnabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    80
        final String[] clientEnabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    81
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    82
        ContextVersion(String contextVersion, String[] serverEnabledProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    83
                String[] clientEnabledProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    84
            this.contextVersion = contextVersion;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    85
            this.serverEnabledProtocols = serverEnabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    86
            this.clientEnabledProtocols = clientEnabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    87
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    88
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    89
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    90
    private static boolean checkProtocols(String[] target, String[] expected) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    91
        boolean success = true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    92
        if (target.length == 0) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    93
            System.out.println("\tError: No protocols");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    94
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    95
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    96
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    97
        if (!protocolEquals(target, expected)) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    98
            System.out.println("\tError: Expected to get protocols " +
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    99
                    Arrays.toString(expected));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   100
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   101
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   102
        System.out.println("\t  Protocols found " + Arrays.toString(target));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   103
        return success;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   104
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   105
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   106
    private static boolean protocolEquals(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   107
            String[] actualProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   108
            String[] expectedProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   109
        if (actualProtocols.length != expectedProtocols.length) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   110
            return false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   111
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   112
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   113
        Set<String> set = new HashSet<>(Arrays.asList(expectedProtocols));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   114
        for (String actual : actualProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   115
            if (set.add(actual)) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   116
                return false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   117
            }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   118
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   119
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   120
        return true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   121
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   122
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   123
    private static boolean checkCipherSuites(String[] target) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   124
        boolean success = true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   125
        if (target.length == 0) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   126
            System.out.println("\tError: No cipher suites");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   127
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   128
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   129
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   130
        return success;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   131
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   132
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   133
    public static void main(String[] args) throws Exception {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   134
        // reset the security property to make sure that the algorithms
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   135
        // and keys used in this test are not disabled.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   136
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   137
        System.out.println("jdk.tls.client.protocols = " +
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   138
                System.getProperty("jdk.tls.client.protocols"));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   139
        System.out.println("jdk.tls.server.protocols = "+
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   140
                System.getProperty("jdk.tls.server.protocols"));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   141
        Test();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   142
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   143
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   144
    static void Test() throws Exception {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   145
        boolean failed = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   146
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   147
        for (ContextVersion cv : ContextVersion.values()) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   148
            System.out.println("Checking SSLContext of " + cv.contextVersion);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   149
            SSLContext context = SSLContext.getInstance(cv.contextVersion);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   150
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   151
            // Default SSLContext is initialized automatically.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   152
            if (!cv.contextVersion.equals("Default")) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   153
                // Use default TK, KM and random.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   154
                context.init(null, null, null);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   155
            }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   156
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   157
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   158
            // Check SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   159
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   160
            // Check default SSLParameters of SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   161
            System.out.println("\tChecking default SSLParameters");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   162
            SSLParameters parameters = context.getDefaultSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   163
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   164
            String[] protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   165
            failed |= !checkProtocols(protocols, cv.clientEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   166
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   167
            String[] ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   168
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   169
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   170
            // Check supported SSLParameters of SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   171
            System.out.println("\tChecking supported SSLParameters");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   172
            parameters = context.getSupportedSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   173
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   174
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   175
            failed |= !checkProtocols(protocols, supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   176
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   177
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   178
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   179
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   180
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   181
            // Check SSLEngine
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   182
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   183
            // Check SSLParameters of SSLEngine
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   184
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   185
            System.out.println("\tChecking SSLEngine of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   186
            System.out.println("\tChecking SSLEngine.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   187
            SSLEngine engine = context.createSSLEngine();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   188
            engine.setUseClientMode(true);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   189
            parameters = engine.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   190
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   191
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   192
            failed |= !checkProtocols(protocols, cv.clientEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   193
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   194
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   195
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   196
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   197
            System.out.println("\tChecking SSLEngine.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   198
            protocols = engine.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   199
            failed |= !checkProtocols(protocols, cv.clientEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   200
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   201
            System.out.println("\tChecking SSLEngine.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   202
            ciphers = engine.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   203
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   204
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   205
            System.out.println("\tChecking SSLEngine.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   206
            protocols = engine.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   207
            failed |= !checkProtocols(protocols, supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   208
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   209
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   210
                    "\tChecking SSLEngine.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   211
            ciphers = engine.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   212
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   213
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   214
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   215
            // Check SSLSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   216
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   217
            // Check SSLParameters of SSLSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   218
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   219
            System.out.println("\tChecking SSLSocket of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   220
            System.out.println("\tChecking SSLSocket.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   221
            SocketFactory fac = context.getSocketFactory();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   222
            SSLSocket socket = (SSLSocket) fac.createSocket();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   223
            parameters = socket.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   224
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   225
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   226
            failed |= !checkProtocols(protocols, cv.clientEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   227
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   228
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   229
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   230
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   231
            System.out.println("\tChecking SSLSocket.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   232
            protocols = socket.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   233
            failed |= !checkProtocols(protocols, cv.clientEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   234
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   235
            System.out.println("\tChecking SSLSocket.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   236
            ciphers = socket.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   237
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   238
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   239
            System.out.println("\tChecking SSLSocket.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   240
            protocols = socket.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   241
            failed |= !checkProtocols(protocols, supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   242
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   243
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   244
                    "\tChecking SSLSocket.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   245
            ciphers = socket.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   246
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   247
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   248
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   249
            // Check SSLServerSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   250
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   251
            // Check SSLParameters of SSLServerSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   252
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   253
            System.out.println("\tChecking SSLServerSocket of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   254
            System.out.println("\tChecking SSLServerSocket.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   255
            SSLServerSocketFactory sf = context.getServerSocketFactory();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   256
            SSLServerSocket ssocket = (SSLServerSocket) sf.createServerSocket();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   257
            parameters = ssocket.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   258
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   259
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   260
            failed |= !checkProtocols(protocols, cv.serverEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   261
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   262
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   263
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   264
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   265
            System.out.println("\tChecking SSLEngine.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   266
            protocols = ssocket.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   267
            failed |= !checkProtocols(protocols, cv.serverEnabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   268
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   269
            System.out.println("\tChecking SSLEngine.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   270
            ciphers = ssocket.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   271
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   272
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   273
            System.out.println("\tChecking SSLEngine.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   274
            protocols = ssocket.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   275
            failed |= !checkProtocols(protocols, supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   276
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   277
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   278
                    "\tChecking SSLEngine.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   279
            ciphers = ssocket.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   280
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   281
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   282
            if (failed) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   283
                throw new Exception("Run into problems, see log for more details");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   284
            } else {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   285
                System.out.println("\t... Success");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   286
            }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   287
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   288
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   289
}