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