4632N/A/*
4632N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/A/*
4632N/A * @test
4632N/A * @bug 6893158
4632N/A * @bug 6907425
4632N/A * @run main/othervm MoreKvno
4632N/A * @summary AP_REQ check should use key version number
4632N/A */
4632N/A
4632N/Aimport org.ietf.jgss.GSSException;
4632N/Aimport sun.security.jgss.GSSUtil;
4632N/Aimport sun.security.krb5.KrbException;
4632N/Aimport sun.security.krb5.PrincipalName;
4632N/Aimport sun.security.krb5.internal.ktab.KeyTab;
4632N/Aimport sun.security.krb5.internal.Krb5;
4632N/A
4632N/Apublic class MoreKvno {
4632N/A
4632N/A static PrincipalName p;
4632N/A public static void main(String[] args)
4632N/A throws Exception {
4632N/A
4632N/A OneKDC kdc = new OneKDC(null);
4632N/A kdc.writeJAASConf();
4632N/A
4632N/A // Rewrite keytab, 3 set of keys with different kvno
4632N/A KeyTab ktab = KeyTab.create(OneKDC.KTAB);
4632N/A p = new PrincipalName(
4632N/A OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST);
4632N/A ktab.addEntry(p, "pass1".toCharArray(), 1, true);
4632N/A ktab.addEntry(p, "pass3".toCharArray(), 3, true);
4632N/A ktab.addEntry(p, "pass2".toCharArray(), 2, true);
4632N/A ktab.save();
4632N/A
4632N/A char[] pass = "pass2".toCharArray();
4632N/A kdc.addPrincipal(OneKDC.SERVER, pass);
4632N/A go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);
4632N/A
4632N/A pass = "pass3".toCharArray();
4632N/A kdc.addPrincipal(OneKDC.SERVER, pass);
4632N/A // "server" initiate also, check pass2 is used at authentication
4632N/A go(OneKDC.SERVER, "server", pass);
4632N/A
4632N/A try {
4632N/A pass = "pass4".toCharArray();
4632N/A kdc.addPrincipal(OneKDC.SERVER, pass);
4632N/A go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);
4632N/A throw new Exception("This test should fail");
4632N/A } catch (GSSException gsse) {
4632N/A KrbException ke = (KrbException)gsse.getCause();
4632N/A if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) {
4632N/A throw new Exception("Not expected failure code: " +
4632N/A ke.returnCode());
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A static void go(String server, String entry, char[] pass) throws Exception {
4632N/A Context c, s;
4632N/A
4632N/A // Part 1: Test keytab
4632N/A c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);
4632N/A s = Context.fromJAAS(entry);
4632N/A
4632N/A c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
4632N/A s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
4632N/A
4632N/A Context.handshake(c, s);
s.dispose();
c.dispose();
// Part 2: Test username/password pair
c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);
s = Context.fromUserPass(p.getNameString(), pass, true);
c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
Context.handshake(c, s);
s.dispose();
c.dispose();
}
}