jdk/test/sun/security/jgss/spnego/MSOID.java
author weijun
Tue, 05 May 2015 21:14:12 +0800
changeset 30324 6f3109ded2b8
permissions -rw-r--r--
8078439: SPNEGO auth fails if client proposes MS krb5 OID 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
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    28
 */
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    29
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    30
import org.ietf.jgss.GSSContext;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    31
import org.ietf.jgss.GSSCredential;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    32
import org.ietf.jgss.GSSException;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    33
import org.ietf.jgss.GSSManager;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    34
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    35
import java.lang.Exception;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    36
import java.nio.file.Files;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    37
import java.nio.file.Paths;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    38
import java.util.Arrays;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    39
import java.util.Base64;
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
public class MSOID {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
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
        // msoid.txt is a NegTokenInit packet sent from Internet Explorer to
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    45
        // IIS server on a test machine. No sensitive info included.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    46
        byte[] header = Files.readAllBytes(
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    47
                Paths.get(System.getProperty("test.src"), "msoid.txt"));
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    48
        byte[] token = Base64.getMimeDecoder().decode(
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    49
                Arrays.copyOfRange(header, 10, header.length));
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
        GSSCredential cred = null;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    52
        GSSContext ctx = GSSManager.getInstance().createContext(cred);
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
        try {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    55
            ctx.acceptSecContext(token, 0, token.length);
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    56
            // Before the fix, GSS_KRB5_MECH_OID_MS is not recognized
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    57
            // and acceptor chooses another mech and goes on
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    58
            throw new Exception("Should fail");
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    59
        } catch (GSSException gsse) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    60
            // After the fix, GSS_KRB5_MECH_OID_MS is recognized but the token
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    61
            // cannot be accepted because we don't have any krb5 credential.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    62
            gsse.printStackTrace();
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    63
            if (gsse.getMajor() != GSSException.NO_CRED) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    64
                throw gsse;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    65
            }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    66
            for (StackTraceElement st: gsse.getStackTrace()) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    67
                if (st.getClassName().startsWith("sun.security.jgss.krb5.")) {
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    68
                    // Good, it is already in krb5 mech's hand.
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    69
                    return;
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    70
                }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    71
            }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    72
            throw gsse;
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
    }
6f3109ded2b8 8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff changeset
    75
}