Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/MoreKvno.java
38854 views
/*1* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6893158 6907425 719715926* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock MoreKvno27* @summary AP_REQ check should use key version number28*/2930import org.ietf.jgss.GSSException;31import sun.security.jgss.GSSUtil;32import sun.security.krb5.KrbException;33import sun.security.krb5.PrincipalName;34import sun.security.krb5.internal.ktab.KeyTab;35import sun.security.krb5.internal.Krb5;3637public class MoreKvno {3839static PrincipalName p;40public static void main(String[] args)41throws Exception {4243OneKDC kdc = new OneKDC(null);44kdc.writeJAASConf();4546// Rewrite keytab, 3 set of keys with different kvno47KeyTab ktab = KeyTab.create(OneKDC.KTAB);48p = new PrincipalName(49OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST);50ktab.addEntry(p, "pass1".toCharArray(), 1, true);51ktab.addEntry(p, "pass3".toCharArray(), 3, true);52ktab.addEntry(p, "pass2".toCharArray(), 2, true);53ktab.save();5455char[] pass = "pass2".toCharArray();56kdc.addPrincipal(OneKDC.SERVER, pass);57go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);5859pass = "pass3".toCharArray();60kdc.addPrincipal(OneKDC.SERVER, pass);61// "server" initiate also, check pass2 is used at authentication62go(OneKDC.SERVER, "server", pass);6364try {65pass = "pass4".toCharArray();66kdc.addPrincipal(OneKDC.SERVER, pass);67go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass);68throw new Exception("This test should fail");69} catch (GSSException gsse) {70// Since 7197159, different kvno is accepted, this return code71// will never be thrown out again.72//KrbException ke = (KrbException)gsse.getCause();73//if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) {74// throw new Exception("Not expected failure code: " +75// ke.returnCode());76//}77}78}7980static void go(String server, String entry, char[] pass) throws Exception {81Context c, s;8283// Part 1: Test keytab84c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);85s = Context.fromJAAS(entry);8687c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);88s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);8990Context.handshake(c, s);9192s.dispose();93c.dispose();9495// Part 2: Test username/password pair96c = Context.fromUserPass("dummy", "bogus".toCharArray(), false);97s = Context.fromUserPass(p.getNameString(), pass, true);9899c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);100s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);101102Context.handshake(c, s);103104s.dispose();105c.dispose();106}107}108109110