author | weijun |
Fri, 12 Aug 2011 11:20:45 +0800 | |
changeset 10327 | 37a3f951eb3a |
parent 8396 | 587947f96036 |
child 14895 | 5ad2d7032375 |
permissions | -rw-r--r-- |
4168 | 1 |
/* |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
7172
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
4168 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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. |
|
4168 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6893158 |
|
4532 | 27 |
* @bug 6907425 |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
7172
diff
changeset
|
28 |
* @run main/othervm MoreKvno |
4168 | 29 |
* @summary AP_REQ check should use key version number |
30 |
*/ |
|
31 |
||
4532 | 32 |
import org.ietf.jgss.GSSException; |
4168 | 33 |
import sun.security.jgss.GSSUtil; |
4532 | 34 |
import sun.security.krb5.KrbException; |
4168 | 35 |
import sun.security.krb5.PrincipalName; |
36 |
import sun.security.krb5.internal.ktab.KeyTab; |
|
4532 | 37 |
import sun.security.krb5.internal.Krb5; |
4168 | 38 |
|
39 |
public class MoreKvno { |
|
40 |
||
4532 | 41 |
static PrincipalName p; |
4168 | 42 |
public static void main(String[] args) |
43 |
throws Exception { |
|
44 |
||
45 |
OneKDC kdc = new OneKDC(null); |
|
46 |
kdc.writeJAASConf(); |
|
47 |
||
48 |
// Rewrite keytab, 3 set of keys with different kvno |
|
49 |
KeyTab ktab = KeyTab.create(OneKDC.KTAB); |
|
4532 | 50 |
p = new PrincipalName( |
51 |
OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); |
|
7172 | 52 |
ktab.addEntry(p, "pass1".toCharArray(), 1, true); |
53 |
ktab.addEntry(p, "pass3".toCharArray(), 3, true); |
|
54 |
ktab.addEntry(p, "pass2".toCharArray(), 2, true); |
|
4168 | 55 |
ktab.save(); |
56 |
||
4532 | 57 |
char[] pass = "pass2".toCharArray(); |
58 |
kdc.addPrincipal(OneKDC.SERVER, pass); |
|
59 |
go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); |
|
60 |
||
61 |
pass = "pass3".toCharArray(); |
|
62 |
kdc.addPrincipal(OneKDC.SERVER, pass); |
|
4168 | 63 |
// "server" initiate also, check pass2 is used at authentication |
4532 | 64 |
go(OneKDC.SERVER, "server", pass); |
65 |
||
66 |
try { |
|
67 |
pass = "pass4".toCharArray(); |
|
68 |
kdc.addPrincipal(OneKDC.SERVER, pass); |
|
69 |
go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); |
|
70 |
throw new Exception("This test should fail"); |
|
71 |
} catch (GSSException gsse) { |
|
72 |
KrbException ke = (KrbException)gsse.getCause(); |
|
73 |
if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) { |
|
74 |
throw new Exception("Not expected failure code: " + |
|
75 |
ke.returnCode()); |
|
76 |
} |
|
77 |
} |
|
4168 | 78 |
} |
79 |
||
4532 | 80 |
static void go(String server, String entry, char[] pass) throws Exception { |
4168 | 81 |
Context c, s; |
4532 | 82 |
|
83 |
// Part 1: Test keytab |
|
4168 | 84 |
c = Context.fromUserPass("dummy", "bogus".toCharArray(), false); |
85 |
s = Context.fromJAAS(entry); |
|
86 |
||
87 |
c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID); |
|
88 |
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID); |
|
89 |
||
90 |
Context.handshake(c, s); |
|
91 |
||
92 |
s.dispose(); |
|
93 |
c.dispose(); |
|
4532 | 94 |
|
95 |
// Part 2: Test username/password pair |
|
96 |
c = Context.fromUserPass("dummy", "bogus".toCharArray(), false); |
|
97 |
s = Context.fromUserPass(p.getNameString(), pass, true); |
|
98 |
||
99 |
c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID); |
|
100 |
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID); |
|
101 |
||
102 |
Context.handshake(c, s); |
|
103 |
||
104 |
s.dispose(); |
|
105 |
c.dispose(); |
|
4168 | 106 |
} |
107 |
} |