author | weijun |
Fri, 27 Nov 2009 08:51:28 +0800 | |
changeset 4336 | 4c792c19266e |
parent 3050 | c0ce59daa004 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2942
37d9baeb7518
6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
2
diff
changeset
|
2 |
* Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.security.jgss.krb5; |
|
27 |
||
28 |
import org.ietf.jgss.*; |
|
29 |
import javax.security.auth.kerberos.DelegationPermission; |
|
30 |
import java.io.IOException; |
|
31 |
import java.net.InetAddress; |
|
32 |
import java.net.Inet4Address; |
|
33 |
import java.net.Inet6Address; |
|
34 |
import java.security.MessageDigest; |
|
35 |
import java.security.NoSuchAlgorithmException; |
|
3050
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
36 |
import java.util.Arrays; |
2 | 37 |
import sun.security.krb5.*; |
2942
37d9baeb7518
6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
2
diff
changeset
|
38 |
import sun.security.jgss.HttpCaller; |
2 | 39 |
import sun.security.krb5.internal.Krb5; |
40 |
||
41 |
abstract class InitialToken extends Krb5Token { |
|
42 |
||
43 |
private static final int CHECKSUM_TYPE = 0x8003; |
|
44 |
||
45 |
private static final int CHECKSUM_LENGTH_SIZE = 4; |
|
46 |
private static final int CHECKSUM_BINDINGS_SIZE = 16; |
|
47 |
private static final int CHECKSUM_FLAGS_SIZE = 4; |
|
48 |
private static final int CHECKSUM_DELEG_OPT_SIZE = 2; |
|
49 |
private static final int CHECKSUM_DELEG_LGTH_SIZE = 2; |
|
50 |
||
51 |
private static final int CHECKSUM_DELEG_FLAG = 1; |
|
52 |
private static final int CHECKSUM_MUTUAL_FLAG = 2; |
|
53 |
private static final int CHECKSUM_REPLAY_FLAG = 4; |
|
54 |
private static final int CHECKSUM_SEQUENCE_FLAG = 8; |
|
55 |
private static final int CHECKSUM_CONF_FLAG = 16; |
|
56 |
private static final int CHECKSUM_INTEG_FLAG = 32; |
|
57 |
||
58 |
private final byte[] CHECKSUM_FIRST_BYTES = |
|
59 |
{(byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00}; |
|
60 |
||
61 |
private static final int CHANNEL_BINDING_AF_INET = 2; |
|
62 |
private static final int CHANNEL_BINDING_AF_INET6 = 24; |
|
63 |
private static final int CHANNEL_BINDING_AF_NULL_ADDR = 255; |
|
64 |
||
65 |
private static final int Inet4_ADDRSZ = 4; |
|
66 |
private static final int Inet6_ADDRSZ = 16; |
|
67 |
||
68 |
protected class OverloadedChecksum { |
|
69 |
||
70 |
private byte[] checksumBytes = null; |
|
71 |
private Credentials delegCreds = null; |
|
72 |
private int flags = 0; |
|
73 |
||
74 |
/** |
|
75 |
* Called on the initiator side when creating the |
|
76 |
* InitSecContextToken. |
|
77 |
*/ |
|
78 |
public OverloadedChecksum(Krb5Context context, |
|
79 |
Credentials tgt, |
|
80 |
Credentials serviceTicket) |
|
81 |
throws KrbException, IOException, GSSException { |
|
82 |
||
83 |
byte[] krbCredMessage = null; |
|
84 |
int pos = 0; |
|
85 |
int size = CHECKSUM_LENGTH_SIZE + CHECKSUM_BINDINGS_SIZE + |
|
86 |
CHECKSUM_FLAGS_SIZE; |
|
87 |
||
4336 | 88 |
if (!tgt.isForwardable()) { |
89 |
context.setCredDelegState(false); |
|
90 |
context.setDelegPolicyState(false); |
|
91 |
} else if (context.getCredDelegState()) { |
|
92 |
if (context.getDelegPolicyState()) { |
|
93 |
if (!serviceTicket.checkDelegate()) { |
|
94 |
// delegation not permitted by server policy, mark it |
|
95 |
context.setDelegPolicyState(false); |
|
96 |
} |
|
97 |
} |
|
98 |
} else if (context.getDelegPolicyState()) { |
|
99 |
if (serviceTicket.checkDelegate()) { |
|
100 |
context.setCredDelegState(true); |
|
2 | 101 |
} else { |
4336 | 102 |
context.setDelegPolicyState(false); |
2 | 103 |
} |
104 |
} |
|
105 |
||
4336 | 106 |
if (context.getCredDelegState()) { |
107 |
KrbCred krbCred = null; |
|
108 |
CipherHelper cipherHelper = |
|
109 |
context.getCipherHelper(serviceTicket.getSessionKey()); |
|
110 |
if (useNullKey(cipherHelper)) { |
|
111 |
krbCred = new KrbCred(tgt, serviceTicket, |
|
112 |
EncryptionKey.NULL_KEY); |
|
113 |
} else { |
|
114 |
krbCred = new KrbCred(tgt, serviceTicket, |
|
115 |
serviceTicket.getSessionKey()); |
|
116 |
} |
|
117 |
krbCredMessage = krbCred.getMessage(); |
|
118 |
size += CHECKSUM_DELEG_OPT_SIZE + |
|
119 |
CHECKSUM_DELEG_LGTH_SIZE + |
|
120 |
krbCredMessage.length; |
|
121 |
} |
|
122 |
||
2 | 123 |
checksumBytes = new byte[size]; |
124 |
||
125 |
checksumBytes[pos++] = CHECKSUM_FIRST_BYTES[0]; |
|
126 |
checksumBytes[pos++] = CHECKSUM_FIRST_BYTES[1]; |
|
127 |
checksumBytes[pos++] = CHECKSUM_FIRST_BYTES[2]; |
|
128 |
checksumBytes[pos++] = CHECKSUM_FIRST_BYTES[3]; |
|
129 |
||
130 |
ChannelBinding localBindings = context.getChannelBinding(); |
|
131 |
if (localBindings != null) { |
|
132 |
byte[] localBindingsBytes = |
|
133 |
computeChannelBinding(context.getChannelBinding()); |
|
134 |
System.arraycopy(localBindingsBytes, 0, |
|
135 |
checksumBytes, pos, localBindingsBytes.length); |
|
136 |
// System.out.println("ChannelBinding hash: " |
|
137 |
// + getHexBytes(localBindingsBytes)); |
|
138 |
} |
|
139 |
||
140 |
pos += CHECKSUM_BINDINGS_SIZE; |
|
141 |
||
142 |
if (context.getCredDelegState()) |
|
143 |
flags |= CHECKSUM_DELEG_FLAG; |
|
144 |
if (context.getMutualAuthState()) |
|
145 |
flags |= CHECKSUM_MUTUAL_FLAG; |
|
146 |
if (context.getReplayDetState()) |
|
147 |
flags |= CHECKSUM_REPLAY_FLAG; |
|
148 |
if (context.getSequenceDetState()) |
|
149 |
flags |= CHECKSUM_SEQUENCE_FLAG; |
|
150 |
if (context.getIntegState()) |
|
151 |
flags |= CHECKSUM_INTEG_FLAG; |
|
152 |
if (context.getConfState()) |
|
153 |
flags |= CHECKSUM_CONF_FLAG; |
|
154 |
||
155 |
byte[] temp = new byte[4]; |
|
156 |
writeLittleEndian(flags, temp); |
|
157 |
checksumBytes[pos++] = temp[0]; |
|
158 |
checksumBytes[pos++] = temp[1]; |
|
159 |
checksumBytes[pos++] = temp[2]; |
|
160 |
checksumBytes[pos++] = temp[3]; |
|
161 |
||
162 |
if (context.getCredDelegState()) { |
|
163 |
||
164 |
PrincipalName delegateTo = |
|
165 |
serviceTicket.getServer(); |
|
166 |
// Cannot use '\"' instead of "\"" in constructor because |
|
167 |
// it is interpreted as suggested length! |
|
168 |
StringBuffer buf = new StringBuffer("\""); |
|
169 |
buf.append(delegateTo.getName()).append('\"'); |
|
170 |
String realm = delegateTo.getRealmAsString(); |
|
171 |
buf.append(" \"krbtgt/").append(realm).append('@'); |
|
172 |
buf.append(realm).append('\"'); |
|
173 |
SecurityManager sm = System.getSecurityManager(); |
|
174 |
if (sm != null) { |
|
175 |
DelegationPermission perm = |
|
176 |
new DelegationPermission(buf.toString()); |
|
177 |
sm.checkPermission(perm); |
|
178 |
} |
|
179 |
||
180 |
||
181 |
/* |
|
182 |
* Write 1 in little endian but in two bytes |
|
183 |
* for DlgOpt |
|
184 |
*/ |
|
185 |
||
186 |
checksumBytes[pos++] = (byte)0x01; |
|
187 |
checksumBytes[pos++] = (byte)0x00; |
|
188 |
||
189 |
/* |
|
190 |
* Write the length of the delegated credential in little |
|
191 |
* endian but in two bytes for Dlgth |
|
192 |
*/ |
|
193 |
||
194 |
if (krbCredMessage.length > 0x0000ffff) |
|
195 |
throw new GSSException(GSSException.FAILURE, -1, |
|
196 |
"Incorrect messsage length"); |
|
197 |
||
198 |
writeLittleEndian(krbCredMessage.length, temp); |
|
199 |
checksumBytes[pos++] = temp[0]; |
|
200 |
checksumBytes[pos++] = temp[1]; |
|
201 |
System.arraycopy(krbCredMessage, 0, |
|
202 |
checksumBytes, pos, krbCredMessage.length); |
|
203 |
} |
|
204 |
||
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* Called on the acceptor side when reading an InitSecContextToken. |
|
209 |
*/ |
|
210 |
// XXX Passing in Checksum is not required. byte[] can |
|
211 |
// be passed in if this checksum type denotes a |
|
212 |
// raw_checksum. In that case, make Checksum class krb5 |
|
213 |
// internal. |
|
214 |
public OverloadedChecksum(Krb5Context context, |
|
215 |
Checksum checksum, EncryptionKey key) |
|
216 |
throws GSSException, KrbException, IOException { |
|
217 |
||
218 |
int pos = 0; |
|
219 |
||
220 |
checksumBytes = checksum.getBytes(); |
|
221 |
||
222 |
if ((checksumBytes[0] != CHECKSUM_FIRST_BYTES[0]) || |
|
223 |
(checksumBytes[1] != CHECKSUM_FIRST_BYTES[1]) || |
|
224 |
(checksumBytes[2] != CHECKSUM_FIRST_BYTES[2]) || |
|
225 |
(checksumBytes[3] != CHECKSUM_FIRST_BYTES[3])) { |
|
226 |
throw new GSSException(GSSException.FAILURE, -1, |
|
227 |
"Incorrect checksum"); |
|
228 |
} |
|
229 |
||
230 |
ChannelBinding localBindings = context.getChannelBinding(); |
|
231 |
||
3050
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
232 |
// Ignore remote channel binding info when not requested at |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
233 |
// local side (RFC 4121 4.1.1.2: the acceptor MAY ignore...). |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
234 |
// |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
235 |
// All major krb5 implementors implement this "MAY", |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
236 |
// and some applications depend on it as a workaround |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
237 |
// for not having a way to negotiate the use of channel |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
238 |
// binding -- the initiator application always uses CB |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
239 |
// and hopes the acceptor will ignore the CB if the |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
240 |
// acceptor doesn't support CB. |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
241 |
if (localBindings != null) { |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
242 |
byte[] remoteBindingBytes = new byte[CHECKSUM_BINDINGS_SIZE]; |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
243 |
System.arraycopy(checksumBytes, 4, remoteBindingBytes, 0, |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
244 |
CHECKSUM_BINDINGS_SIZE); |
2 | 245 |
|
3050
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
246 |
byte[] noBindings = new byte[CHECKSUM_BINDINGS_SIZE]; |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
247 |
if (!Arrays.equals(noBindings, remoteBindingBytes)) { |
2 | 248 |
byte[] localBindingsBytes = |
249 |
computeChannelBinding(localBindings); |
|
3050
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
250 |
if (!Arrays.equals(localBindingsBytes, |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
251 |
remoteBindingBytes)) { |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
252 |
throw new GSSException(GSSException.BAD_BINDINGS, -1, |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
253 |
"Bytes mismatch!"); |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
254 |
} |
2 | 255 |
} else { |
3050
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
256 |
throw new GSSException(GSSException.BAD_BINDINGS, -1, |
c0ce59daa004
6851973: ignore incoming channel binding if acceptor does not set one
weijun
parents:
2942
diff
changeset
|
257 |
"Token missing ChannelBinding!"); |
2 | 258 |
} |
259 |
} |
|
260 |
||
261 |
flags = readLittleEndian(checksumBytes, 20, 4); |
|
262 |
||
263 |
if ((flags & CHECKSUM_DELEG_FLAG) > 0) { |
|
264 |
||
265 |
/* |
|
266 |
* XXX |
|
267 |
* if ((checksumBytes[24] != (byte)0x01) && |
|
268 |
* (checksumBytes[25] != (byte)0x00)) |
|
269 |
*/ |
|
270 |
||
271 |
int credLen = readLittleEndian(checksumBytes, 26, 2); |
|
272 |
byte[] credBytes = new byte[credLen]; |
|
273 |
System.arraycopy(checksumBytes, 28, credBytes, 0, credLen); |
|
274 |
||
275 |
CipherHelper cipherHelper = context.getCipherHelper(key); |
|
276 |
if (useNullKey(cipherHelper)) { |
|
277 |
delegCreds = |
|
278 |
new KrbCred(credBytes, EncryptionKey.NULL_KEY). |
|
279 |
getDelegatedCreds()[0]; |
|
280 |
} else { |
|
281 |
delegCreds = |
|
282 |
new KrbCred(credBytes, key). |
|
283 |
getDelegatedCreds()[0]; |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
// check if KRB-CRED message should use NULL_KEY for encryption |
|
289 |
private boolean useNullKey(CipherHelper ch) { |
|
290 |
boolean flag = true; |
|
291 |
// for "newer" etypes and RC4-HMAC do not use NULL KEY |
|
292 |
if ((ch.getProto() == 1) || ch.isArcFour()) { |
|
293 |
flag = false; |
|
294 |
} |
|
295 |
return flag; |
|
296 |
} |
|
297 |
||
298 |
public Checksum getChecksum() throws KrbException { |
|
299 |
return new Checksum(checksumBytes, CHECKSUM_TYPE); |
|
300 |
} |
|
301 |
||
302 |
public Credentials getDelegatedCreds() { |
|
303 |
return delegCreds; |
|
304 |
} |
|
305 |
||
4336 | 306 |
// Only called by acceptor |
2 | 307 |
public void setContextFlags(Krb5Context context) { |
308 |
// default for cred delegation is false |
|
309 |
if ((flags & CHECKSUM_DELEG_FLAG) > 0) |
|
310 |
context.setCredDelegState(true); |
|
311 |
// default for the following are true |
|
312 |
if ((flags & CHECKSUM_MUTUAL_FLAG) == 0) { |
|
313 |
context.setMutualAuthState(false); |
|
314 |
} |
|
315 |
if ((flags & CHECKSUM_REPLAY_FLAG) == 0) { |
|
316 |
context.setReplayDetState(false); |
|
317 |
} |
|
318 |
if ((flags & CHECKSUM_SEQUENCE_FLAG) == 0) { |
|
319 |
context.setSequenceDetState(false); |
|
320 |
} |
|
321 |
if ((flags & CHECKSUM_CONF_FLAG) == 0) { |
|
322 |
context.setConfState(false); |
|
323 |
} |
|
324 |
if ((flags & CHECKSUM_INTEG_FLAG) == 0) { |
|
325 |
context.setIntegState(false); |
|
326 |
} |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
private int getAddrType(InetAddress addr) { |
|
331 |
int addressType = CHANNEL_BINDING_AF_NULL_ADDR; |
|
332 |
||
333 |
if (addr instanceof Inet4Address) |
|
334 |
addressType = CHANNEL_BINDING_AF_INET; |
|
335 |
else if (addr instanceof Inet6Address) |
|
336 |
addressType = CHANNEL_BINDING_AF_INET6; |
|
337 |
return (addressType); |
|
338 |
} |
|
339 |
||
340 |
private byte[] getAddrBytes(InetAddress addr) throws GSSException { |
|
341 |
int addressType = getAddrType(addr); |
|
342 |
byte[] addressBytes = addr.getAddress(); |
|
343 |
if (addressBytes != null) { |
|
344 |
switch (addressType) { |
|
345 |
case CHANNEL_BINDING_AF_INET: |
|
346 |
if (addressBytes.length != Inet4_ADDRSZ) { |
|
347 |
throw new GSSException(GSSException.FAILURE, -1, |
|
348 |
"Incorrect AF-INET address length in ChannelBinding."); |
|
349 |
} |
|
350 |
return (addressBytes); |
|
351 |
case CHANNEL_BINDING_AF_INET6: |
|
352 |
if (addressBytes.length != Inet6_ADDRSZ) { |
|
353 |
throw new GSSException(GSSException.FAILURE, -1, |
|
354 |
"Incorrect AF-INET6 address length in ChannelBinding."); |
|
355 |
} |
|
356 |
return (addressBytes); |
|
357 |
default: |
|
358 |
throw new GSSException(GSSException.FAILURE, -1, |
|
359 |
"Cannot handle non AF-INET addresses in ChannelBinding."); |
|
360 |
} |
|
361 |
} |
|
362 |
return null; |
|
363 |
} |
|
364 |
||
365 |
private byte[] computeChannelBinding(ChannelBinding channelBinding) |
|
366 |
throws GSSException { |
|
367 |
||
368 |
InetAddress initiatorAddress = channelBinding.getInitiatorAddress(); |
|
369 |
InetAddress acceptorAddress = channelBinding.getAcceptorAddress(); |
|
370 |
int size = 5*4; |
|
371 |
||
372 |
int initiatorAddressType = getAddrType(initiatorAddress); |
|
373 |
int acceptorAddressType = getAddrType(acceptorAddress); |
|
374 |
||
375 |
byte[] initiatorAddressBytes = null; |
|
376 |
if (initiatorAddress != null) { |
|
377 |
initiatorAddressBytes = getAddrBytes(initiatorAddress); |
|
378 |
size += initiatorAddressBytes.length; |
|
379 |
} |
|
380 |
||
381 |
byte[] acceptorAddressBytes = null; |
|
382 |
if (acceptorAddress != null) { |
|
383 |
acceptorAddressBytes = getAddrBytes(acceptorAddress); |
|
384 |
size += acceptorAddressBytes.length; |
|
385 |
} |
|
386 |
||
387 |
byte[] appDataBytes = channelBinding.getApplicationData(); |
|
388 |
if (appDataBytes != null) { |
|
389 |
size += appDataBytes.length; |
|
390 |
} |
|
391 |
||
392 |
byte[] data = new byte[size]; |
|
393 |
||
394 |
int pos = 0; |
|
395 |
||
396 |
writeLittleEndian(initiatorAddressType, data, pos); |
|
397 |
pos += 4; |
|
398 |
||
399 |
if (initiatorAddressBytes != null) { |
|
400 |
writeLittleEndian(initiatorAddressBytes.length, data, pos); |
|
401 |
pos += 4; |
|
402 |
System.arraycopy(initiatorAddressBytes, 0, |
|
403 |
data, pos, initiatorAddressBytes.length); |
|
404 |
pos += initiatorAddressBytes.length; |
|
405 |
} else { |
|
406 |
// Write length 0 |
|
407 |
pos += 4; |
|
408 |
} |
|
409 |
||
410 |
writeLittleEndian(acceptorAddressType, data, pos); |
|
411 |
pos += 4; |
|
412 |
||
413 |
if (acceptorAddressBytes != null) { |
|
414 |
writeLittleEndian(acceptorAddressBytes.length, data, pos); |
|
415 |
pos += 4; |
|
416 |
System.arraycopy(acceptorAddressBytes, 0, |
|
417 |
data, pos, acceptorAddressBytes.length); |
|
418 |
pos += acceptorAddressBytes.length; |
|
419 |
} else { |
|
420 |
// Write length 0 |
|
421 |
pos += 4; |
|
422 |
} |
|
423 |
||
424 |
if (appDataBytes != null) { |
|
425 |
writeLittleEndian(appDataBytes.length, data, pos); |
|
426 |
pos += 4; |
|
427 |
System.arraycopy(appDataBytes, 0, data, pos, |
|
428 |
appDataBytes.length); |
|
429 |
pos += appDataBytes.length; |
|
430 |
} else { |
|
431 |
// Write 0 |
|
432 |
pos += 4; |
|
433 |
} |
|
434 |
||
435 |
try { |
|
436 |
MessageDigest md5 = MessageDigest.getInstance("MD5"); |
|
437 |
return md5.digest(data); |
|
438 |
} catch (NoSuchAlgorithmException e) { |
|
439 |
throw new GSSException(GSSException.FAILURE, -1, |
|
440 |
"Could not get MD5 Message Digest - " |
|
441 |
+ e.getMessage()); |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
public abstract byte[] encode() throws IOException; |
|
446 |
||
447 |
} |