Path: blob/master/test/jdk/sun/security/krb5/auto/ForwardableCheck.java
41152 views
/*1* Copyright (c) 2014, 2018, 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 8022582 819448626* @summary Relax response flags checking in sun.security.krb5.KrbKdcRep.check.27* @library /test/lib28* @compile -XDignore.symbol.file ForwardableCheck.java29* @run main jdk.test.lib.FileInstaller TestHosts TestHosts30* @run main/othervm -Djdk.net.hosts.file=TestHosts ForwardableCheck31*/3233import org.ietf.jgss.GSSException;34import sun.security.jgss.GSSUtil;3536import java.util.Arrays;3738public class ForwardableCheck {3940public static void main(String[] args) throws Exception {41OneKDC kdc = new OneKDC(null);42kdc.writeJAASConf();4344// USER can impersonate someone else45kdc.setOption(KDC.Option.ALLOW_S4U2SELF,46Arrays.asList(OneKDC.USER + "@" + OneKDC.REALM));47// USER2 is sensitive48kdc.setOption(KDC.Option.SENSITIVE_ACCOUNTS,49Arrays.asList(OneKDC.USER2 + "@" + OneKDC.REALM));5051Context c;5253// USER2 is sensitive but it's still able to get a normal ticket54c = Context.fromUserPass(OneKDC.USER2, OneKDC.PASS2, false);5556// ... and connect to another account57c.startAsClient(OneKDC.USER, GSSUtil.GSS_KRB5_MECH_OID);58c.x().requestCredDeleg(true);59c.x().requestMutualAuth(false);6061c.take(new byte[0]);6263if (!c.x().isEstablished()) {64throw new Exception("Context should have been established");65}6667// ... but will not be able to delegate itself68if (c.x().getCredDelegState()) {69throw new Exception("Impossible");70}7172// Although USER is allowed to impersonate other people,73// it cannot impersonate USER2 coz it's sensitive.74c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);75try {76c.impersonate(OneKDC.USER2);77throw new Exception("Should fail");78} catch (GSSException e) {79e.printStackTrace();80}81}82}838485