jdk/test/sun/security/krb5/auto/MSOID2.java
author weijun
Thu, 04 Jun 2015 15:29:23 +0800
changeset 30958 30ab8e4e8a17
parent 30820 0d4717a011d3
child 31474 7b79555b8073
permissions -rw-r--r--
8079821: MSOID2.java test is not perfect Reviewed-by: valeriep
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
/*
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    26
 * @bug 8078439
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
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    28
 * @modules java.base/sun.misc
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    29
 *          java.base/sun.net.spi.nameservice
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    30
 *          java.base/sun.security.util
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    31
 *          java.security.jgss/sun.security.jgss
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    32
 *          java.security.jgss/sun.security.krb5
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    33
 *          java.security.jgss/sun.security.krb5.internal
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    34
 *          java.security.jgss/sun.security.krb5.internal.ccache
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    35
 *          java.security.jgss/sun.security.krb5.internal.crypto
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 30324
diff changeset
    36
 *          java.security.jgss/sun.security.krb5.internal.ktab
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    37
 * @compile -XDignore.symbol.file MSOID2.java
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    38
 * @run main/othervm 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
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    41
import sun.security.jgss.GSSUtil;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    42
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    43
// The basic krb5 test skeleton you can copy from
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    44
public class MSOID2 {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    45
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
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
        new OneKDC(null).writeJAASConf();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    49
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    50
        Context c, s;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    51
        c = Context.fromJAAS("client");
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    52
        s = Context.fromJAAS("server");
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    53
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    54
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    55
        s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    56
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    57
        byte[] t = new byte[0];
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    58
        boolean first = true;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    59
        while (true) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    60
            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
    61
            if (first) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    62
                // Tweak the packet to append an extra OID
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    63
                int len = t.length;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    64
                byte[] nt = new byte[len + 11];
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    65
                System.arraycopy(t, 0, nt, 0, 0x23);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    66
                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
    67
                System.arraycopy(t, 0x23, nt, 0x2e, len-0x23);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    68
                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
    69
                // Length bytes to be tweaked
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    70
                for (int pos: new int[] {3, 0xf, 0x13, 0x15, 0x17}) {
30958
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    71
                    int newLen = (nt[pos]&0xff) + 11;
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    72
                    // The length byte at nt[pos] might overflow. It's
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    73
                    // unlikely for nt[pos-1] to overflow, which means the size
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    74
                    // of token is bigger than 65535.
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    75
                    if (newLen >= 256) {
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    76
                        nt[pos-1] = (byte)(nt[pos-1] + 1);
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    77
                    }
30ab8e4e8a17 8079821: MSOID2.java test is not perfect
weijun
parents: 30820
diff changeset
    78
                    nt[pos] = (byte)newLen;
30324
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    79
                }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    80
                t = nt;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    81
                new sun.misc.HexDumpEncoder().encodeBuffer(t, System.out);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    82
            }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    83
            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
    84
            if (c.x().isEstablished() && s.x().isEstablished()) break;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    85
            first = false;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    86
        }
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
        Context.transmit("i say high --", c, s);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    89
        Context.transmit("   you say low", s, c);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    90
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    91
        s.dispose();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    92
        c.dispose();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    93
    }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    94
}