author | weijun |
Tue, 11 Aug 2009 12:20:32 +0800 | |
changeset 3483 | a16fce1820ef |
parent 3482 | 4aaa66ce712d |
child 4336 | 4c792c19266e |
permissions | -rw-r--r-- |
1454 | 1 |
/* |
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
2 |
* Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. |
1454 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
*/ |
|
23 |
||
24 |
import com.sun.security.auth.module.Krb5LoginModule; |
|
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
25 |
import java.security.Key; |
1454 | 26 |
import java.security.PrivilegedActionException; |
27 |
import java.security.PrivilegedExceptionAction; |
|
28 |
import java.util.Arrays; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.Map; |
|
31 |
import javax.security.auth.Subject; |
|
32 |
import javax.security.auth.kerberos.KerberosKey; |
|
33 |
import javax.security.auth.kerberos.KerberosTicket; |
|
34 |
import javax.security.auth.login.LoginContext; |
|
35 |
import org.ietf.jgss.GSSContext; |
|
36 |
import org.ietf.jgss.GSSCredential; |
|
37 |
import org.ietf.jgss.GSSException; |
|
38 |
import org.ietf.jgss.GSSManager; |
|
39 |
import org.ietf.jgss.GSSName; |
|
40 |
import org.ietf.jgss.MessageProp; |
|
41 |
import org.ietf.jgss.Oid; |
|
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
42 |
import com.sun.security.jgss.ExtendedGSSContext; |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
43 |
import com.sun.security.jgss.InquireType; |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
44 |
import com.sun.security.jgss.AuthorizationDataEntry; |
1454 | 45 |
|
46 |
/** |
|
47 |
* Context of a JGSS subject, encapsulating Subject and GSSContext. |
|
48 |
* |
|
49 |
* Three "constructors", which acquire the (private) credentials and fill |
|
50 |
* it into the Subject: |
|
51 |
* |
|
52 |
* 1. static fromJAAS(): Creates a Context using a JAAS login config entry |
|
53 |
* 2. static fromUserPass(): Creates a Context using a username and a password |
|
54 |
* 3. delegated(): A new context which uses the delegated credentials from a |
|
55 |
* previously established acceptor Context |
|
56 |
* |
|
57 |
* Two context initiators, which create the GSSContext object inside: |
|
58 |
* |
|
59 |
* 1. startAsClient() |
|
60 |
* 2. startAsServer() |
|
61 |
* |
|
62 |
* Privileged action: |
|
63 |
* doAs(): Performs an action in the name of the Subject |
|
64 |
* |
|
65 |
* Handshake process: |
|
66 |
* static handShake(initiator, acceptor) |
|
67 |
* |
|
68 |
* A four-phase typical data communication which includes all four GSS |
|
69 |
* actions (wrap, unwrap, getMic and veryfyMiC): |
|
70 |
* static transmit(message, from, to) |
|
71 |
*/ |
|
72 |
public class Context { |
|
73 |
||
74 |
private Subject s; |
|
75 |
private GSSContext x; |
|
76 |
private boolean f; // context established? |
|
77 |
private String name; |
|
78 |
private GSSCredential cred; // see static method delegated(). |
|
79 |
||
80 |
private Context() {} |
|
81 |
||
82 |
/** |
|
83 |
* Using the delegated credentials from a previous acceptor |
|
84 |
* @param c |
|
85 |
*/ |
|
86 |
public Context delegated() throws Exception { |
|
87 |
Context out = new Context(); |
|
88 |
out.s = s; |
|
89 |
out.cred = x.getDelegCred(); |
|
90 |
out.name = name + " as " + out.cred.getName().toString(); |
|
91 |
return out; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Logins with a JAAS login config entry name |
|
96 |
*/ |
|
97 |
public static Context fromJAAS(final String name) throws Exception { |
|
98 |
Context out = new Context(); |
|
99 |
out.name = name; |
|
100 |
LoginContext lc = new LoginContext(name); |
|
101 |
lc.login(); |
|
102 |
out.s = lc.getSubject(); |
|
103 |
return out; |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Logins with a username and a password, using Krb5LoginModule directly |
|
108 |
* @param storeKey true if key should be saved, used on acceptor side |
|
109 |
*/ |
|
110 |
public static Context fromUserPass(String user, char[] pass, boolean storeKey) throws Exception { |
|
111 |
Context out = new Context(); |
|
112 |
out.name = user; |
|
113 |
out.s = new Subject(); |
|
114 |
Krb5LoginModule krb5 = new Krb5LoginModule(); |
|
115 |
Map<String, String> map = new HashMap<String, String>(); |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
116 |
Map<String, Object> shared = new HashMap<String, Object>(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
117 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
118 |
if (pass != null) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
119 |
map.put("useFirstPass", "true"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
120 |
shared.put("javax.security.auth.login.name", user); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
121 |
shared.put("javax.security.auth.login.password", pass); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
122 |
} else { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
123 |
map.put("doNotPrompt", "true"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
124 |
map.put("useTicketCache", "true"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
125 |
if (user != null) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
126 |
map.put("principal", user); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
127 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
1574
diff
changeset
|
128 |
} |
1454 | 129 |
if (storeKey) { |
130 |
map.put("storeKey", "true"); |
|
131 |
} |
|
132 |
||
133 |
krb5.initialize(out.s, null, shared, map); |
|
134 |
krb5.login(); |
|
135 |
krb5.commit(); |
|
136 |
return out; |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Starts as a client |
|
141 |
* @param target communication peer |
|
142 |
* @param mech GSS mech |
|
143 |
* @throws java.lang.Exception |
|
144 |
*/ |
|
145 |
public void startAsClient(final String target, final Oid mech) throws Exception { |
|
146 |
doAs(new Action() { |
|
147 |
@Override |
|
148 |
public byte[] run(Context me, byte[] dummy) throws Exception { |
|
149 |
GSSManager m = GSSManager.getInstance(); |
|
150 |
me.x = m.createContext( |
|
151 |
target.indexOf('@') < 0 ? |
|
152 |
m.createName(target, null) : |
|
153 |
m.createName(target, GSSName.NT_HOSTBASED_SERVICE), |
|
154 |
mech, |
|
155 |
cred, |
|
156 |
GSSContext.DEFAULT_LIFETIME); |
|
157 |
return null; |
|
158 |
} |
|
159 |
}, null); |
|
160 |
f = false; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Starts as a server |
|
165 |
* @param mech GSS mech |
|
166 |
* @throws java.lang.Exception |
|
167 |
*/ |
|
168 |
public void startAsServer(final Oid mech) throws Exception { |
|
169 |
doAs(new Action() { |
|
170 |
@Override |
|
171 |
public byte[] run(Context me, byte[] dummy) throws Exception { |
|
172 |
GSSManager m = GSSManager.getInstance(); |
|
173 |
me.x = m.createContext(m.createCredential( |
|
174 |
null, |
|
175 |
GSSCredential.INDEFINITE_LIFETIME, |
|
176 |
mech, |
|
177 |
GSSCredential.ACCEPT_ONLY)); |
|
178 |
return null; |
|
179 |
} |
|
180 |
}, null); |
|
181 |
f = false; |
|
182 |
} |
|
183 |
||
184 |
/** |
|
185 |
* Accesses the internal GSSContext object. Currently it's used for -- |
|
186 |
* |
|
187 |
* 1. calling requestXXX() before handshake |
|
188 |
* 2. accessing source name |
|
189 |
* |
|
190 |
* Note: If the application needs to do any privileged call on this |
|
191 |
* object, please use doAs(). Otherwise, it can be done directly. The |
|
192 |
* methods listed above are all non-privileged calls. |
|
193 |
* |
|
194 |
* @return the GSSContext object |
|
195 |
*/ |
|
196 |
public GSSContext x() { |
|
197 |
return x; |
|
198 |
} |
|
199 |
||
200 |
/** |
|
201 |
* Disposes the GSSContext within |
|
202 |
* @throws org.ietf.jgss.GSSException |
|
203 |
*/ |
|
204 |
public void dispose() throws GSSException { |
|
205 |
x.dispose(); |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Does something using the Subject inside |
|
210 |
* @param action the action |
|
211 |
* @param in the input byte |
|
212 |
* @return the output byte |
|
213 |
* @throws java.lang.Exception |
|
214 |
*/ |
|
215 |
public byte[] doAs(final Action action, final byte[] in) throws Exception { |
|
216 |
try { |
|
217 |
return Subject.doAs(s, new PrivilegedExceptionAction<byte[]>() { |
|
218 |
||
219 |
@Override |
|
220 |
public byte[] run() throws Exception { |
|
221 |
return action.run(Context.this, in); |
|
222 |
} |
|
223 |
}); |
|
224 |
} catch (PrivilegedActionException pae) { |
|
225 |
throw pae.getException(); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Prints status of GSSContext and Subject |
|
231 |
* @throws java.lang.Exception |
|
232 |
*/ |
|
233 |
public void status() throws Exception { |
|
234 |
System.out.println("STATUS OF " + name.toUpperCase()); |
|
235 |
try { |
|
236 |
StringBuffer sb = new StringBuffer(); |
|
237 |
if (x.getAnonymityState()) { |
|
238 |
sb.append("anon, "); |
|
239 |
} |
|
240 |
if (x.getConfState()) { |
|
241 |
sb.append("conf, "); |
|
242 |
} |
|
243 |
if (x.getCredDelegState()) { |
|
244 |
sb.append("deleg, "); |
|
245 |
} |
|
246 |
if (x.getIntegState()) { |
|
247 |
sb.append("integ, "); |
|
248 |
} |
|
249 |
if (x.getMutualAuthState()) { |
|
250 |
sb.append("mutual, "); |
|
251 |
} |
|
252 |
if (x.getReplayDetState()) { |
|
253 |
sb.append("rep det, "); |
|
254 |
} |
|
255 |
if (x.getSequenceDetState()) { |
|
256 |
sb.append("seq det, "); |
|
257 |
} |
|
258 |
System.out.println("Context status of " + name + ": " + sb.toString()); |
|
259 |
System.out.println(x.getSrcName() + " -> " + x.getTargName()); |
|
260 |
} catch (Exception e) { |
|
261 |
;// Don't care |
|
262 |
} |
|
263 |
System.out.println("====================================="); |
|
264 |
for (Object o : s.getPrivateCredentials()) { |
|
265 |
System.out.println(" " + o.getClass()); |
|
266 |
if (o instanceof KerberosTicket) { |
|
267 |
KerberosTicket kt = (KerberosTicket) o; |
|
268 |
System.out.println(" " + kt.getServer() + " for " + kt.getClient()); |
|
269 |
} else if (o instanceof KerberosKey) { |
|
270 |
KerberosKey kk = (KerberosKey) o; |
|
271 |
System.out.print(" " + kk.getKeyType() + " " + kk.getVersionNumber() + " " + kk.getAlgorithm() + " "); |
|
272 |
for (byte b : kk.getEncoded()) { |
|
273 |
System.out.printf("%02X", b & 0xff); |
|
274 |
} |
|
275 |
System.out.println(); |
|
276 |
} else if (o instanceof Map) { |
|
277 |
Map map = (Map) o; |
|
278 |
for (Object k : map.keySet()) { |
|
279 |
System.out.println(" " + k + ": " + map.get(k)); |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
283 |
if (x != null && x instanceof ExtendedGSSContext) { |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
284 |
if (x.isEstablished()) { |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
285 |
ExtendedGSSContext ex = (ExtendedGSSContext)x; |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
286 |
Key k = (Key)ex.inquireSecContext( |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
287 |
InquireType.KRB5_GET_SESSION_KEY); |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
288 |
if (k == null) { |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
289 |
throw new Exception("Session key cannot be null"); |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
290 |
} |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
291 |
System.out.println("Session key is: " + k); |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
292 |
boolean[] flags = (boolean[])ex.inquireSecContext( |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
293 |
InquireType.KRB5_GET_TKT_FLAGS); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
294 |
if (flags == null) { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
295 |
throw new Exception("Ticket flags cannot be null"); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
296 |
} |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
297 |
System.out.println("Ticket flags is: " + Arrays.toString(flags)); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
298 |
String authTime = (String)ex.inquireSecContext( |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
299 |
InquireType.KRB5_GET_AUTHTIME); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
300 |
if (authTime == null) { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
301 |
throw new Exception("Auth time cannot be null"); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
302 |
} |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
303 |
System.out.println("AuthTime is: " + authTime); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
304 |
if (!x.isInitiator()) { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
305 |
AuthorizationDataEntry[] ad = (AuthorizationDataEntry[])ex.inquireSecContext( |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
306 |
InquireType.KRB5_GET_AUTHZ_DATA); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
307 |
System.out.println("AuthzData is: " + Arrays.toString(ad)); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
308 |
} |
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
309 |
} |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
1575
diff
changeset
|
310 |
} |
1454 | 311 |
} |
312 |
||
313 |
/** |
|
314 |
* Transmits a message from one Context to another. The sender wraps the |
|
315 |
* message and sends it to the receiver. The receiver unwraps it, creates |
|
316 |
* a MIC of the clear text and sends it back to the sender. The sender |
|
317 |
* verifies the MIC against the message sent earlier. |
|
318 |
* @param message the message |
|
319 |
* @param s1 the sender |
|
320 |
* @param s2 the receiver |
|
321 |
* @throws java.lang.Exception If anything goes wrong |
|
322 |
*/ |
|
323 |
static public void transmit(final String message, final Context s1, |
|
324 |
final Context s2) throws Exception { |
|
325 |
final byte[] messageBytes = message.getBytes(); |
|
326 |
System.out.printf("-------------------- TRANSMIT from %s to %s------------------------\n", |
|
327 |
s1.name, s2.name); |
|
328 |
||
329 |
byte[] t = s1.doAs(new Action() { |
|
330 |
@Override |
|
331 |
public byte[] run(Context me, byte[] dummy) throws Exception { |
|
332 |
System.out.println("wrap"); |
|
333 |
MessageProp p1 = new MessageProp(0, true); |
|
334 |
byte[] out = me.x.wrap(messageBytes, 0, messageBytes.length, p1); |
|
335 |
System.out.println(printProp(p1)); |
|
336 |
return out; |
|
337 |
} |
|
338 |
}, null); |
|
339 |
||
340 |
t = s2.doAs(new Action() { |
|
341 |
@Override |
|
342 |
public byte[] run(Context me, byte[] input) throws Exception { |
|
343 |
MessageProp p1 = new MessageProp(0, true); |
|
344 |
byte[] bytes = me.x.unwrap(input, 0, input.length, p1); |
|
345 |
if (!Arrays.equals(messageBytes, bytes)) |
|
346 |
throw new Exception("wrap/unwrap mismatch"); |
|
347 |
System.out.println("unwrap"); |
|
348 |
System.out.println(printProp(p1)); |
|
349 |
p1 = new MessageProp(0, true); |
|
350 |
System.out.println("getMIC"); |
|
351 |
bytes = me.x.getMIC(bytes, 0, bytes.length, p1); |
|
352 |
System.out.println(printProp(p1)); |
|
353 |
return bytes; |
|
354 |
} |
|
355 |
}, t); |
|
356 |
// Re-unwrap should make p2.isDuplicateToken() returns true |
|
357 |
s1.doAs(new Action() { |
|
358 |
@Override |
|
359 |
public byte[] run(Context me, byte[] input) throws Exception { |
|
360 |
MessageProp p1 = new MessageProp(0, true); |
|
361 |
System.out.println("verifyMIC"); |
|
362 |
me.x.verifyMIC(input, 0, input.length, |
|
363 |
messageBytes, 0, messageBytes.length, |
|
364 |
p1); |
|
365 |
System.out.println(printProp(p1)); |
|
366 |
return null; |
|
367 |
} |
|
368 |
}, t); |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* Returns a string description of a MessageProp object |
|
373 |
* @param prop the object |
|
374 |
* @return the description |
|
375 |
*/ |
|
376 |
static public String printProp(MessageProp prop) { |
|
377 |
StringBuffer sb = new StringBuffer(); |
|
378 |
sb.append("MessagePop: "); |
|
379 |
sb.append("QOP="+ prop.getQOP() + ", "); |
|
380 |
sb.append(prop.getPrivacy()?"privacy, ":""); |
|
381 |
sb.append(prop.isDuplicateToken()?"dup, ":""); |
|
382 |
sb.append(prop.isGapToken()?"gap, ":""); |
|
383 |
sb.append(prop.isOldToken()?"old, ":""); |
|
384 |
sb.append(prop.isUnseqToken()?"unseq, ":""); |
|
385 |
sb.append(prop.getMinorString()+ "(" + prop.getMinorStatus()+")"); |
|
386 |
return sb.toString(); |
|
387 |
} |
|
388 |
||
389 |
/** |
|
390 |
* Handshake (security context establishment process) between two Contexts |
|
391 |
* @param c the initiator |
|
392 |
* @param s the acceptor |
|
393 |
* @throws java.lang.Exception |
|
394 |
*/ |
|
395 |
static public void handshake(final Context c, final Context s) throws Exception { |
|
396 |
byte[] t = new byte[0]; |
|
397 |
while (!c.f || !s.f) { |
|
398 |
t = c.doAs(new Action() { |
|
399 |
@Override |
|
400 |
public byte[] run(Context me, byte[] input) throws Exception { |
|
401 |
if (me.x.isEstablished()) { |
|
402 |
me.f = true; |
|
403 |
System.out.println(c.name + " side established"); |
|
1574 | 404 |
if (input != null) { |
405 |
throw new Exception("Context established but " + |
|
406 |
"still receive token at " + c.name); |
|
407 |
} |
|
1454 | 408 |
return null; |
409 |
} else { |
|
410 |
System.out.println(c.name + " call initSecContext"); |
|
411 |
return me.x.initSecContext(input, 0, input.length); |
|
412 |
} |
|
413 |
} |
|
414 |
}, t); |
|
415 |
||
416 |
t = s.doAs(new Action() { |
|
417 |
@Override |
|
418 |
public byte[] run(Context me, byte[] input) throws Exception { |
|
419 |
if (me.x.isEstablished()) { |
|
420 |
me.f = true; |
|
421 |
System.out.println(s.name + " side established"); |
|
1574 | 422 |
if (input != null) { |
423 |
throw new Exception("Context established but " + |
|
424 |
"still receive token at " + s.name); |
|
425 |
} |
|
1454 | 426 |
return null; |
427 |
} else { |
|
428 |
System.out.println(s.name + " called acceptSecContext"); |
|
429 |
return me.x.acceptSecContext(input, 0, input.length); |
|
430 |
} |
|
431 |
} |
|
432 |
}, t); |
|
433 |
} |
|
434 |
} |
|
435 |
} |