test/jdk/sun/security/krb5/auto/IgnoreChannelBinding.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:
3050
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3050
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     4
 *
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     8
 *
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    13
 * accompanied this code).
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    14
 *
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3050
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3050
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3050
diff changeset
    21
 * questions.
3050
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    22
 */
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    23
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    24
/*
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 6851973 8194486
3050
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    27
 * @summary ignore incoming channel binding if acceptor does not set one
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    28
 * @library /test/lib
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    29
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    30
 * @run main/othervm -Djdk.net.hosts.file=TestHosts IgnoreChannelBinding
3050
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    31
 */
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    32
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    33
import java.net.InetAddress;
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    34
import org.ietf.jgss.ChannelBinding;
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    35
import org.ietf.jgss.GSSException;
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    36
import sun.security.jgss.GSSUtil;
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    37
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    38
public class IgnoreChannelBinding {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    39
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    40
    public static void main(String[] args)
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    41
            throws Exception {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    42
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    43
        new OneKDC(null).writeJAASConf();
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    44
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    45
        Context c = Context.fromJAAS("client");
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    46
        Context s = Context.fromJAAS("server");
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    47
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    48
        // All silent
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    49
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    50
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    51
        Context.handshake(c, s);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    52
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    53
        // Initiator req, acceptor ignore
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    54
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    55
        c.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    56
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    57
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    58
                new byte[0]
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    59
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    60
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    61
        Context.handshake(c, s);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    62
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    63
        // Both req, and match
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    64
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    65
        c.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    66
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    67
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    68
                new byte[0]
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    69
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    70
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    71
        s.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    72
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    73
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    74
                new byte[0]
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    75
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    76
        Context.handshake(c, s);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    77
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    78
        // Both req, NOT match
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    79
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    80
        c.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    81
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    82
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    83
                new byte[0]
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    84
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    85
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    86
        s.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    87
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    88
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    89
                new byte[1]     // 0 -> 1
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    90
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    91
        try {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    92
            Context.handshake(c, s);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    93
            throw new Exception("Acceptor should reject initiator");
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    94
        } catch (GSSException ge) {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    95
            // Expected bahavior
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    96
        }
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    97
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    98
        // Acceptor req, reject
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
    99
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   100
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   101
        s.x().setChannelBinding(new ChannelBinding(
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   102
                InetAddress.getByName("client.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   103
                InetAddress.getByName("host.rabbit.hole"),
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   104
                new byte[0]
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   105
                ));
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   106
        try {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   107
            Context.handshake(c, s);
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   108
            throw new Exception("Acceptor should reject initiator");
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   109
        } catch (GSSException ge) {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   110
            // Expected bahavior
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   111
            if (ge.getMajor() != GSSException.BAD_BINDINGS) {
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   112
                throw ge;
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   113
            }
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   114
        }
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   115
    }
c0ce59daa004 6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
diff changeset
   116
}