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 6355584 8044215 8194486
27  * @summary Introduce constrained Kerberos delegation
28  * @library /test/lib
29  * @compile -XDignore.symbol.file S4U2proxy.java
30  * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
31  * @run main/othervm -Djdk.net.hosts.file=TestHosts S4U2proxy krb5
32  * @run main/othervm -Djdk.net.hosts.file=TestHosts S4U2proxy spnego
33  */
34 
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import org.ietf.jgss.Oid;
40 import sun.security.jgss.GSSUtil;
41 
42 public class S4U2proxy {
43 
main(String[] args)44     public static void main(String[] args) throws Exception {
45         Oid mech;
46         if (args[0].equals("spnego")) {
47             mech = GSSUtil.GSS_SPNEGO_MECH_OID;
48         } else if (args[0].contains("krb5")) {
49             mech = GSSUtil.GSS_KRB5_MECH_OID;
50         } else {
51             throw new Exception("Unknown mech");
52         }
53 
54         OneKDC kdc = new OneKDC(null);
55         kdc.writeJAASConf();
56         kdc.setOption(KDC.Option.PREAUTH_REQUIRED, false);
57         Map<String,List<String>> map = new HashMap<>();
58         map.put(OneKDC.SERVER + "@" + OneKDC.REALM, Arrays.asList(
59                 new String[]{OneKDC.BACKEND + "@" + OneKDC.REALM}));
60         kdc.setOption(KDC.Option.ALLOW_S4U2PROXY, map);
61 
62         Context c, s, b;
63         c = Context.fromJAAS("client");
64         s = Context.fromJAAS("server");
65         b = Context.fromJAAS("backend");
66 
67         c.startAsClient(OneKDC.SERVER, mech);
68         s.startAsServer(null, mech, false);
69 
70         Context.handshake(c, s);
71         Context p = s.delegated();
72 
73         p.startAsClient(OneKDC.BACKEND, mech);
74 
75         // 8044215: requestCredDeleg is useless and harmless
76         p.x().requestCredDeleg(true);
77 
78         b.startAsServer(mech);
79         Context.handshake(p, b);
80 
81         p.startAsClient(OneKDC.BACKEND, mech);
82         b.startAsServer(mech);
83         Context.handshake(p, b);
84     }
85 }
86