test/jdk/sun/security/krb5/auto/UnboundSSLPrincipalProperty.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;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    29
import javax.security.auth.login.LoginException;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    30
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
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    33
 * @bug 8025123 8194486
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    34
 * @summary Checks if an unbound server uses a service principal
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    35
 *          from sun.security.krb5.principal system property if specified
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 UnboundSSLPrincipalProperty
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 UnboundSSLPrincipalProperty
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 UnboundSSLPrincipalProperty {
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) throws IOException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    46
            NoSuchAlgorithmException,LoginException, PrivilegedActionException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    47
            InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    48
        UnboundSSLPrincipalProperty test = new UnboundSSLPrincipalProperty();
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
    public 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 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 service3host = "service3." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    59
        String service1Principal = "host/" + service1host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    60
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    61
        String service3Principal = "host/" + service3host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    62
                + "@" + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    63
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    64
        Map<String, String> principals = new HashMap<>();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    65
        principals.put(UnboundSSLUtils.USER_PRINCIPAL,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    66
                UnboundSSLUtils.USER_PASSWORD);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    67
        principals.put(UnboundSSLUtils.KRBTGT_PRINCIPAL, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    68
        principals.put(service1Principal, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    69
        principals.put(service3Principal, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    70
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    71
        System.setProperty("java.security.krb5.conf",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    72
                UnboundSSLUtils.KRB5_CONF_FILENAME);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    73
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    74
        // start a local KDC instance
31429
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    75
        KDC.startKDC(UnboundSSLUtils.HOST, UnboundSSLUtils.KRB5_CONF_FILENAME,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    76
                UnboundSSLUtils.REALM, principals,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    77
                UnboundSSLUtils.KTAB_FILENAME, KDC.KtabMode.APPEND);
30038
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
        System.setProperty("java.security.auth.login.config",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    80
                UnboundSSLUtils.TEST_SRC + UnboundSSLUtils.FS + jaacConfigFile);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    81
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
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
        // start an SSL server instance
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    84
        try (final SSLEchoServer server = SSLEchoServer.init(
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    85
                UnboundSSLUtils.TLS_KRB5_FILTER, UnboundSSLUtils.SNI_PATTERN)) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    86
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    87
            // specify a service principal for the server
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    88
            System.setProperty("sun.security.krb5.principal",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    89
                    service3Principal);
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
            UnboundSSLUtils.startServerWithJaas(server, serverJaasConfig);
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
            // wait for the server is ready
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    94
            while (!server.isReady()) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    95
                Thread.sleep(UnboundSSLUtils.DELAY);
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    98
            int port = server.getPort();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    99
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   100
            // connetion failure is expected
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   101
            // since service3 principal was specified to use by the server
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   102
            System.out.println("Connect: SNI hostname = " + service1host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   103
                    + ", connection failure is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   104
            try {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   105
                SSLClient.init(UnboundSSLUtils.HOST, port,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   106
                        UnboundSSLUtils.TLS_KRB5_FILTER, service1host)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   107
                            .connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   108
                throw new RuntimeException("Test failed: "
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   109
                        + "expected IOException not thrown");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   110
            } catch (IOException e) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   111
                System.out.println("Expected exception: " + e);
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   114
            System.out.println("Connect: SNI hostname = " + service3host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   115
                    + ", successful connection is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   116
            SSLClient.init(UnboundSSLUtils.HOST, port,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   117
                    UnboundSSLUtils.TLS_KRB5_FILTER, service3host).connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   118
        }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   119
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   120
        System.out.println("Test passed");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   121
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   122
}