author | weijun |
Thu, 02 Jul 2015 16:20:43 +0800 | |
changeset 31474 | 7b79555b8073 |
parent 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
28670
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
1 |
/* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
4 |
* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
8 |
* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
14 |
* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
18 |
* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
21 |
* questions. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
22 |
*/ |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
23 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
24 |
/* |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
25 |
* @test |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
26 |
* @bug 8022582 |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
27 |
* @summary Relax response flags checking in sun.security.krb5.KrbKdcRep.check. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
28 |
* @compile -XDignore.symbol.file ForwardableCheck.java |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
29 |
* @run main/othervm ForwardableCheck |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
30 |
*/ |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
31 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
32 |
import org.ietf.jgss.GSSException; |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
33 |
import sun.security.jgss.GSSUtil; |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
34 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
35 |
import java.util.Arrays; |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
36 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
37 |
public class ForwardableCheck { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
38 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
40 |
OneKDC kdc = new OneKDC(null); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
41 |
kdc.writeJAASConf(); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
42 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
43 |
// USER can impersonate someone else |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
44 |
kdc.setOption(KDC.Option.ALLOW_S4U2SELF, |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
45 |
Arrays.asList(OneKDC.USER + "@" + OneKDC.REALM)); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
46 |
// USER2 is sensitive |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
47 |
kdc.setOption(KDC.Option.SENSITIVE_ACCOUNTS, |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
48 |
Arrays.asList(OneKDC.USER2 + "@" + OneKDC.REALM)); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
49 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
50 |
Context c; |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
51 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
52 |
// USER2 is sensitive but it's still able to get a normal ticket |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
53 |
c = Context.fromUserPass(OneKDC.USER2, OneKDC.PASS2, false); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
54 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
55 |
// ... and connect to another account |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
56 |
c.startAsClient(OneKDC.USER, GSSUtil.GSS_KRB5_MECH_OID); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
57 |
c.x().requestCredDeleg(true); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
58 |
c.x().requestMutualAuth(false); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
59 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
60 |
c.take(new byte[0]); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
61 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
62 |
if (!c.x().isEstablished()) { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
63 |
throw new Exception("Context should have been established"); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
64 |
} |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
65 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
66 |
// ... but will not be able to delegate itself |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
67 |
if (c.x().getCredDelegState()) { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
68 |
throw new Exception("Impossible"); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
69 |
} |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
70 |
|
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
71 |
// Although USER is allowed to impersonate other people, |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
72 |
// it cannot impersonate USER2 coz it's sensitive. |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
73 |
c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
74 |
try { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
75 |
c.impersonate(OneKDC.USER2); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
76 |
throw new Exception("Should fail"); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
77 |
} catch (GSSException e) { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
78 |
e.printStackTrace(); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
79 |
} |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
80 |
} |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
diff
changeset
|
81 |
} |