Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/BasicKrb5Test.java
38853 views
/*1* Copyright (c) 2008, 2013, 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 670697426* @summary Add krb5 test infrastructure27* @compile -XDignore.symbol.file BasicKrb5Test.java28* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test29* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-crc30* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-md531* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des3-cbc-sha132* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes128-cts33* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes256-cts34* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test rc4-hmac35* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test -s36* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-crc -s37* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-md5 -s38* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des3-cbc-sha1 -s39* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes128-cts -s40* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes256-cts -s41* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test rc4-hmac -s42* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test -C43* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-crc -C44* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-md5 -C45* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des3-cbc-sha1 -C46* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes128-cts -C47* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes256-cts -C48* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test rc4-hmac -C49* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test -s -C50* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-crc -s -C51* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des-cbc-md5 -s -C52* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test des3-cbc-sha1 -s -C53* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes128-cts -s -C54* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test aes256-cts -s -C55* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock BasicKrb5Test rc4-hmac -s -C56*/5758import org.ietf.jgss.GSSName;59import sun.security.jgss.GSSUtil;60import sun.security.krb5.Config;61import sun.security.krb5.KrbException;62import sun.security.krb5.internal.crypto.EType;6364/**65* Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each66* party uses JAAS login to get subjects and executes JGSS calls using67* Subject.doAs.68*/69public class BasicKrb5Test {7071private static boolean conf = true;72/**73* @param args empty or etype74*/75public static void main(String[] args)76throws Exception {7778String etype = null;79for (String arg: args) {80if (arg.equals("-s")) Context.usingStream = true;81else if (arg.equals("-C")) conf = false;82else etype = arg;83}8485// Creates and starts the KDC. This line must be put ahead of etype check86// since the check needs a krb5.conf.87try {88new OneKDC(etype).writeJAASConf();89} catch (KrbException ke) {90System.out.println("Testing etype " + etype + "Not supported.");91return;92}9394new BasicKrb5Test().go(OneKDC.SERVER, OneKDC.BACKEND);95}9697void go(final String server, final String backend) throws Exception {98Context c, s, s2, b;99c = Context.fromJAAS("client");100s = Context.fromJAAS("server");101b = Context.fromJAAS("backend");102103c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);104c.x().requestCredDeleg(true);105c.x().requestConf(conf);106s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);107108c.status();109s.status();110111Context.handshake(c, s);112GSSName client = c.x().getSrcName();113114c.status();115s.status();116117Context.transmit("i say high --", c, s);118Context.transmit(" you say low", s, c);119120s2 = s.delegated();121s.dispose();122s = null;123124s2.startAsClient(backend, GSSUtil.GSS_KRB5_MECH_OID);125s2.x().requestConf(conf);126b.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);127128s2.status();129b.status();130131Context.handshake(s2, b);132GSSName client2 = b.x().getSrcName();133134if (!client.equals(client2)) {135throw new Exception("Delegation failed");136}137138s2.status();139b.status();140141Context.transmit("you say hello --", s2, b);142Context.transmit(" i say goodbye", b, s2);143144s2.dispose();145b.dispose();146}147}148149150