jdk/test/sun/security/krb5/auto/UnboundSSLMultipleKeys.java
author stefank
Mon, 04 Apr 2016 09:15:01 +0200
changeset 37241 b9961c99c356
parent 31429 ce4193650b40
permissions -rw-r--r--
8152538: UL doesn't inline the LogTagSet::is_level check Reviewed-by: mlarsson, brutisso
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
/*
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    34
 * @bug 8025123
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    36
 * @run main/othervm UnboundSSLMultipleKeys
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    37
 *                              unbound.ssl.jaas.conf server_star
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    38
 * @run main/othervm UnboundSSLMultipleKeys
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    39
 *                              unbound.ssl.jaas.conf server_multiple_principals
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    40
 */
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    41
public class UnboundSSLMultipleKeys {
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 static void main(String[] args)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    44
            throws IOException, NoSuchAlgorithmException, LoginException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    45
            PrivilegedActionException, InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    46
        UnboundSSLMultipleKeys test = new UnboundSSLMultipleKeys();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    47
        test.start(args[0], args[1]);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    48
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    49
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    50
    private void start(String jaacConfigFile, String serverJaasConfig)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    51
            throws IOException, NoSuchAlgorithmException, LoginException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    52
            PrivilegedActionException, InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    53
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    54
        // define service principals
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    55
        String service1host = "service1." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    56
        String service2host = "service2." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    57
        String service3host = "service3." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    58
        String service1Principal = "host/" + service1host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    59
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    60
        String service2Principal = "host/" + service2host + "@"
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 service3Principal = "host/" + service3host + "@"
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    65
        Map<String, String> principals = new HashMap<>();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    66
        principals.put(UnboundSSLUtils.USER_PRINCIPAL,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    67
                UnboundSSLUtils.USER_PASSWORD);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    68
        principals.put(UnboundSSLUtils.KRBTGT_PRINCIPAL, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    69
        principals.put(service1Principal, "pass0");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    70
        principals.put(service1Principal, "pass1");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    71
        principals.put(service1Principal, "pass2");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    72
        principals.put(service2Principal, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    73
        principals.put(service3Principal, "pass");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    74
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    75
        System.setProperty("java.security.krb5.conf",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    76
                UnboundSSLUtils.KRB5_CONF_FILENAME);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    77
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    78
        /*
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    79
         * Start a local KDC instance
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
         * 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
    82
         * 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
    83
         * for service1 principal in KDC.
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    84
         */
31429
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    85
        KDC.startKDC(UnboundSSLUtils.HOST, UnboundSSLUtils.KRB5_CONF_FILENAME,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    86
                UnboundSSLUtils.REALM, principals,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    87
                UnboundSSLUtils.KTAB_FILENAME, KDC.KtabMode.APPEND);
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    88
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    89
        System.setProperty("java.security.auth.login.config",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    90
                UnboundSSLUtils.TEST_SRC + UnboundSSLUtils.FS + jaacConfigFile);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    91
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    92
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    93
        // start an SSL server instance
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    94
        try (SSLEchoServer server = SSLEchoServer.init(
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    95
                UnboundSSLUtils.TLS_KRB5_FILTER, UnboundSSLUtils.SNI_PATTERN)) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    96
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    97
            UnboundSSLUtils.startServerWithJaas(server, serverJaasConfig);
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
            //  wait for the server is ready
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   100
            while (!server.isReady()) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   101
                Thread.sleep(UnboundSSLUtils.DELAY);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   102
            }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   103
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   104
            // run a client
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   105
            System.out.println("Successful connection is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   106
            SSLClient.init(UnboundSSLUtils.HOST, server.getPort(),
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   107
                    UnboundSSLUtils.TLS_KRB5_FILTER, service1host).connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   108
        }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   109
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   110
        System.out.println("Test passed");
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   113
}