jdk/test/sun/security/krb5/auto/MoreKvno.java
author msheppar
Thu, 21 Feb 2013 20:01:22 +0000
changeset 16020 b57c48f16179
parent 14895 5ad2d7032375
child 23010 6dadb192ad81
permissions -rw-r--r--
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests Summary: Refactored code to use java.util.Base64 Mime Encoder and Decoder as a replacement for sun.misc.BASE64Encoder and sun.misc.BASE64Decoder Reviewed-by: vinnie, chegar, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     1
/*
8396
587947f96036 7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents: 7172
diff changeset
     2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     4
 *
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     8
 *
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    13
 * accompanied this code).
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    14
 *
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    21
 * questions.
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    22
 */
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    23
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    24
/*
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    25
 * @test
14895
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    26
 * @bug 6893158 6907425 7197159
8396
587947f96036 7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents: 7172
diff changeset
    27
 * @run main/othervm MoreKvno
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    28
 * @summary AP_REQ check should use key version number
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    29
 */
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    30
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    31
import org.ietf.jgss.GSSException;
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    32
import sun.security.jgss.GSSUtil;
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    33
import sun.security.krb5.KrbException;
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    34
import sun.security.krb5.PrincipalName;
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    35
import sun.security.krb5.internal.ktab.KeyTab;
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    36
import sun.security.krb5.internal.Krb5;
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    37
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    38
public class MoreKvno {
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    39
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    40
    static PrincipalName p;
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    41
    public static void main(String[] args)
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    42
            throws Exception {
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    43
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    44
        OneKDC kdc = new OneKDC(null);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    45
        kdc.writeJAASConf();
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    46
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    47
        // Rewrite keytab, 3 set of keys with different kvno
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    48
        KeyTab ktab = KeyTab.create(OneKDC.KTAB);
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    49
        p = new PrincipalName(
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    50
            OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST);
7172
01308fd663b3 6997740: ktab entry related test compilation error
weijun
parents: 5506
diff changeset
    51
        ktab.addEntry(p, "pass1".toCharArray(), 1, true);
01308fd663b3 6997740: ktab entry related test compilation error
weijun
parents: 5506
diff changeset
    52
        ktab.addEntry(p, "pass3".toCharArray(), 3, true);
01308fd663b3 6997740: ktab entry related test compilation error
weijun
parents: 5506
diff changeset
    53
        ktab.addEntry(p, "pass2".toCharArray(), 2, true);
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    54
        ktab.save();
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    55
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    56
        char[] pass = "pass2".toCharArray();
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    57
        kdc.addPrincipal(OneKDC.SERVER, pass);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    58
        go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    59
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    60
        pass = "pass3".toCharArray();
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    61
        kdc.addPrincipal(OneKDC.SERVER, pass);
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    62
        // "server" initiate also, check pass2 is used at authentication
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    63
        go(OneKDC.SERVER, "server", pass);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    64
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    65
        try {
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    66
            pass = "pass4".toCharArray();
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    67
            kdc.addPrincipal(OneKDC.SERVER, pass);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    68
            go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    69
            throw new Exception("This test should fail");
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    70
        } catch (GSSException gsse) {
14895
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    71
            // Since 7197159, different kvno is accepted, this return code
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    72
            // will never be thrown out again.
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    73
            //KrbException ke = (KrbException)gsse.getCause();
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    74
            //if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) {
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    75
            //    throw new Exception("Not expected failure code: " +
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    76
            //            ke.returnCode());
5ad2d7032375 7197159: accept different kvno if there no match
weijun
parents: 8396
diff changeset
    77
            //}
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    78
        }
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    79
    }
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    80
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    81
    static void go(String server, String entry, char[] pass) throws Exception {
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    82
        Context c, s;
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    83
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    84
        // Part 1: Test keytab
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    85
        c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    86
        s = Context.fromJAAS(entry);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    87
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    88
        c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    89
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    90
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    91
        Context.handshake(c, s);
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    92
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    93
        s.dispose();
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
    94
        c.dispose();
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    95
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    96
        // Part 2: Test username/password pair
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    97
        c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    98
        s = Context.fromUserPass(p.getNameString(), pass, true);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
    99
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   100
        c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   101
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   102
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   103
        Context.handshake(c, s);
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   104
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   105
        s.dispose();
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4168
diff changeset
   106
        c.dispose();
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
   107
    }
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents:
diff changeset
   108
}