author | weijun |
Fri, 12 Aug 2011 11:20:45 +0800 | |
changeset 10327 | 37a3f951eb3a |
parent 7175 | 46ec4c2dbc16 |
child 11357 | 0ef20e50a018 |
permissions | -rw-r--r-- |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
1 |
/* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
4 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
8 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
14 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
18 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
21 |
* questions. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
22 |
*/ |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
23 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
24 |
/* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
25 |
* @test |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
26 |
* @bug 6952519 |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
27 |
* @run main/timeout=40/othervm TcpTimeout |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
28 |
* @summary kdc_timeout is not being honoured when using TCP |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
29 |
*/ |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
30 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
31 |
import java.io.*; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
32 |
import java.net.ServerSocket; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
33 |
import sun.security.krb5.Config; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
34 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
35 |
public class TcpTimeout { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
36 |
public static void main(String[] args) |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
37 |
throws Exception { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
38 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
39 |
System.setProperty("sun.security.krb5.debug", "true"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
40 |
final int p1 = 10000 + new java.util.Random().nextInt(10000); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
41 |
final int p2 = 20000 + new java.util.Random().nextInt(10000); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
42 |
final int p3 = 30000 + new java.util.Random().nextInt(10000); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
43 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
44 |
KDC k = new KDC(OneKDC.REALM, OneKDC.KDCHOST, p3, true); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
45 |
k.addPrincipal(OneKDC.USER, OneKDC.PASS); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
46 |
k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
47 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
48 |
// Start two listener that does not communicate, simulate timeout |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
49 |
new Thread() { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
50 |
public void run() { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
51 |
try { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
52 |
new ServerSocket(p1).accept(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
53 |
} catch (Exception e) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
54 |
}} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
55 |
}.start(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
56 |
new Thread() { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
57 |
public void run() { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
58 |
try { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
59 |
new ServerSocket(p2).accept(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
60 |
} catch (Exception e) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
61 |
}} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
62 |
}.start(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
63 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
64 |
FileWriter fw = new FileWriter("alternative-krb5.conf"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
65 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
66 |
fw.write("[libdefaults]\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
67 |
"udp_preference_limit = 1\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
68 |
"max_retries = 2\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
69 |
"default_realm = " + OneKDC.REALM + "\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
70 |
"kdc_timeout = 5000\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
71 |
fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
72 |
"kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
73 |
"kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
74 |
"kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
75 |
"}\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
76 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
77 |
fw.close(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
78 |
System.setProperty("java.security.krb5.conf", "alternative-krb5.conf"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
79 |
Config.refresh(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
80 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
81 |
// The correct behavior should be: |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
82 |
// 5 sec on p1, 5 sec on p1, fail |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
83 |
// 5 sec on p2, 5 sec on p2, fail |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
84 |
// p3 ok, p3 ok again for preauth. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
85 |
// The total time should be 20sec + 2x. x is processing time for AS-REQ. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
86 |
int count = 6; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
87 |
long start = System.nanoTime(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
88 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
89 |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
90 |
PrintStream oldout = System.out; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
91 |
System.setOut(new PrintStream(bo)); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
92 |
Context c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
93 |
System.setOut(oldout); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
94 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
95 |
String[] lines = new String(bo.toByteArray()).split("\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
96 |
for (String line: lines) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
97 |
if (line.startsWith(">>> KDCCommunication")) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
98 |
System.out.println(line); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
99 |
count--; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
100 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
101 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
102 |
if (count != 0) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
103 |
throw new Exception("Retry count is " + count + " less"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
104 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
105 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
106 |
long end = System.nanoTime(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
107 |
if ((end - start)/1000000000L < 20) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
108 |
throw new Exception("Too fast? " + (end - start)/1000000000L); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
109 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
110 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
111 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
112 |
private static KDC on(int p) throws Exception { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
113 |
KDC k = new KDC(OneKDC.REALM, OneKDC.KDCHOST, p, true); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
114 |
k.addPrincipal(OneKDC.USER, OneKDC.PASS); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
115 |
k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
116 |
return k; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
117 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
118 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
119 |
private static void addFakeKDCs() |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
120 |
throws Exception { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
121 |
BufferedReader fr = new BufferedReader(new FileReader(OneKDC.KRB5_CONF)); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
122 |
FileWriter fw = new FileWriter("alternative-krb5.conf"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
123 |
while (true) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
124 |
String s = fr.readLine(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
125 |
if (s == null) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
126 |
break; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
127 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
128 |
if (s.trim().startsWith("kdc = ")) { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
129 |
fw.write(" kdc = localhost:33333\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
130 |
fw.write(" kdc = localhost:22222\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
131 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
132 |
fw.write(s + "\n"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
133 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
134 |
fr.close(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
135 |
fw.close(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
136 |
sun.security.krb5.Config.refresh(); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
137 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
138 |
} |