test/jdk/sun/security/krb5/auto/UnboundSSL.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 can handle connections
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    36
 *          only for allowed service principals
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    37
 * @library /test/lib
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    38
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    39
 * @run main/othervm/policy=unbound.ssl.policy -Djdk.net.hosts.file=TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    40
 *      UnboundSSL unbound.ssl.jaas.conf server_star
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    41
 * @run main/othervm/policy=unbound.ssl.policy -Djdk.net.hosts.file=TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    42
 *      UnboundSSL unbound.ssl.jaas.conf server_multiple_principals
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    43
 */
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    44
public class UnboundSSL {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    45
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    46
    public static void main(String[] args) throws IOException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    47
            NoSuchAlgorithmException,LoginException, PrivilegedActionException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    48
            InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    49
        UnboundSSL test = new UnboundSSL();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    50
        test.start(args[0], args[1]);
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    53
    private void start(String jaacConfigFile, String serverJaasConfig)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    54
            throws IOException, NoSuchAlgorithmException,LoginException,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    55
            PrivilegedActionException, InterruptedException {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    56
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    57
        // define principals
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    58
        String service1host = "service1." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    59
        String service2host = "service2." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    60
        String service3host = "service3." + UnboundSSLUtils.HOST;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    61
        String service1Principal = "host/" + service1host + "@"
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
        String service2Principal = "host/" + service2host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    64
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    65
        String service3Principal = "host/" + service3host + "@"
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    66
                + UnboundSSLUtils.REALM;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    67
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    68
        Map<String, String> principals = new HashMap<>();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    69
        principals.put(UnboundSSLUtils.USER_PRINCIPAL,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    70
                UnboundSSLUtils.USER_PASSWORD);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    71
        principals.put(UnboundSSLUtils.KRBTGT_PRINCIPAL, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    72
        principals.put(service1Principal, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    73
        principals.put(service2Principal, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    74
        principals.put(service3Principal, null);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    75
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    76
        System.setProperty("java.security.krb5.conf",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    77
               UnboundSSLUtils.KRB5_CONF_FILENAME);
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
31429
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    80
        KDC.startKDC(UnboundSSLUtils.HOST, UnboundSSLUtils.KRB5_CONF_FILENAME,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    81
                UnboundSSLUtils.REALM, principals,
ce4193650b40 8075301: Tests for sun.security.krb5.principal system property
weijun
parents: 30038
diff changeset
    82
                UnboundSSLUtils.KTAB_FILENAME, KDC.KtabMode.APPEND);
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    83
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    84
        System.setProperty("java.security.auth.login.config",
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    85
                UnboundSSLUtils.TEST_SRC + UnboundSSLUtils.FS + jaacConfigFile);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    86
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    87
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    88
        try (final SSLEchoServer server = SSLEchoServer.init(
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    89
                UnboundSSLUtils.TLS_KRB5_FILTER, UnboundSSLUtils.SNI_PATTERN)) {
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
            // start a server instance
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    92
            UnboundSSLUtils.startServerWithJaas(server, serverJaasConfig);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    93
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    94
            // wait for the server is ready
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    95
            while (!server.isReady()) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    96
                Thread.sleep(UnboundSSLUtils.DELAY);
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
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
    99
            int port = server.getPort();
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
            // run clients
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
            // the server should have a permission to handle a request
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   104
            // with this service principal (there should be an appropriate
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   105
            // javax.security.auth.kerberos.ServicePermission in policy file)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   106
            System.out.println("Connect: SNI hostname = " + service1host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   107
                    + ", 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, port,
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
            // the server should NOT have a permission to handle a request
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   112
            // with this service principal (there should be an appropriate
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   113
            // javax.security.auth.kerberos.ServicePermission in policy file)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   114
            // handshake failures is expected
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   115
            System.out.println("Connect: SNI hostname = " + service2host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   116
                    + ", connection failure is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   117
            try {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   118
                SSLClient.init(UnboundSSLUtils.HOST, port,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   119
                        UnboundSSLUtils.TLS_KRB5_FILTER, service2host)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   120
                            .connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   121
                throw new RuntimeException("Test failed: "
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   122
                        + "expected IOException not thrown");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   123
            } catch (IOException e) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   124
                System.out.println("Expected exception: " + e);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   125
            }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   126
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   127
            // the server should have a permission to handle a request
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   128
            // with this service principal (there should be an appropriate
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   129
            // javax.security.auth.kerberos.ServicePermission in policy file)
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   130
            System.out.println("Connect: SNI hostname = " + service3host
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   131
                    + ", successful connection is expected");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   132
            SSLClient.init(UnboundSSLUtils.HOST, port,
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   133
                    UnboundSSLUtils.TLS_KRB5_FILTER, service3host).connect();
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   134
        }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   135
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   136
        System.out.println("Test passed");
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   137
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff changeset
   138
}