jdk/test/sun/security/krb5/auto/DiffNameSameKey.java
author weijun
Thu, 02 Jul 2015 16:20:43 +0800
changeset 31474 7b79555b8073
parent 30820 0d4717a011d3
permissions -rw-r--r--
8130112: Create a common TEST.properties for @modules in test/sun/security/krb5/auto Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 15006
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     4
 *
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     8
 *
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    13
 * accompanied this code).
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    14
 *
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    18
 *
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    21
 * questions.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    22
 */
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    23
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    24
/*
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    25
 * @test
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    26
 * @bug 8005447
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    27
 * @summary default principal can act as anyone
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file DiffNameSameKey.java
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    29
 * @run main/othervm/fail DiffNameSameKey a
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    30
 * @run main/othervm DiffNameSameKey b
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    31
 */
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    32
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    33
import sun.security.jgss.GSSUtil;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    34
import sun.security.krb5.PrincipalName;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    35
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    36
/**
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    37
 * This test confirms the compatibility codes described in
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    38
 * ServiceCreds.getEKeys(). If the acceptor starts as x.us.oracle.com
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    39
 * but client requests for x.us, as long as the KDC supports both names
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    40
 * and the keys are the same, the auth should succeed.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    41
 */
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    42
public class DiffNameSameKey {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    43
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    44
    static final String SERVER2 = "x" + OneKDC.SERVER;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    45
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    47
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    48
        OneKDC kdc = new KDC2();
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    49
        kdc.addPrincipal(SERVER2, "samepass".toCharArray());
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    50
        kdc.addPrincipal(OneKDC.SERVER, "samepass".toCharArray());
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    51
        kdc.writeJAASConf();
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    52
        kdc.writeKtab(OneKDC.KTAB);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    53
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    54
        Context c, s;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    55
        c = Context.fromJAAS("client");
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    56
        s = Context.fromJAAS("server");
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    57
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    58
        switch (args[0]) {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    59
            case "a":   // If server starts as another service, should fail
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    60
                c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    61
                s.startAsServer(SERVER2.replace('/', '@'),
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    62
                        GSSUtil.GSS_SPNEGO_MECH_OID);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    63
                break;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    64
            case "b":   // If client requests another server with the same keys,
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    65
                        // succeed to be compatible
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    66
                c.startAsClient(SERVER2, GSSUtil.GSS_SPNEGO_MECH_OID);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    67
                s.startAsServer(OneKDC.SERVER.replace('/', '@'),
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    68
                        GSSUtil.GSS_SPNEGO_MECH_OID);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    69
                break;
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    70
        }
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    71
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    72
        Context.handshake(c, s);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    73
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    74
        s.dispose();
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    75
        c.dispose();
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    76
    }
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    77
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    78
    /**
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    79
     * This KDC returns the same salt for all principals. This means same
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    80
     * passwords generate same keys.
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    81
     */
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    82
    static class KDC2 extends OneKDC {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    83
        KDC2() throws Exception {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    84
            super(null);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    85
        }
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    86
        @Override
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    87
        public String getSalt(PrincipalName pn) {
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    88
            return "SAME";
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    89
        }
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    90
    }
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents:
diff changeset
    91
}