test/jdk/sun/security/krb5/auto/MSOID2.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:
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
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.
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     4
 *
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     8
 *
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    13
 * accompanied this code).
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    14
 *
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    18
 *
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    21
 * questions.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    22
 */
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    23
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    24
/*
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 8078439 8194486
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    27
 * @summary SPNEGO auth fails if client proposes MS krb5 OID
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    28
 * @library /test/lib
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file MSOID2.java
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    30
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    31
 * @run main/othervm -Djdk.net.hosts.file=TestHosts MSOID2
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    32
 */
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    33
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    34
import sun.security.jgss.GSSUtil;
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 31474
diff changeset
    35
import sun.security.util.HexDumpEncoder;
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    36
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    37
// The basic krb5 test skeleton you can copy from
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    38
public class MSOID2 {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    39
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    41
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    42
        new OneKDC(null).writeJAASConf();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    43
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    44
        Context c, s;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    45
        c = Context.fromJAAS("client");
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    46
        s = Context.fromJAAS("server");
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    47
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    48
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    49
        s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    50
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    51
        byte[] t = new byte[0];
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    52
        boolean first = true;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    53
        while (true) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    54
            if (t != null || !c.x().isEstablished()) t = c.take(t);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    55
            if (first) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    56
                // Tweak the packet to append an extra OID
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    57
                int len = t.length;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    58
                byte[] nt = new byte[len + 11];
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    59
                System.arraycopy(t, 0, nt, 0, 0x23);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    60
                System.arraycopy(t, 0x18, nt, 0x23, 11);    // dup the OID
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    61
                System.arraycopy(t, 0x23, nt, 0x2e, len-0x23);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    62
                nt[0x1d] = (byte)0x82;  // change the 1st to MS OID
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    63
                // Length bytes to be tweaked
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    64
                for (int pos: new int[] {3, 0xf, 0x13, 0x15, 0x17}) {
30958
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    65
                    int newLen = (nt[pos]&0xff) + 11;
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    66
                    // The length byte at nt[pos] might overflow. It's
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    67
                    // unlikely for nt[pos-1] to overflow, which means the size
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    68
                    // of token is bigger than 65535.
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    69
                    if (newLen >= 256) {
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    70
                        nt[pos-1] = (byte)(nt[pos-1] + 1);
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    71
                    }
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    72
                    nt[pos] = (byte)newLen;
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    73
                }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    74
                t = nt;
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 31474
diff changeset
    75
                new HexDumpEncoder().encodeBuffer(t, System.out);
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    76
            }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    77
            if (t != null || !s.x().isEstablished()) t = s.take(t);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    78
            if (c.x().isEstablished() && s.x().isEstablished()) break;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    79
            first = false;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    80
        }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    81
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    82
        Context.transmit("i say high --", c, s);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    83
        Context.transmit("   you say low", s, c);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    84
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    85
        s.dispose();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    86
        c.dispose();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    87
    }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    88
}