164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
else
_GS2Header = (_plusAvailable ? @"p=tls-unique,," : @"y,,");
_cNonce = [[self XMPP_genNonce] retain];
[_clientFirstMessageBare release];
_clientFirstMessageBare = nil;
_clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@",
_authcid,
_cNonce];
[ret addItems: [_GS2Header UTF8String]
count: [_GS2Header UTF8StringLength]];
[ret addItems: [_clientFirstMessageBare UTF8String]
count: [_clientFirstMessageBare UTF8StringLength]];
|
|
|
<
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
else
_GS2Header = (_plusAvailable ? @"p=tls-unique,," : @"y,,");
_cNonce = [[self XMPP_genNonce] retain];
[_clientFirstMessageBare release];
_clientFirstMessageBare = nil;
_clientFirstMessageBare = [[OFString alloc]
initWithFormat: @"n=%@,r=%@", _authcid, _cNonce];
[ret addItems: [_GS2Header UTF8String]
count: [_GS2Header UTF8StringLength]];
[ret addItems: [_clientFirstMessageBare UTF8String]
count: [_clientFirstMessageBare UTF8StringLength]];
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
while ((comp = [enumerator nextObject]) != nil) {
OFString *entry = [comp substringWithRange:
of_range(2, [comp length] - 2)];
if ([comp hasPrefix: @"r="]) {
if (![entry hasPrefix: _cNonce])
@throw [XMPPAuthFailedException
exceptionWithClass: [self class]
connection: nil
reason: @"Received wrong "
@"nonce"];
sNonce = entry;
got |= GOT_SNONCE;
} else if ([comp hasPrefix: @"s="]) {
salt = [OFDataArray
dataArrayWithBase64EncodedString: entry];
got |= GOT_SALT;
} else if ([comp hasPrefix: @"i="]) {
iterCount = [entry decimalValue];
got |= GOT_ITERCOUNT;
}
}
if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
@throw [OFInvalidServerReplyException
exceptionWithClass: [self class]];
// Add c=<base64(GS2Header+channelBindingData)>
tmpArray = [OFDataArray dataArray];
[tmpArray addItems: [_GS2Header UTF8String]
count: [_GS2Header UTF8StringLength]];
if (_plusAvailable && [_connection encrypted]) {
OFDataArray *channelBinding = [((SSLSocket*)[_connection socket])
|
<
|
|
|
|
<
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
while ((comp = [enumerator nextObject]) != nil) {
OFString *entry = [comp substringWithRange:
of_range(2, [comp length] - 2)];
if ([comp hasPrefix: @"r="]) {
if (![entry hasPrefix: _cNonce])
@throw [XMPPAuthFailedException
exceptionWithConnection: nil
reason: @"Received wrong "
@"nonce"];
sNonce = entry;
got |= GOT_SNONCE;
} else if ([comp hasPrefix: @"s="]) {
salt = [OFDataArray
dataArrayWithBase64EncodedString: entry];
got |= GOT_SALT;
} else if ([comp hasPrefix: @"i="]) {
iterCount = [entry decimalValue];
got |= GOT_ITERCOUNT;
}
}
if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
@throw [OFInvalidServerReplyException exception];
// Add c=<base64(GS2Header+channelBindingData)>
tmpArray = [OFDataArray dataArray];
[tmpArray addItems: [_GS2Header UTF8String]
count: [_GS2Header UTF8StringLength]];
if (_plusAvailable && [_connection encrypted]) {
OFDataArray *channelBinding = [((SSLSocket*)[_connection socket])
|
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
length: [data count] *
[data itemSize]];
value = [mess substringWithRange: of_range(2, [mess length] - 2)];
if ([mess hasPrefix: @"v="]) {
if (![value isEqual: [_serverSignature stringByBase64Encoding]])
@throw [XMPPAuthFailedException
exceptionWithClass: [self class]
connection: nil
reason: @"Received wrong "
@"ServerSignature"];
_authenticated = YES;
} else
@throw [XMPPAuthFailedException exceptionWithClass: [self class]
connection: nil
reason: value];
return nil;
}
- (OFString*)XMPP_genNonce
{
uint8_t buf[64];
|
<
|
|
|
|
<
|
|
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
length: [data count] *
[data itemSize]];
value = [mess substringWithRange: of_range(2, [mess length] - 2)];
if ([mess hasPrefix: @"v="]) {
if (![value isEqual: [_serverSignature stringByBase64Encoding]])
@throw [XMPPAuthFailedException
exceptionWithConnection: nil
reason: @"Received wrong "
@"ServerSignature"];
_authenticated = YES;
} else
@throw [XMPPAuthFailedException exceptionWithConnection: nil
reason: value];
return nil;
}
- (OFString*)XMPP_genNonce
{
uint8_t buf[64];
|