author | ssahoo |
Fri, 26 Aug 2016 01:20:30 -0700 | |
changeset 40557 | 7aff3e34365e |
parent 34687 | d302ed125dc9 |
permissions | -rw-r--r-- |
30324
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
1 |
/* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
4 |
* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
8 |
* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
14 |
* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
18 |
* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
21 |
* questions. |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
22 |
*/ |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
23 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
24 |
/* |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
25 |
* @test |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
26 |
* @bug 8078439 |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
27 |
* @summary SPNEGO auth fails if client proposes MS krb5 OID |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
28 |
* @compile -XDignore.symbol.file MSOID2.java |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
29 |
* @run main/othervm MSOID2 |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
30 |
*/ |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
31 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
32 |
import sun.security.jgss.GSSUtil; |
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
31474
diff
changeset
|
33 |
import sun.security.util.HexDumpEncoder; |
30324
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
34 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
35 |
// The basic krb5 test skeleton you can copy from |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
36 |
public class MSOID2 { |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
37 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
39 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
40 |
new OneKDC(null).writeJAASConf(); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
41 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
42 |
Context c, s; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
43 |
c = Context.fromJAAS("client"); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
44 |
s = Context.fromJAAS("server"); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
45 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
46 |
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
47 |
s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
48 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
49 |
byte[] t = new byte[0]; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
50 |
boolean first = true; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
51 |
while (true) { |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
52 |
if (t != null || !c.x().isEstablished()) t = c.take(t); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
53 |
if (first) { |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
54 |
// Tweak the packet to append an extra OID |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
55 |
int len = t.length; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
56 |
byte[] nt = new byte[len + 11]; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
57 |
System.arraycopy(t, 0, nt, 0, 0x23); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
58 |
System.arraycopy(t, 0x18, nt, 0x23, 11); // dup the OID |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
59 |
System.arraycopy(t, 0x23, nt, 0x2e, len-0x23); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
60 |
nt[0x1d] = (byte)0x82; // change the 1st to MS OID |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
61 |
// Length bytes to be tweaked |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
62 |
for (int pos: new int[] {3, 0xf, 0x13, 0x15, 0x17}) { |
30958 | 63 |
int newLen = (nt[pos]&0xff) + 11; |
64 |
// The length byte at nt[pos] might overflow. It's |
|
65 |
// unlikely for nt[pos-1] to overflow, which means the size |
|
66 |
// of token is bigger than 65535. |
|
67 |
if (newLen >= 256) { |
|
68 |
nt[pos-1] = (byte)(nt[pos-1] + 1); |
|
69 |
} |
|
70 |
nt[pos] = (byte)newLen; |
|
30324
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
71 |
} |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
72 |
t = nt; |
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
31474
diff
changeset
|
73 |
new HexDumpEncoder().encodeBuffer(t, System.out); |
30324
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
74 |
} |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
75 |
if (t != null || !s.x().isEstablished()) t = s.take(t); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
76 |
if (c.x().isEstablished() && s.x().isEstablished()) break; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
77 |
first = false; |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
78 |
} |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
79 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
80 |
Context.transmit("i say high --", c, s); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
81 |
Context.transmit(" you say low", s, c); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
82 |
|
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
83 |
s.dispose(); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
84 |
c.dispose(); |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
85 |
} |
6f3109ded2b8
8078439: SPNEGO auth fails if client proposes MS krb5 OID
weijun
parents:
diff
changeset
|
86 |
} |