test/jdk/sun/security/krb5/auto/UnboundSSLMultipleKeys.java
author ssahoo
Thu, 25 Jan 2018 05:57:22 -0800
changeset 48668 2da4a52715d8
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194486: Several krb5 tests failed in Mac. Summary: Several tests failed due to improper host service Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     4
 *
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     7
 * published by the Free Software Foundation.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     8
 *
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    13
 * accompanied this code).
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    14
 *
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    18
 *
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    21
 * questions.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    22
 */
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    23
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    24
import java.io.IOException;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    25
import java.security.NoSuchAlgorithmException;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    26
import java.security.PrivilegedActionException;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    27
import java.util.HashMap;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    28
import java.util.Map;
31429
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    29
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    30
import javax.security.auth.login.LoginException;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    31
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    32
/*
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    33
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    34
 * @bug 8025123 8194486
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    35
 * @summary Checks if an unbound server pick up a correct key from keytab
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    36
 * @library /test/lib
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    37
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    38
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundSSLMultipleKeys
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    39
 *                              unbound.ssl.jaas.conf server_star
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    40
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundSSLMultipleKeys
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    41
 *                              unbound.ssl.jaas.conf server_multiple_principals
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    42
 */
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    43
public class UnboundSSLMultipleKeys {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    44
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    45
    public static void main(String[] args)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    46
            throws IOException, NoSuchAlgorithmException, LoginException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    47
            PrivilegedActionException, InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    48
        UnboundSSLMultipleKeys test = new UnboundSSLMultipleKeys();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    49
        test.start(args[0], args[1]);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    50
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    51
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    52
    private void start(String jaacConfigFile, String serverJaasConfig)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    53
            throws IOException, NoSuchAlgorithmException, LoginException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    54
            PrivilegedActionException, InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    55
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    56
        // define service principals
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    57
        String service1host = "service1." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    58
        String service2host = "service2." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    59
        String service3host = "service3." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    60
        String service1Principal = "host/" + service1host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    61
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    62
        String service2Principal = "host/" + service2host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    63
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    64
        String service3Principal = "host/" + service3host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    65
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    66
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    67
        Map<String, String> principals = new HashMap<>();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    68
        principals.put(UnboundSSLUtils.USER_PRINCIPAL,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    69
                UnboundSSLUtils.USER_PASSWORD);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    70
        principals.put(UnboundSSLUtils.KRBTGT_PRINCIPAL, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    71
        principals.put(service1Principal, "pass0");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    72
        principals.put(service1Principal, "pass1");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    73
        principals.put(service1Principal, "pass2");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    74
        principals.put(service2Principal, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    75
        principals.put(service3Principal, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    76
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    77
        System.setProperty("java.security.krb5.conf",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    78
                UnboundSSLUtils.KRB5_CONF_FILENAME);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    79
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    80
        /*
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    81
         * Start a local KDC instance
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    82
         *
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    83
         * Keytab file contains 3 keys (with different KVNO) for service1
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    84
         * principal, but password for only one key is the same with the record
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    85
         * for service1 principal in KDC.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    86
         */
31429
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    87
        KDC.startKDC(UnboundSSLUtils.HOST, UnboundSSLUtils.KRB5_CONF_FILENAME,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    88
                UnboundSSLUtils.REALM, principals,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    89
                UnboundSSLUtils.KTAB_FILENAME, KDC.KtabMode.APPEND);
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    90
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    91
        System.setProperty("java.security.auth.login.config",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    92
                UnboundSSLUtils.TEST_SRC + UnboundSSLUtils.FS + jaacConfigFile);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    93
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    94
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    95
        // start an SSL server instance
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    96
        try (SSLEchoServer server = SSLEchoServer.init(
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    97
                UnboundSSLUtils.TLS_KRB5_FILTER, UnboundSSLUtils.SNI_PATTERN)) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    98
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    99
            UnboundSSLUtils.startServerWithJaas(server, serverJaasConfig);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   100
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   101
            //  wait for the server is ready
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   102
            while (!server.isReady()) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   103
                Thread.sleep(UnboundSSLUtils.DELAY);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   104
            }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   105
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   106
            // run a client
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   107
            System.out.println("Successful connection is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   108
            SSLClient.init(UnboundSSLUtils.HOST, server.getPort(),
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   109
                    UnboundSSLUtils.TLS_KRB5_FILTER, service1host).connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   110
        }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   111
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   112
        System.out.println("Test passed");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   113
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   114
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   115
}