author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 8396 | 587947f96036 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2279
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
1 |
/* |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
2279
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
4 |
* |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
8 |
* |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
14 |
* |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
18 |
* |
5506 | 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. |
|
2279
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
22 |
*/ |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
23 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
24 |
/* |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
25 |
* @test |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
26 |
* @bug 6815182 |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
5506
diff
changeset
|
27 |
* @run main/othervm SpnegoReqFlags |
2279
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
28 |
* @summary GSSAPI/SPNEGO does not work with server using MIT Kerberos library |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
29 |
*/ |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
30 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
31 |
import sun.security.jgss.GSSUtil; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
32 |
import sun.security.util.BitArray; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
33 |
import sun.security.util.DerInputStream; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
34 |
import sun.security.util.DerValue; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
35 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
36 |
public class SpnegoReqFlags { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
37 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
38 |
public static void main(String[] args) |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
39 |
throws Exception { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
40 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
41 |
// Create and start the KDC |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
42 |
new OneKDC(null).writeJAASConf(); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
43 |
new SpnegoReqFlags().go(); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
44 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
45 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
46 |
void go() throws Exception { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
47 |
Context c = Context.fromJAAS("client"); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
48 |
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
49 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
50 |
byte[] token = c.doAs(new Action() { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
51 |
@Override |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
52 |
public byte[] run(Context me, byte[] input) throws Exception { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
53 |
me.x().requestCredDeleg(true); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
54 |
me.x().requestReplayDet(false); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
55 |
me.x().requestSequenceDet(false); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
56 |
return me.x().initSecContext(new byte[0], 0, 0); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
57 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
58 |
}, null); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
59 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
60 |
DerValue d = new DerValue(token); // GSSToken |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
61 |
DerInputStream ins = d.data; // OID + mech token |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
62 |
d.data.getDerValue(); // skip OID |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
63 |
d = d.data.getDerValue(); // NegTokenInit |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
64 |
d = d.data.getDerValue(); // The SEQUENCE inside |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
65 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
66 |
boolean found = false; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
67 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
68 |
// Go through all fields inside NegTokenInit. The reqFlags field |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
69 |
// is optional. It's even not recommended in RFC 4178. |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
70 |
while (d.data.available() > 0) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
71 |
DerValue d2 = d.data.getDerValue(); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
72 |
if (d2.isContextSpecific((byte)1)) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
73 |
found = true; |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
74 |
System.out.println("regFlags field located."); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
75 |
BitArray ba = d2.data.getUnalignedBitString(); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
76 |
if (ba.length() != 7) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
77 |
throw new Exception("reqFlags should contain 7 bits"); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
78 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
79 |
if (!ba.get(0)) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
80 |
throw new Exception("delegFlag should be true"); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
81 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
82 |
if (ba.get(2) || ba.get(3)) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
83 |
throw new Exception("replay/sequenceFlag should be false"); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
84 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
85 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
86 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
87 |
|
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
88 |
if (!found) { |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
89 |
System.out.println("Warning: regFlags field not found, too new?"); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
90 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
91 |
c.dispose(); |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
92 |
} |
e5639c0d8552
6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents:
diff
changeset
|
93 |
} |