jdk/test/sun/security/ssl/sanity/ciphersuites/NoKerberos.java
author alanb
Mon, 21 Jan 2013 23:35:36 -0500
changeset 15685 14c6889b6132
child 23010 6dadb192ad81
permissions -rw-r--r--
8004502: Compact Profiles contents Reviewed-by: dholmes, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15685
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     1
/*
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     4
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     8
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    13
 * accompanied this code).
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    14
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    18
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    21
 * questions.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    22
 */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    23
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    24
/* @test
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    25
 * @bug 8004502
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    26
 * @summary Sanity check to ensure that Kerberos cipher suites cannot be
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    27
 *   negotiated when running on a compact profile that does not include Kerberos
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    28
 */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    29
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    30
import java.net.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    31
import java.util.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    32
import javax.net.ssl.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    33
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    34
public class NoKerberos {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    35
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    36
    static final List<String> KERBEROS_CIPHER_SUITES = Arrays.asList(
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    37
        "TLS_KRB5_WITH_RC4_128_SHA",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    38
        "TLS_KRB5_WITH_RC4_128_MD5",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    39
        "TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    40
        "TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    41
        "TLS_KRB5_WITH_DES_CBC_SHA",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    42
        "TLS_KRB5_WITH_DES_CBC_MD5",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    43
        "TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    44
        "TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    45
        "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    46
        "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    47
    );
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    48
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    49
    /**
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    50
     * Checks that the given array of supported cipher suites does not include
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    51
     * any Kerberos cipher suites.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    52
     */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    53
    static void checkNotSupported(String[] supportedSuites) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    54
        for (String suites: supportedSuites) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    55
            if (KERBEROS_CIPHER_SUITES.contains(suites)) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    56
                throw new RuntimeException("Supported list of cipher suites " +
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    57
                    " should not include Kerberos cipher suites");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    58
            }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    59
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    60
    }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    61
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    63
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    64
            Class.forName("javax.security.auth.kerberos.KerberosPrincipal");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    65
            System.out.println("Kerberos is present, nothing to test");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    66
            return;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    67
        } catch (ClassNotFoundException okay) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    68
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    69
        // test SSLSocket
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    70
        try (Socket s = SSLSocketFactory.getDefault().createSocket()) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    71
            SSLSocket sslSocket = (SSLSocket)s;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    72
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    73
            checkNotSupported(sslSocket.getSupportedCipherSuites());
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    74
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    75
            // attempt to enable each of the Kerberos cipher suites
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    76
            for (String kcs: KERBEROS_CIPHER_SUITES) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    77
                String[] suites = { kcs };
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    78
                try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    79
                    sslSocket.setEnabledCipherSuites(suites);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    80
                    throw new RuntimeException("SSLSocket.setEnabledCipherSuitessuites allowed " +
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    81
                        kcs + " but Kerberos not supported");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    82
                } catch (IllegalArgumentException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    83
            }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    84
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    85
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    86
        // test SSLServerSocket
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    87
        try (ServerSocket ss = SSLServerSocketFactory.getDefault().createServerSocket()) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    88
            SSLServerSocket sslSocket = (SSLServerSocket)ss;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    89
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    90
            checkNotSupported(sslSocket.getSupportedCipherSuites());
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    91
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    92
            // attempt to enable each of the Kerberos cipher suites
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    93
            for (String kcs: KERBEROS_CIPHER_SUITES) {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    94
                String[] suites = { kcs };
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    95
                try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    96
                    sslSocket.setEnabledCipherSuites(suites);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    97
                    throw new RuntimeException("SSLSocket.setEnabledCipherSuitessuites allowed " +
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    98
                        kcs + " but Kerberos not supported");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    99
                } catch (IllegalArgumentException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   100
            }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   101
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   102
    }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   103
}