test/jdk/sun/security/ssl/SSLContextImpl/DefaultDTLSEnabledProtocols.java
author ascarpino
Fri, 25 May 2018 12:43:45 -0700
branchJDK-8145252-TLS13-branch
changeset 56611 f8f7e604e1f8
child 51771 1f805481d8de
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) 2013, 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.client.protocols with DTLS
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    30
 * @run main/othervm DefaultDTLSEnabledProtocols
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    31
 */
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    32
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    33
import java.security.Security;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    34
import java.util.Arrays;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    35
import java.util.HashSet;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    36
import java.util.Set;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    37
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    38
import javax.net.SocketFactory;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    39
import javax.net.ssl.KeyManager;
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
import javax.net.ssl.TrustManager;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    47
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    48
public class DefaultDTLSEnabledProtocols {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    49
    static enum ContextVersion {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    50
        TLS_CV_01("DTLS",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    51
                new String[] {"DTLSv1.0", "DTLSv1.2"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    52
        TLS_CV_02("DTLSv1.0",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    53
                new String[] {"DTLSv1.0"}),
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    54
        TLS_CV_03("DTLSv1.2",
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    55
                new String[] {"DTLSv1.0", "DTLSv1.2"});
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    56
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    57
        final String contextVersion;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    58
        final String[] enabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    59
        final static String[] supportedProtocols = new String[] {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    60
                "DTLSv1.0", "DTLSv1.2"};
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    61
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    62
        ContextVersion(String contextVersion, String[] enabledProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    63
            this.contextVersion = contextVersion;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    64
            this.enabledProtocols = enabledProtocols;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    65
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    66
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    67
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    68
    private static boolean checkProtocols(String[] target, String[] expected) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    69
        boolean success = true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    70
        if (target.length == 0) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    71
            System.out.println("\tError: No protocols");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    72
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    73
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    74
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    75
        if (!protocolEquals(target, expected)) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    76
            System.out.println("\tError: Expected to get protocols " +
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    77
                    Arrays.toString(expected));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    78
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    79
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    80
        System.out.println("\t  Protocols found " + Arrays.toString(target));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    81
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    82
        return success;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    83
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    84
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    85
    private static boolean protocolEquals(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    86
            String[] actualProtocols,
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    87
            String[] expectedProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    88
        if (actualProtocols.length != expectedProtocols.length) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    89
            return false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    90
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    91
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    92
        Set<String> set = new HashSet<>(Arrays.asList(expectedProtocols));
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    93
        for (String actual : actualProtocols) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    94
            if (set.add(actual)) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    95
                return false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    96
            }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    97
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    98
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
    99
        return true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   100
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   101
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   102
    private static boolean checkCipherSuites(String[] target) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   103
        boolean success = true;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   104
        if (target.length == 0) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   105
            System.out.println("\tError: No cipher suites");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   106
            success = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   107
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   108
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   109
        return success;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   110
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   111
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   112
    public static void main(String[] args) throws Exception {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   113
        // reset the security property to make sure that the algorithms
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   114
        // and keys used in this test are not disabled.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   115
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   116
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   117
        boolean failed = false;
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   118
        for (ContextVersion cv : ContextVersion.values()) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   119
            System.out.println("Checking SSLContext of " + cv.contextVersion);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   120
            SSLContext context = SSLContext.getInstance(cv.contextVersion);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   121
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   122
            // Default SSLContext is initialized automatically.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   123
            if (!cv.contextVersion.equals("Default")) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   124
                // Use default TK, KM and random.
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   125
                context.init((KeyManager[])null, (TrustManager[])null, null);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   126
            }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   127
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   128
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   129
            // Check SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   130
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   131
            // Check default SSLParameters of SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   132
            System.out.println("\tChecking default SSLParameters");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   133
            SSLParameters parameters = context.getDefaultSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   134
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   135
            String[] protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   136
            failed |= !checkProtocols(protocols, cv.enabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   137
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   138
            String[] ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   139
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   140
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   141
            // Check supported SSLParameters of SSLContext
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   142
            System.out.println("\tChecking supported SSLParameters");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   143
            parameters = context.getSupportedSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   144
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   145
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   146
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   147
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   148
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   149
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   150
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   151
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   152
            // Check SSLEngine
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   153
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   154
            // Check SSLParameters of SSLEngine
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   155
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   156
            System.out.println("\tChecking SSLEngine of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   157
            System.out.println("\tChecking SSLEngine.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   158
            SSLEngine engine = context.createSSLEngine();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   159
            engine.setUseClientMode(true);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   160
            parameters = engine.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   161
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   162
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   163
            failed |= !checkProtocols(protocols, cv.enabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   164
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   165
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   166
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   167
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   168
            System.out.println("\tChecking SSLEngine.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   169
            protocols = engine.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   170
            failed |= !checkProtocols(protocols, cv.enabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   171
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   172
            System.out.println("\tChecking SSLEngine.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   173
            ciphers = engine.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   174
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   175
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   176
            System.out.println("\tChecking SSLEngine.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   177
            protocols = engine.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   178
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   179
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   180
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   181
                    "\tChecking SSLEngine.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   182
            ciphers = engine.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   183
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   184
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   185
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   186
            // Check SSLSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   187
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   188
            // Check SSLParameters of SSLSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   189
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   190
            System.out.println("\tChecking SSLSocket of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   191
            System.out.println("\tChecking SSLSocket.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   192
            SocketFactory fac = context.getSocketFactory();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   193
            SSLSocket socket = (SSLSocket)fac.createSocket();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   194
            parameters = socket.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   195
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   196
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   197
            failed |= !checkProtocols(protocols, cv.enabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   198
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   199
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   200
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   201
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   202
            System.out.println("\tChecking SSLEngine.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   203
            protocols = socket.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   204
            failed |= !checkProtocols(protocols, cv.enabledProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   205
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   206
            System.out.println("\tChecking SSLEngine.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   207
            ciphers = socket.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   208
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   209
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   210
            System.out.println("\tChecking SSLEngine.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   211
            protocols = socket.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   212
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   213
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   214
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   215
                    "\tChecking SSLEngine.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   216
            ciphers = socket.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   217
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   218
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   219
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   220
            // Check SSLServerSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   221
            //
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   222
            // Check SSLParameters of SSLServerSocket
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   223
            System.out.println();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   224
            System.out.println("\tChecking SSLServerSocket of this SSLContext");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   225
            System.out.println("\tChecking SSLServerSocket.getSSLParameters()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   226
            SSLServerSocketFactory sf = context.getServerSocketFactory();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   227
            SSLServerSocket ssocket = (SSLServerSocket)sf.createServerSocket();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   228
            parameters = ssocket.getSSLParameters();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   229
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   230
            protocols = parameters.getProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   231
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   232
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   233
            ciphers = parameters.getCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   234
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   235
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   236
            System.out.println("\tChecking SSLEngine.getEnabledProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   237
            protocols = ssocket.getEnabledProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   238
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   239
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   240
            System.out.println("\tChecking SSLEngine.getEnabledCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   241
            ciphers = ssocket.getEnabledCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   242
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   243
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   244
            System.out.println("\tChecking SSLEngine.getSupportedProtocols()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   245
            protocols = ssocket.getSupportedProtocols();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   246
            failed |= !checkProtocols(protocols, cv.supportedProtocols);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   247
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   248
            System.out.println(
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   249
                    "\tChecking SSLEngine.getSupportedCipherSuites()");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   250
            ciphers = ssocket.getSupportedCipherSuites();
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   251
            failed |= !checkCipherSuites(ciphers);
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   252
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   253
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   254
        if (failed) {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   255
            throw new Exception("Run into problems, see log for more details");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   256
        } else {
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   257
            System.out.println("\t... Success");
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   258
        }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   259
    }
f8f7e604e1f8 added jdk.tls.server.protocols
ascarpino
parents:
diff changeset
   260
}