author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 25403 | e982fe3e83a4 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
14340 | 1 |
/* |
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* |
|
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. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 7110803 |
|
27 |
* @summary SASL service for multiple hostnames |
|
28 |
* @compile -XDignore.symbol.file SaslBasic.java |
|
29 |
* @run main/othervm SaslBasic bound |
|
30 |
* @run main/othervm SaslBasic unbound |
|
31 |
*/ |
|
25403
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
32 |
import com.sun.security.jgss.InquireType; |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
33 |
|
14340 | 34 |
import java.io.IOException; |
35 |
import java.util.Arrays; |
|
36 |
import java.util.HashMap; |
|
37 |
import java.util.Locale; |
|
38 |
import javax.security.auth.callback.Callback; |
|
39 |
import javax.security.auth.callback.CallbackHandler; |
|
40 |
import javax.security.auth.callback.UnsupportedCallbackException; |
|
41 |
import javax.security.sasl.*; |
|
42 |
||
43 |
// The basic krb5 test skeleton you can copy from |
|
44 |
public class SaslBasic { |
|
45 |
||
46 |
public static void main(String[] args) throws Exception { |
|
47 |
||
48 |
boolean bound = args[0].equals("bound"); |
|
49 |
String name = "host." + OneKDC.REALM.toLowerCase(Locale.US); |
|
50 |
||
51 |
new OneKDC(null).writeJAASConf(); |
|
52 |
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); |
|
53 |
||
54 |
HashMap clntprops = new HashMap(); |
|
55 |
clntprops.put(Sasl.QOP, "auth-conf"); |
|
56 |
SaslClient sc = Sasl.createSaslClient( |
|
57 |
new String[]{"GSSAPI"}, null, "server", |
|
58 |
name, clntprops, null); |
|
59 |
||
60 |
final HashMap srvprops = new HashMap(); |
|
61 |
srvprops.put(Sasl.QOP, "auth,auth-int,auth-conf"); |
|
62 |
SaslServer ss = Sasl.createSaslServer("GSSAPI", "server", |
|
63 |
bound? name: null, srvprops, |
|
64 |
new CallbackHandler() { |
|
65 |
public void handle(Callback[] callbacks) |
|
66 |
throws IOException, UnsupportedCallbackException { |
|
67 |
for (Callback cb : callbacks) { |
|
68 |
if (cb instanceof RealmCallback) { |
|
69 |
((RealmCallback) cb).setText(OneKDC.REALM); |
|
70 |
} else if (cb instanceof AuthorizeCallback) { |
|
71 |
((AuthorizeCallback) cb).setAuthorized(true); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
}); |
|
76 |
||
77 |
byte[] token = new byte[0]; |
|
78 |
while (!sc.isComplete() || !ss.isComplete()) { |
|
79 |
if (!sc.isComplete()) { |
|
80 |
token = sc.evaluateChallenge(token); |
|
81 |
} |
|
82 |
if (!ss.isComplete()) { |
|
83 |
token = ss.evaluateResponse(token); |
|
84 |
} |
|
85 |
} |
|
86 |
if (!bound) { |
|
25403
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
87 |
String boundName = (String)ss.getNegotiatedProperty( |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
88 |
Sasl.BOUND_SERVER_NAME); |
14340 | 89 |
if (!boundName.equals(name)) { |
90 |
throw new Exception("Wrong bound server name"); |
|
91 |
} |
|
92 |
} |
|
25403
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
93 |
Object key = ss.getNegotiatedProperty( |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
94 |
"com.sun.security.jgss.inquiretype.krb5_get_session_key"); |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
95 |
if (key == null) { |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
96 |
throw new Exception("Extended negotiated property not read"); |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
97 |
} |
14340 | 98 |
byte[] hello = "hello".getBytes(); |
99 |
token = sc.wrap(hello, 0, hello.length); |
|
100 |
token = ss.unwrap(token, 0, token.length); |
|
101 |
if (!Arrays.equals(hello, token)) { |
|
102 |
throw new Exception("Message altered"); |
|
103 |
} |
|
104 |
} |
|
105 |
} |