ObjXMPP  Check-in [6a3b21ce25]

Overview
Comment:Adjust to latest ObjFW API changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6a3b21ce25e5740102258de6c49346b82d1fa5b13d05cab4b02d56954d141e09
User & Date: js on 2012-06-07 12:19:03
Other Links: manifest | tags
Context
2012-07-12
03:34
Don't access isa directly. check-in: c987aa9a5f user: js tags: trunk
2012-06-07
12:19
Adjust to latest ObjFW API changes. check-in: 6a3b21ce25 user: js tags: trunk
2012-06-01
22:16
Add missing header files check-in: 6d15f9618b user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPConnection.h from [59e5a55330] to [d1760a91eb].

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
 * This is useful for handling multiple connections at once.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer. If length is 0, it is assumed that
 *		 the connection was closed.
 */
- (void)parseBuffer: (const char*)buffer
	 withLength: (size_t)length;

/**
 * \brief Returns the socket used by the XMPPConnection.
 *
 * \return The socket used by the XMPPConnection
 */
- (OFTCPSocket*)socket;







|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
 * This is useful for handling multiple connections at once.
 *
 * \param buffer The buffer to parse
 * \param length The length of the buffer. If length is 0, it is assumed that
 *		 the connection was closed.
 */
- (void)parseBuffer: (const char*)buffer
	     length: (size_t)length;

/**
 * \brief Returns the socket used by the XMPPConnection.
 *
 * \return The socket used by the XMPPConnection
 */
- (OFTCPSocket*)socket;

Modified src/XMPPConnection.m from [0bbbbace48] to [e2f332ead2].

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
}

- (void)handleConnection
{
	char buffer[512];

	for (;;) {
		size_t length = [sock readNBytes: 512
				      intoBuffer: buffer];

		[self parseBuffer: buffer
		       withLength: length];

		if (length < 1)
			return;
	}
}

- (void)parseBuffer: (const char*)buffer
	 withLength: (size_t)length
{
	if (length < 1) {
		[delegates broadcastSelector: @selector(connectionWasClosed:)
				  withObject: self];
		return;
	}

	[parser parseBuffer: buffer
		 withLength: length];

	[oldParser release];
	[oldElementBuilder release];

	oldParser = nil;
	oldElementBuilder = nil;
}







|
|


|







|








|







291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
}

- (void)handleConnection
{
	char buffer[512];

	for (;;) {
		size_t length = [sock readIntoBuffer: buffer
					      length: 512];

		[self parseBuffer: buffer
			   length: length];

		if (length < 1)
			return;
	}
}

- (void)parseBuffer: (const char*)buffer
	     length: (size_t)length
{
	if (length < 1) {
		[delegates broadcastSelector: @selector(connectionWasClosed:)
				  withObject: self];
		return;
	}

	[parser parseBuffer: buffer
		     length: length];

	[oldParser release];
	[oldElementBuilder release];

	oldParser = nil;
	oldElementBuilder = nil;
}

Modified src/XMPPPLAINAuth.m from [ecc589ba4a] to [375d451a91].

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	if (authzid)
		[message addItem: authzid];

	/* separator */
	[message addItem: ""];

	/* authcid */
	[message addNItems: [authcid UTF8StringLength]
		fromCArray: [authcid UTF8String]];

	/* separator */
	[message addItem: ""];

	/* passwd */
	[message addNItems: [password UTF8StringLength]
		fromCArray: [password UTF8String]];

	return message;
}
@end







|
|





|
|




52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	if (authzid)
		[message addItem: authzid];

	/* separator */
	[message addItem: ""];

	/* authcid */
	[message addItemsFromCArray: [authcid UTF8String]
			      count: [authcid UTF8StringLength]];

	/* separator */
	[message addItem: ""];

	/* passwd */
	[message addItemsFromCArray: [password UTF8String]
			      count: [password UTF8StringLength]];

	return message;
}
@end

Modified src/XMPPSCRAMAuth.m from [e92e687eeb] to [b45bfcda94].

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

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

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

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


	return ret;
}

- (OFDataArray*)continueWithData: (OFDataArray*)data
{







|
|

|
|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

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

	[ret addItemsFromCArray: [GS2Header UTF8String]
			  count: [GS2Header UTF8StringLength]];

	[ret addItemsFromCArray: [clientFirstMessageBare UTF8String]
			  count: [clientFirstMessageBare UTF8StringLength]];


	return ret;
}

- (OFDataArray*)continueWithData: (OFDataArray*)data
{
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296

297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
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
369
370
371
372
373
374
375
376
	}

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

	// Add c=<base64(GS2Header+channelBindingData)>
	tmpArray = [OFDataArray dataArray];
	[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 UTF8StringLength]
	    fromCArray: [tmpString UTF8String]];

	// Add r=<nonce>
	[ret addItem: ","];
	[ret addNItems: 2
	    fromCArray: "r="];

	[ret addNItems: [sNonce UTF8StringLength]
	    fromCArray: [sNonce UTF8String]];

	/*
	 * IETF RFC 5802:
	 * SaltedPassword := Hi(Normalize(password), salt, i)
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: [password UTF8StringLength]
		 fromCArray: [password UTF8String]];

	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 UTF8StringLength]
		    fromCArray: [clientFirstMessageBare UTF8String]];

	[authMessage addItem: ","];

	[authMessage addNItems: [data count] * [data itemSize]
		    fromCArray: [data cArray]];
	[authMessage addItem: ","];
	[authMessage addNItems: [ret count]
		    fromCArray: [ret cArray]];

	/*
	 * IETF RFC 5802:
	 * ClientKey := HMAC(SaltedPassword, "Client Key")
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: 10
		 fromCArray: "Client Key"];
	clientKey = [self XMPP_HMACWithKey: saltedPassword
				      data: tmpArray];

	/*
	 * IETF RFC 5802:
	 * StoredKey := H(ClientKey)
	 */
	[hash updateWithBuffer: (void*) clientKey
			length: [hashType digestSize]];
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: [hashType digestSize]
		 fromCArray: [hash digest]];


	/*
	 * IETF RFC 5802:
	 * ClientSignature := HMAC(StoredKey, AuthMessage)
	 */
	clientSignature = [self XMPP_HMACWithKey: tmpArray
					    data: authMessage];

	/*
	 * IETF RFC 5802:
	 * ServerKey := HMAC(SaltedPassword, "Server Key")
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: 10
		 fromCArray: "Server Key"];
	serverKey = [self XMPP_HMACWithKey: saltedPassword
				      data: tmpArray];

	/*
	 * IETF RFC 5802:
	 * ServerSignature := HMAC(ServerKey, AuthMessage)
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: [hashType digestSize]
		 fromCArray: serverKey];

	serverSignature = [[OFDataArray alloc] init];
	[serverSignature addNItems: [hashType digestSize]
			fromCArray: [self XMPP_HMACWithKey: tmpArray
						      data: authMessage]];


	/*
	 * IETF RFC 5802:
	 * ClientProof := ClientKey XOR ClientSignature
	 */
	tmpArray = [OFDataArray dataArray];
	for (i = 0; i < [hashType digestSize]; i++) {
		uint8_t c = clientKey[i] ^ clientSignature[i];
		[tmpArray addItem: &c];
	}

	// Add p=<base64(ClientProof)>
	[ret addItem: ","];
	[ret addNItems: 2
	    fromCArray: "p="];

	tmpString = [tmpArray stringByBase64Encoding];
	[ret addNItems: [tmpString UTF8StringLength]
	    fromCArray: [tmpString UTF8String]];

	return ret;
}

- (OFDataArray*)XMPP_parseServerFinalMessage: (OFDataArray*)data
{
	OFString *mess, *value;







|
|



|
|


<
|
>
|
|



<
|
>
|
|






|
|











|
|
>

>
|
<

|
|






|
|










<
|
>













|
|








<
|
>

|
|
|
>













<
|
>

|
|







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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
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
369
370
371
372
373
374
375
376
377
378
	}

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

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

	[ret addItemsFromCArray: "c="
			  count: 2];
	[ret addItemsFromCArray: [tmpString UTF8String]
			  count: [tmpString UTF8StringLength]];

	// Add r=<nonce>
	[ret addItem: ","];

	[ret addItemsFromCArray: "r="
			  count: 2];
	[ret addItemsFromCArray: [sNonce UTF8String]
			  count: [sNonce UTF8StringLength]];

	/*
	 * IETF RFC 5802:
	 * SaltedPassword := Hi(Normalize(password), salt, i)
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addItemsFromCArray: [password UTF8String]
			       count: [password UTF8StringLength]];

	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 addItemsFromCArray: [clientFirstMessageBare UTF8String]
				  count: [clientFirstMessageBare
					     UTF8StringLength]];
	[authMessage addItem: ","];
	[authMessage addItemsFromCArray: [data cArray]
				  count: [data count] * [data itemSize]];

	[authMessage addItem: ","];
	[authMessage addItemsFromCArray: [ret cArray]
				  count: [ret count]];

	/*
	 * IETF RFC 5802:
	 * ClientKey := HMAC(SaltedPassword, "Client Key")
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addItemsFromCArray: "Client Key"
			       count: 10];
	clientKey = [self XMPP_HMACWithKey: saltedPassword
				      data: tmpArray];

	/*
	 * IETF RFC 5802:
	 * StoredKey := H(ClientKey)
	 */
	[hash updateWithBuffer: (void*) clientKey
			length: [hashType digestSize]];
	tmpArray = [OFDataArray dataArray];

	[tmpArray addItemsFromCArray: [hash digest]
			       count: [hashType digestSize]];

	/*
	 * IETF RFC 5802:
	 * ClientSignature := HMAC(StoredKey, AuthMessage)
	 */
	clientSignature = [self XMPP_HMACWithKey: tmpArray
					    data: authMessage];

	/*
	 * IETF RFC 5802:
	 * ServerKey := HMAC(SaltedPassword, "Server Key")
	 */
	tmpArray = [OFDataArray dataArray];
	[tmpArray addItemsFromCArray: "Server Key"
			       count: 10];
	serverKey = [self XMPP_HMACWithKey: saltedPassword
				      data: tmpArray];

	/*
	 * IETF RFC 5802:
	 * ServerSignature := HMAC(ServerKey, AuthMessage)
	 */
	tmpArray = [OFDataArray dataArray];

	[tmpArray addItemsFromCArray: serverKey
			       count: [hashType digestSize]];
	serverSignature = [[OFDataArray alloc] init];
	[serverSignature addItemsFromCArray: [self
						 XMPP_HMACWithKey: tmpArray
							     data: authMessage]
				      count: [hashType digestSize]];

	/*
	 * IETF RFC 5802:
	 * ClientProof := ClientKey XOR ClientSignature
	 */
	tmpArray = [OFDataArray dataArray];
	for (i = 0; i < [hashType digestSize]; i++) {
		uint8_t c = clientKey[i] ^ clientSignature[i];
		[tmpArray addItem: &c];
	}

	// Add p=<base64(ClientProof)>
	[ret addItem: ","];

	[ret addItemsFromCArray: "p="
			  count: 2];
	tmpString = [tmpArray stringByBase64Encoding];
	[ret addItemsFromCArray: [tmpString UTF8String]
			  count: [tmpString UTF8StringLength]];

	return ret;
}

- (OFDataArray*)XMPP_parseServerFinalMessage: (OFDataArray*)data
{
	OFString *mess, *value;
433
434
435
436
437
438
439
440
441

442

443
444
445
446
447
448
449
450
451
	uint8_t *kI = NULL, *kO = NULL;
	OFHash *hashI, *hashO;

	if ([key itemSize] * [key count] > blockSize) {
		hashI = [[[hashType alloc] init] autorelease];
		[hashI updateWithBuffer: [key cArray]
				length: [key itemSize] * [key count]];
		[k addNItems: [hashType digestSize]
		  fromCArray: [hashI digest]];

	} else

		[k addNItems: [key itemSize] * [key count]
		  fromCArray: [key cArray]];

	@try {
		kI = [self allocMemoryWithSize: blockSize];
		kO = [self allocMemoryWithSize: blockSize];

		kSize = [k count];
		memcpy(kI, [k cArray], kSize);







<
|
>

>
|
<







435
436
437
438
439
440
441

442
443
444
445
446

447
448
449
450
451
452
453
	uint8_t *kI = NULL, *kO = NULL;
	OFHash *hashI, *hashO;

	if ([key itemSize] * [key count] > blockSize) {
		hashI = [[[hashType alloc] init] autorelease];
		[hashI updateWithBuffer: [key cArray]
				length: [key itemSize] * [key count]];

		[k addItemsFromCArray: [hashI digest]
				count: [hashType digestSize]];
	} else
		[k addItemsFromCArray: [key cArray]
				count: [key itemSize] * [key count]];


	@try {
		kI = [self allocMemoryWithSize: blockSize];
		kO = [self allocMemoryWithSize: blockSize];

		kSize = [k count];
		memcpy(kI, [k cArray], kSize);
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535

	result = [self allocMemoryWithSize: digestSize];

	@try {
		memset(result, 0, digestSize);

		salty = [[salt_ copy] autorelease];
		[salty addNItems: 4
		      fromCArray: "\0\0\0\1"];


		uOld = [self XMPP_HMACWithKey: str
					 data: salty];

		for (j = 0; j < digestSize; j++)
			result[j] ^= uOld[j];

		for (j = 0; j < i - 1; j++) {
			tmp = [OFDataArray dataArray];
			[tmp addNItems: digestSize
			    fromCArray: uOld];


			u = [self XMPP_HMACWithKey: str
					      data: tmp];

			for (k = 0; k < digestSize; k++)
				result[k] ^= u[k];

			uOld = u;

			[pool releaseObjects];
		}

		ret = [OFDataArray dataArray];
		[ret addNItems: digestSize
		    fromCArray: result];

	} @finally {
		[self freeMemory: result];
	}

	[ret retain];
	[pool release];

	return [ret autorelease];
}
@end







<
|
>









<
|
>













<
|
>










493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537

	result = [self allocMemoryWithSize: digestSize];

	@try {
		memset(result, 0, digestSize);

		salty = [[salt_ copy] autorelease];

		[salty addItemsFromCArray: "\0\0\0\1"
				    count: 4];

		uOld = [self XMPP_HMACWithKey: str
					 data: salty];

		for (j = 0; j < digestSize; j++)
			result[j] ^= uOld[j];

		for (j = 0; j < i - 1; j++) {
			tmp = [OFDataArray dataArray];

			[tmp addItemsFromCArray: uOld
					  count: digestSize];

			u = [self XMPP_HMACWithKey: str
					      data: tmp];

			for (k = 0; k < digestSize; k++)
				result[k] ^= u[k];

			uOld = u;

			[pool releaseObjects];
		}

		ret = [OFDataArray dataArray];

		[ret addItemsFromCArray: result
				  count: digestSize];
	} @finally {
		[self freeMemory: result];
	}

	[ret retain];
	[pool release];

	return [ret autorelease];
}
@end