ObjXMPP  Diff

Differences From Artifact [b88bfe5c49]:

To Artifact [e3e56c14fb]:


164
165
166
167
168
169
170
171
172


173
174
175


176
177
178
179
180
181
182
164
165
166
167
168
169
170


171
172
173


174
175
176
177
178
179
180
181
182







-
-
+
+

-
-
+
+








	[clientFirstMessageBare release];
	clientFirstMessageBare = nil;
	clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@",
								   authcid,
								   cNonce];

	[ret addNItems: [GS2Header cStringLength]
	    fromCArray: [GS2Header cString]];
	[ret addNItems: [GS2Header UTF8StringLength]
	    fromCArray: [GS2Header UTF8String]];

	[ret addNItems: [clientFirstMessageBare cStringLength]
	    fromCArray: [clientFirstMessageBare cString]];
	[ret addNItems: [clientFirstMessageBare UTF8StringLength]
	    fromCArray: [clientFirstMessageBare UTF8String]];

	return ret;
}

- (OFDataArray*)calculateResponseWithChallenge: (OFDataArray*)challenge
{
	size_t i;
194
195
196
197
198
199
200
201
202
203



204
205
206
207
208
209
210
194
195
196
197
198
199
200



201
202
203
204
205
206
207
208
209
210







-
-
-
+
+
+







		GOT_ITERCOUNT = 0x04
	} got = 0;

	hash = [[[hashType alloc] init] autorelease];
	ret = [OFDataArray dataArrayWithItemSize: 1];
	authMessage = [OFDataArray dataArrayWithItemSize: 1];

	OFString *chal = [OFString stringWithCString: [challenge cArray]
					      length: [challenge count] *
						      [challenge itemSize]];
	OFString *chal = [OFString stringWithUTF8String: [challenge cArray]
						 length: [challenge count] *
							 [challenge itemSize]];

	enumerator =
	    [[chal componentsSeparatedByString: @","] objectEnumerator];
	while ((comp = [enumerator nextObject]) != nil) {
		OFString *entry = [comp substringWithRange:
		    of_range(2, [comp length] - 2)];

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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275


276
277
278
279
280
281
282
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282







-
-
+
+









-
-
+
+





-
-
+
+


-
-
+
+















-
-
+
+







	}

	if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
		@throw [OFInvalidServerReplyException newWithClass: isa];

	// Add c=<base64(GS2Header+channelBindingData)>
	tmpArray = [OFDataArray dataArrayWithItemSize: 1];
	[tmpArray addNItems: [GS2Header cStringLength]
		 fromCArray: [GS2Header cString]];
	[tmpArray addNItems: [GS2Header UTF8StringLength]
		 fromCArray: [GS2Header UTF8String]];
	if (plusAvailable && [connection encrypted]) {
		OFDataArray *channelBinding = [((SSLSocket*)[connection socket])
		    channelBindingDataWithType: @"tls-unique"];
		[tmpArray addNItems: [channelBinding count]
			 fromCArray: [channelBinding cArray]];
	}
	tmpString = [tmpArray stringByBase64Encoding];
	[ret addNItems: 2
	    fromCArray: "c="];
	[ret addNItems: [tmpString cStringLength]
	    fromCArray: [tmpString cString]];
	[ret addNItems: [tmpString UTF8StringLength]
	    fromCArray: [tmpString UTF8String]];

	// Add r=<nonce>
	[ret addItem: ","];
	[ret addNItems: 2
	    fromCArray: "r="];
	[ret addNItems: [sNonce cStringLength]
	    fromCArray: [sNonce cString]];
	[ret addNItems: [sNonce UTF8StringLength]
	    fromCArray: [sNonce UTF8String]];

	tmpArray = [OFDataArray dataArrayWithItemSize: 1];
	[tmpArray addNItems: [password cStringLength]
		 fromCArray: [password cString]];
	[tmpArray addNItems: [password UTF8StringLength]
		 fromCArray: [password UTF8String]];

	/*
	 * IETF RFC 5802:
	 * SaltedPassword := Hi(Normalize(password), salt, i)
	 */
	saltedPassword = [self XMPP_hiWithData: tmpArray
					  salt: salt
				iterationCount: iterCount];

	/*
	 * IETF RFC 5802:
	 * AuthMessage := client-first-message-bare + "," +
	 *		  server-first-message + "," +
	 *		  client-final-message-without-proof
	 */
	[authMessage addNItems: [clientFirstMessageBare cStringLength]
		    fromCArray: [clientFirstMessageBare cString]];
	[authMessage addNItems: [clientFirstMessageBare UTF8StringLength]
		    fromCArray: [clientFirstMessageBare UTF8String]];
	[authMessage addItem: ","];
	[authMessage addNItems: [challenge count] * [challenge itemSize]
		    fromCArray: [challenge cArray]];
	[authMessage addItem: ","];
	[authMessage addNItems: [ret count]
		    fromCArray: [ret cArray]];

340
341
342
343
344
345
346
347
348


349
350
351
352
353
354
355
356
357
358
359
360
361



362
363
364
365
366
367
368
340
341
342
343
344
345
346


347
348
349
350
351
352
353
354
355
356
357
358



359
360
361
362
363
364
365
366
367
368







-
-
+
+










-
-
-
+
+
+







	}

	// Add p=<base64(ClientProof)>
	[ret addItem: ","];
	[ret addNItems: 2
	    fromCArray: "p="];
	tmpString = [tmpArray stringByBase64Encoding];
	[ret addNItems: [tmpString cStringLength]
	    fromCArray: [tmpString cString]];
	[ret addNItems: [tmpString UTF8StringLength]
	    fromCArray: [tmpString UTF8String]];

	[ret retain];
	[pool release];

	return [ret autorelease];
}

- (void)parseServerFinalMessage: (OFDataArray*)message
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *mess = [OFString stringWithCString: [message cArray]
					      length: [message count] *
						      [message itemSize]];
	OFString *mess = [OFString stringWithUTF8String: [message cArray]
						 length: [message count] *
							 [message itemSize]];
	OFString *value = [mess substringWithRange:
	    of_range(2, [mess length] - 2)];

	if ([mess hasPrefix: @"v="]) {
		if (![value isEqual: [serverSignature stringByBase64Encoding]])
			@throw [XMPPAuthFailedException
			    newWithClass: isa
389
390
391
392
393
394
395

396
397
398
399
400
401
402
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403







+







		while (tmp == ',')
			tmp = ((buf[i] >> 1) % ('~' - '!')) + '!';

		buf[i] = tmp;
	}

	return [OFString stringWithCString: (char*)buf
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 64];
}

- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key
			data: (OFDataArray*)data
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];