jdk/test/sun/security/krb5/auto/NoAddresses.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 9240 56e01f64958e
child 31474 7b79555b8073
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9240
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     1
/*
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     4
 *
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     8
 *
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    13
 * accompanied this code).
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    14
 *
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    18
 *
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    21
 * questions.
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    22
 */
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    23
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    24
/*
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    25
 * @test
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    26
 * @bug 7032354
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    27
 * @modules java.base/sun.net.spi.nameservice
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    28
 *          java.base/sun.security.util
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    29
 *          java.security.jgss/sun.security.jgss
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    30
 *          java.security.jgss/sun.security.krb5
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    31
 *          java.security.jgss/sun.security.krb5.internal
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    32
 *          java.security.jgss/sun.security.krb5.internal.ccache
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    33
 *          java.security.jgss/sun.security.krb5.internal.crypto
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 9240
diff changeset
    34
 *          java.security.jgss/sun.security.krb5.internal.ktab
9240
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    35
 * @run main/othervm NoAddresses 1
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    36
 * @run main/othervm NoAddresses 2
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    37
 * @run main/othervm/fail NoAddresses 3
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    38
 * @summary no-addresses should not be used on acceptor side
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    39
 */
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    40
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    41
import java.net.InetAddress;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    42
import org.ietf.jgss.ChannelBinding;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    43
import sun.security.jgss.GSSUtil;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    44
import sun.security.krb5.Config;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    45
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    46
public class NoAddresses {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    47
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    48
    public static void main(String[] args)
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    49
            throws Exception {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    50
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    51
        OneKDC kdc = new OneKDC(null);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    52
        kdc.writeJAASConf();
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    53
        KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    54
                "noaddresses = false",
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    55
                "default_keytab_name = " + OneKDC.KTAB);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    56
        Config.refresh();
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    57
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    58
        Context c = Context.fromJAAS("client");
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    59
        Context s = Context.fromJAAS("server");
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    60
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    61
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    62
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    63
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    64
        InetAddress initiator = InetAddress.getLocalHost();
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    65
        InetAddress acceptor = InetAddress.getLocalHost();
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    66
        switch (args[0]) {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    67
            case "1":
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    68
                // no initiator host address available, should be OK
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    69
                break;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    70
            case "2":
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    71
                // correct initiator host address, still fine
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    72
                c.x().setChannelBinding(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    73
                        new ChannelBinding(initiator, acceptor, null));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    74
                s.x().setChannelBinding(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    75
                        new ChannelBinding(initiator, acceptor, null));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    76
                break;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    77
            case "3":
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    78
                // incorrect initiator host address, fail
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    79
                initiator = InetAddress.getByAddress(new byte[]{1,1,1,1});
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    80
                c.x().setChannelBinding(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    81
                        new ChannelBinding(initiator, acceptor, null));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    82
                s.x().setChannelBinding(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    83
                        new ChannelBinding(initiator, acceptor, null));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    84
                break;
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    85
        }
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    86
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    87
        Context.handshake(c, s);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    88
    }
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents:
diff changeset
    89
}