1 /* 2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8001104 8194486 27 * @summary Unbound SASL service: the GSSAPI/krb5 mech 28 * @library /test/lib 29 * @compile -XDignore.symbol.file UnboundService.java 30 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts 31 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService null null 32 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService 33 * server/host.rabbit.hole null 34 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService 35 * server/host.rabbit.hole@RABBIT.HOLE null 36 * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts UnboundService 37 * backend/host.rabbit.hole null 38 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService 39 * null server@host.rabbit.hole 40 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService 41 * server/host.rabbit.hole server@host.rabbit.hole 42 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService 43 * server/host.rabbit.hole@RABBIT.HOLE server@host.rabbit.hole 44 * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts UnboundService 45 * backend/host.rabbit.hole server@host.rabbit.hole 46 */ 47 48 import java.io.File; 49 import java.io.FileOutputStream; 50 import sun.security.jgss.GSSUtil; 51 52 public class UnboundService { 53 54 /** 55 * @param args JAAS config pricipal and GSSCredential creation name 56 */ main(String[] args)57 public static void main(String[] args) throws Exception { 58 59 String principal = args[0]; 60 if (principal.equals("null")) principal = null; 61 62 String server = args[1]; 63 if (server.equals("null")) server = null; 64 65 new OneKDC(null).writeJAASConf(); 66 File f = new File(OneKDC.JAAS_CONF); 67 try (FileOutputStream fos = new FileOutputStream(f)) { 68 fos.write(( 69 "client {\n" + 70 " com.sun.security.auth.module.Krb5LoginModule required;\n};\n" + 71 "unbound {\n" + 72 " com.sun.security.auth.module.Krb5LoginModule required\n" + 73 " useKeyTab=true\n" + 74 " principal=" + 75 (principal==null? "*" :("\"" + principal + "\"")) + "\n" + 76 " doNotPrompt=true\n" + 77 " isInitiator=false\n" + 78 " storeKey=true;\n};\n" 79 ).getBytes()); 80 } 81 82 Context c, s; 83 c = Context.fromJAAS("client"); 84 s = Context.fromJAAS("unbound"); 85 86 c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID); 87 s.startAsServer(server, GSSUtil.GSS_KRB5_MECH_OID); 88 89 Context.handshake(c, s); 90 91 s.dispose(); 92 c.dispose(); 93 } 94 } 95