2461N/A/*
2461N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2461N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2461N/A *
2461N/A * This code is free software; you can redistribute it and/or modify it
2461N/A * under the terms of the GNU General Public License version 2 only, as
2461N/A * published by the Free Software Foundation.
2461N/A *
2461N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2461N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2461N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2461N/A * version 2 for more details (a copy is included in the LICENSE file that
2461N/A * accompanied this code).
2461N/A *
2461N/A * You should have received a copy of the GNU General Public License version
2461N/A * 2 along with this work; if not, write to the Free Software Foundation,
2461N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2461N/A *
2461N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2461N/A * or visit www.oracle.com if you need additional information or have any
2461N/A * questions.
2461N/A */
2461N/A
2461N/A/*
2461N/A * @test
2489N/A * @bug 6932525 6951366 6959292
2461N/A * @summary kerberos login failure on win2008 with AD set to win2000 compat mode
2489N/A * and cannot login if session key and preauth does not use the same etype
3054N/A * @run main/othervm -D6932525 W83
3054N/A * @run main/othervm -D6959292 W83
2461N/A */
2461N/Aimport com.sun.security.auth.module.Krb5LoginModule;
2461N/Aimport java.io.File;
2461N/Aimport sun.security.krb5.Config;
2461N/Aimport sun.security.krb5.EncryptedData;
2461N/Aimport sun.security.krb5.PrincipalName;
2461N/Aimport sun.security.krb5.internal.crypto.EType;
2461N/Aimport sun.security.krb5.internal.ktab.KeyTab;
2461N/A
2461N/Apublic class W83 {
2461N/A public static void main(String[] args) throws Exception {
2461N/A
2461N/A W83 x = new W83();
2461N/A
2461N/A // Cannot use OneKDC. kinit command cannot resolve
2461N/A // hostname kdc.rabbit.hole
2461N/A KDC kdc = new KDC(OneKDC.REALM, "127.0.0.1", 0, true);
2461N/A kdc.addPrincipal(OneKDC.USER, OneKDC.PASS);
2461N/A kdc.addPrincipalRandKey("krbtgt/" + OneKDC.REALM);
2461N/A KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
2461N/A System.setProperty("java.security.krb5.conf", OneKDC.KRB5_CONF);
2461N/A Config.refresh();
2461N/A
2461N/A kdc.writeKtab(OneKDC.KTAB);
2461N/A new File(OneKDC.KRB5_CONF).deleteOnExit();
2461N/A new File(OneKDC.KTAB).deleteOnExit();
2461N/A
2461N/A KeyTab ktab = KeyTab.getInstance(OneKDC.KTAB);
2461N/A for (int etype: EType.getBuiltInDefaults()) {
2461N/A if (etype != EncryptedData.ETYPE_ARCFOUR_HMAC) {
3043N/A ktab.deleteEntries(new PrincipalName(OneKDC.USER), etype, -1);
2461N/A }
2461N/A }
2461N/A ktab.save();
2489N/A
3054N/A if (System.getProperty("6932525") != null) {
3054N/A // For 6932525 and 6951366, make sure the etypes sent in 2nd AS-REQ
3054N/A // is not restricted to that of preauth
3054N/A kdc.setOption(KDC.Option.ONLY_RC4_TGT, true);
3054N/A }
3054N/A if (System.getProperty("6959292") != null) {
3054N/A // For 6959292, make sure that when etype for enc-part in 2nd AS-REQ
3054N/A // is different from that of preauth, client can still decrypt it
3054N/A kdc.setOption(KDC.Option.RC4_FIRST_PREAUTH, true);
3054N/A }
2461N/A x.go();
2461N/A }
2461N/A
2461N/A void go() throws Exception {
2461N/A Krb5LoginModule krb5 = new Krb5LoginModule();
2461N/A StringBuffer error = new StringBuffer();
2461N/A try {
2461N/A Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
2461N/A } catch (Exception e) {
3054N/A e.printStackTrace();
2461N/A error.append("Krb5LoginModule password login error\n");
2461N/A }
2461N/A try {
2461N/A Context.fromUserKtab(OneKDC.USER, OneKDC.KTAB, false);
2461N/A } catch (Exception e) {
3054N/A e.printStackTrace();
2461N/A error.append("Krb5LoginModule keytab login error\n");
2461N/A }
2461N/A try {
2461N/A Class.forName("sun.security.krb5.internal.tools.Kinit");
2461N/A String cmd = System.getProperty("java.home") +
2461N/A System.getProperty("file.separator") +
2461N/A "bin" +
2461N/A System.getProperty("file.separator") +
2461N/A "kinit";
2461N/A
2461N/A int p = execute(
2461N/A cmd,
2461N/A "-J-Djava.security.krb5.conf=" + OneKDC.KRB5_CONF,
2461N/A "-c", "cache1",
2461N/A OneKDC.USER,
2461N/A new String(OneKDC.PASS));
2461N/A if (p != 0) {
2461N/A error.append("kinit password login error\n");
2461N/A }
2461N/A p = execute(
2461N/A cmd,
2461N/A "-J-Djava.security.krb5.conf=" + OneKDC.KRB5_CONF,
2461N/A "-c", "cache2",
2461N/A "-k", "-t", OneKDC.KTAB,
2461N/A OneKDC.USER);
2461N/A if (p != 0) {
2461N/A error.append("kinit keytab login error\n");
2461N/A }
2461N/A } catch (ClassNotFoundException cnfe) {
2461N/A System.out.println("No kinit, test ignored.");
2461N/A // Ignore, not on windows
2461N/A }
2461N/A if (error.length() != 0) {
2461N/A throw new Exception(error.toString());
2461N/A }
2461N/A }
2461N/A
2461N/A private static int execute(String... args) throws Exception {
2461N/A for (String arg: args) {
2461N/A System.out.printf("%s ", arg);
2461N/A }
2461N/A System.out.println();
2461N/A Process p = Runtime.getRuntime().exec(args);
2461N/A return p.waitFor();
2461N/A }
2461N/A}