author | ssahoo |
Thu, 25 Jan 2018 05:57:22 -0800 | |
changeset 48668 | 2da4a52715d8 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
14340 | 1 |
/* |
48668 | 2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
14340 | 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 |
|
48668 | 26 |
* @bug 7110803 8170732 8194486 |
14340 | 27 |
* @summary SASL service for multiple hostnames |
48668 | 28 |
* @library /test/lib |
14340 | 29 |
* @compile -XDignore.symbol.file SaslBasic.java |
48668 | 30 |
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts |
31 |
* @run main/othervm -Djdk.net.hosts.file=TestHosts SaslBasic bound auth-int |
|
32 |
* @run main/othervm -Djdk.net.hosts.file=TestHosts SaslBasic unbound auth-conf |
|
33 |
* @run main/othervm -Djdk.net.hosts.file=TestHosts SaslBasic bound auth |
|
14340 | 34 |
*/ |
35 |
import java.io.IOException; |
|
36 |
import java.util.Arrays; |
|
37 |
import java.util.HashMap; |
|
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"); |
|
39484
3cf8b2fa2b9e
8135114: sun/security/krb5/auto tests failed on machine with TR locale
akosarev
parents:
31474
diff
changeset
|
49 |
String name = "host." + OneKDC.REALM_LOWER_CASE; |
14340 | 50 |
|
51 |
new OneKDC(null).writeJAASConf(); |
|
52 |
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); |
|
53 |
||
54 |
HashMap clntprops = new HashMap(); |
|
43000
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
55 |
clntprops.put(Sasl.QOP, args[1]); |
14340 | 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]; |
|
43000
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
78 |
byte[] lastClientToken = null; |
14340 | 79 |
while (!sc.isComplete() || !ss.isComplete()) { |
80 |
if (!sc.isComplete()) { |
|
81 |
token = sc.evaluateChallenge(token); |
|
43000
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
82 |
lastClientToken = token; |
14340 | 83 |
} |
84 |
if (!ss.isComplete()) { |
|
85 |
token = ss.evaluateResponse(token); |
|
86 |
} |
|
87 |
} |
|
88 |
if (!bound) { |
|
25403
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
89 |
String boundName = (String)ss.getNegotiatedProperty( |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
90 |
Sasl.BOUND_SERVER_NAME); |
14340 | 91 |
if (!boundName.equals(name)) { |
92 |
throw new Exception("Wrong bound server name"); |
|
93 |
} |
|
94 |
} |
|
25403
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
95 |
Object key = ss.getNegotiatedProperty( |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
96 |
"com.sun.security.jgss.inquiretype.krb5_get_session_key"); |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
97 |
if (key == null) { |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
98 |
throw new Exception("Extended negotiated property not read"); |
e982fe3e83a4
8044085: Access ExtendedGSSContext.inquireSecContext() result through SASL
weijun
parents:
14340
diff
changeset
|
99 |
} |
43000
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
100 |
|
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
101 |
if (args[1].equals("auth")) { |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
102 |
// 8170732. These are the maximum size bytes after jgss/krb5 wrap. |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
103 |
if (lastClientToken[17] != 0 || lastClientToken[18] != 0 |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
104 |
|| lastClientToken[19] != 0) { |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
105 |
throw new Exception("maximum size for auth must be 0"); |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
106 |
} |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
107 |
} else { |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
108 |
byte[] hello = "hello".getBytes(); |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
109 |
token = sc.wrap(hello, 0, hello.length); |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
110 |
token = ss.unwrap(token, 0, token.length); |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
111 |
if (!Arrays.equals(hello, token)) { |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
112 |
throw new Exception("Message altered"); |
fa648bd4286b
8170732: GssKrb5Client sends non-zero buffer size when qop is "auth"
weijun
parents:
39484
diff
changeset
|
113 |
} |
14340 | 114 |
} |
115 |
} |
|
116 |
} |