author | weijun |
Mon, 13 Jul 2015 17:44:34 +0800 | |
changeset 31643 | abad00f2c027 |
child 36967 | d041d2e80712 |
permissions | -rw-r--r-- |
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
1 |
/* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
4 |
* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
8 |
* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
14 |
* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
18 |
* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
21 |
* questions. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
22 |
*/ |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
23 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
24 |
/* |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
25 |
* @test |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
26 |
* @bug 8058290 |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
27 |
* @summary JAAS Krb5LoginModule has suspect ticket-renewal logic, |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
28 |
* relies on clockskew grace |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
29 |
* @modules java.base/sun.net.spi.nameservice |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
30 |
* java.base/sun.security.util |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
31 |
* java.security.jgss/sun.security.krb5 |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
32 |
* java.security.jgss/sun.security.krb5.internal |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
33 |
* java.security.jgss/sun.security.krb5.internal.ccache |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
34 |
* java.security.jgss/sun.security.krb5.internal.crypto |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
35 |
* java.security.jgss/sun.security.krb5.internal.ktab |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
36 |
* @compile -XDignore.symbol.file Renew.java |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
37 |
* @run main/othervm Renew 1 |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
38 |
* @run main/othervm Renew 2 |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
39 |
* @run main/othervm Renew 3 |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
40 |
*/ |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
41 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
42 |
import sun.security.krb5.Config; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
43 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
44 |
import java.nio.file.Files; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
45 |
import java.nio.file.Paths; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
46 |
import java.util.Arrays; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
47 |
import java.util.Date; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
48 |
import javax.security.auth.kerberos.KerberosTicket; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
49 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
50 |
public class Renew { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
51 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
52 |
public static void main(String[] args) throws Exception { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
53 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
54 |
// Three test cases: |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
55 |
// 1. renewTGT=false |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
56 |
// 2. renewTGT=true with a short life time, renew will happen |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
57 |
// 3. renewTGT=true with a long life time, renew won't happen |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
58 |
int test = Integer.parseInt(args[0]); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
59 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
60 |
OneKDC k = new OneKDC(null); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
61 |
KDC.saveConfig(OneKDC.KRB5_CONF, k, |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
62 |
"renew_lifetime = 1d", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
63 |
"ticket_lifetime = " + (test == 2? "10s": "8h")); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
64 |
Config.refresh(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
65 |
k.writeJAASConf(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
66 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
67 |
// KDC would save ccache in a file |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
68 |
System.setProperty("test.kdc.save.ccache", "cache.here"); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
69 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
70 |
Files.write(Paths.get(OneKDC.JAAS_CONF), Arrays.asList( |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
71 |
"first {", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
72 |
" com.sun.security.auth.module.Krb5LoginModule required;", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
73 |
"};", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
74 |
"second {", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
75 |
" com.sun.security.auth.module.Krb5LoginModule required", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
76 |
" doNotPrompt=true", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
77 |
" renewTGT=" + (test != 1), |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
78 |
" useTicketCache=true", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
79 |
" ticketCache=cache.here;", |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
80 |
"};" |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
81 |
)); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
82 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
83 |
Context c; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
84 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
85 |
// The first login uses username and password |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
86 |
c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
87 |
Date d1 = c.s().getPrivateCredentials(KerberosTicket.class).iterator().next().getAuthTime(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
88 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
89 |
// 6s is longer than half of 10s |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
90 |
Thread.sleep(6000); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
91 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
92 |
// The second login uses the cache |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
93 |
c = Context.fromJAAS("second"); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
94 |
Date d2 = c.s().getPrivateCredentials(KerberosTicket.class).iterator().next().getAuthTime(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
95 |
|
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
96 |
if (test == 2) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
97 |
if (d1.equals(d2)) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
98 |
throw new Exception("Ticket not renewed"); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
99 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
100 |
} else { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
101 |
if (!d1.equals(d2)) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
102 |
throw new Exception("Ticket renewed"); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
103 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
104 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
105 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff
changeset
|
106 |
} |