ObjXMPP  Check-in [58085da5c5]

Overview
Comment:Style improvements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 58085da5c55c67c39daf638f9a17dd76a98f0d5c376b32cc2fb56b7f59207de7
User & Date: js on 2012-01-26 12:35:05
Other Links: manifest | tags
Context
2012-01-26
22:22
Add missing headers to Xcode project. check-in: 93de763475 user: js tags: trunk
12:35
Style improvements. check-in: 58085da5c5 user: js tags: trunk
12:34
Update Xcode project and reexport ObjOpenSSL. check-in: 42adbaeaf5 user: js tags: trunk
Changes

Modified src/XMPPCallback.h from [d3b2ead060] to [e7183d6d5f].

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35

36
37
38


39

40
41
42
43
44
45
46
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37


38
39
40
41
42
43
44
45
46
47
48







-
+







+

-
-
+
+

+







 */

#import <ObjFW/ObjFW.h>

@class XMPPIQ;

#ifdef OF_HAVE_BLOCKS
typedef void(^xmpp_callback_block)(XMPPIQ*);
typedef void(^xmpp_callback_block_t)(XMPPIQ*);
#endif

@interface XMPPCallback: OFObject
{
	id object;
	SEL selector;
}

#ifdef OF_HAVE_BLOCKS
+ callbackWithCallbackBlock: (xmpp_callback_block)callback;
- initWithCallbackBlock: (xmpp_callback_block)callback;
+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback;
- initWithCallbackBlock: (xmpp_callback_block_t)callback;
#endif

+ callbackWithCallbackObject: (id)object
		    selector: (SEL)selector;
- initWithCallbackObject: (id)object
		selector: (SEL)selector;

- (void)runWithIQ: (XMPPIQ*)iq;
@end

Modified src/XMPPCallback.m from [00c028907e] to [d293755462].

24
25
26
27
28
29
30
31

32
33
34
35
36

37
38
39
40
41
42
43
24
25
26
27
28
29
30

31
32
33
34
35

36
37
38
39
40
41
42
43







-
+




-
+







# include "config.h"
#endif

#import "XMPPCallback.h"

@implementation XMPPCallback
#ifdef OF_HAVE_BLOCKS
+ callbackWithCallbackBlock: (xmpp_callback_block)callback
+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback
{
	return [[[self alloc] initWithCallbackBlock: callback] autorelease];
}

- initWithCallbackBlock: (xmpp_callback_block)callback
- initWithCallbackBlock: (xmpp_callback_block_t)callback
{
	self = [super init];

	object = [callback copy];

	return self;
}
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
51
52
53
54
55
56
57


58
59
60
61
62
63
64
65


66
67
68
69
70
71
72

73
74
75
76
77
78
79







-
-
+







-
-







-
+






}

- initWithCallbackObject: (id)object_
		selector: (SEL)selector_
{
	self = [super init];

	// TODO: Retain or follow delegate paradigm?
	object = [object_ retain];
	object = object_;
	selector = selector_;

	return self;
}

- (void)dealloc
{
	[object release];

	[super dealloc];
}

- (void)runWithIQ: (XMPPIQ*)iq
{
#ifdef OF_HAVE_BLOCKS
	if ([object isKindOfClass: [OFBlock class]])
		((xmpp_callback_block)object)(iq);
		((xmpp_callback_block_t)object)(iq);
	else
#endif
		[object performSelector: selector
			     withObject: iq];
}
@end

Modified src/XMPPConnection.m from [93e7490cdd] to [677aa509d2].

379
380
381
382
383
384
385
386
387
388



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408


409
410
411
412
413
414
415
379
380
381
382
383
384
385



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406


407
408
409
410
411
412
413
414
415







-
-
-
+
+
+


















-
-
+
+







	    @selector(connection:didSendElement:)])
		[delegate connection: self
		      didSendElement: element];

	[sock writeString: [element XMLString]];
}

-     (void)sendIQ: (XMPPIQ*)iq
withCallbackObject: (id)object
	  selector: (SEL)selector
-	(void)sendIQ: (XMPPIQ*)iq
  withCallbackObject: (id)object
	    selector: (SEL)selector
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	@try {
		if (![iq ID])
			[iq setID: [self generateStanzaID]];

		[callbacks setObject: [XMPPCallback
					 callbackWithCallbackObject: object
							   selector: selector]
			      forKey: [iq ID]];
	} @finally {
		[pool release];
	}

	[self sendStanza: iq];
}

#ifdef OF_HAVE_BLOCKS
-    (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (xmpp_callback_block)callback;
-      (void)sendIQ: (XMPPIQ*)iq
  withCallbackBlock: (xmpp_callback_block_t)callback;
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	@try {
		if (![iq ID])
			[iq setID: [self generateStanzaID]];

		[callbacks setObject: [XMPPCallback
929
930
931
932
933
934
935
936
937
938



939
940
941
942
943
944
945
929
930
931
932
933
934
935



936
937
938
939
940
941
942
943
944
945







-
-
-
+
+
+







	if (resource != nil)
		[bind addChild: [OFXMLElement elementWithName: @"resource"
						    namespace: XMPP_NS_BIND
						  stringValue: resource]];

	[iq addChild: bind];

	[self sendIQ: iq
  withCallbackObject: self
	    selector: @selector(XMPP_handleResourceBind:)];
	[self		sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleResourceBind:)];
}

- (void)XMPP_sendStreamError: (OFString*)condition
			text: (OFString*)text
{
	OFXMLElement *error = [OFXMLElement
	    elementWithName: @"error"
988
989
990
991
992
993
994
995
996
997



998
999
1000
1001
1002
1003
1004
988
989
990
991
992
993
994



995
996
997
998
999
1000
1001
1002
1003
1004







-
-
-
+
+
+







{
	XMPPIQ *iq;

	iq = [XMPPIQ IQWithType: @"set"
			     ID: [self generateStanzaID]];
	[iq addChild: [OFXMLElement elementWithName: @"session"
					  namespace: XMPP_NS_SESSION]];
	[self sendIQ: iq
  withCallbackObject: self
	    selector: @selector(XMPP_handleSession:)];
	[self		sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleSession:)];
}

- (void)XMPP_handleSession: (XMPPIQ*)iq
{
	if (![[iq type] isEqual: @"result"])
		assert(0);

Modified src/XMPPEXTERNALAuth.m from [aad38dee82] to [b61498fa1a].

38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+







	return [[[self alloc] initWithAuthzid: authzid_
				      authcid: nil
				     password: nil] autorelease];
}

- (OFDataArray*)initialMessage
{
	OFDataArray *message = [OFDataArray dataArrayWithItemSize: 1];
	OFDataArray *message = [OFDataArray dataArray];

	/* authzid */
	if (authzid)
		[message addItem: authzid];

	return message;
}

Modified src/XMPPPLAINAuth.m from [3b4c3d710b] to [755e5fff17].

42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56







-
+







	return [[[self alloc] initWithAuthzid: authzid
				      authcid: authcid
				     password: password] autorelease];
}

- (OFDataArray*)initialMessage
{
	OFDataArray *message = [OFDataArray dataArrayWithItemSize: 1];
	OFDataArray *message = [OFDataArray dataArray];

	/* authzid */
	if (authzid)
		[message addItem: authzid];

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

Modified src/XMPPPresence.m from [9d5fdb884e] to [929fa57282].

77
78
79
80
81
82
83


84
85
86
87
88
89
90
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92







+
+







				ID: ID_];
}

- (OFString*)type
{
	if (type == nil)
		return @"available";

	return type;
}

- (void)addShow: (OFString*)show
{
	[self addChild: [OFXMLElement elementWithName: @"show"
					    namespace: XMPP_NS_CLIENT
					  stringValue: show]];

Modified src/XMPPSCRAMAuth.m from [50454e1c4a] to [8bb70cd016].

141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155







-
+







		authcid = nil;

	[old release];
}

- (OFDataArray*)initialMessage
{
	OFDataArray *ret = [OFDataArray dataArrayWithItemSize: 1];
	OFDataArray *ret = [OFDataArray dataArray];

	/* New authentication attempt, reset status */
	[cNonce release];
	cNonce = nil;
	[GS2Header release];
	GS2Header = nil;
	[serverSignature release];
211
212
213
214
215
216
217
218
219


220
221
222
223
224
225
226
211
212
213
214
215
216
217


218
219
220
221
222
223
224
225
226







-
-
+
+







	enum {
		GOT_SNONCE    = 0x01,
		GOT_SALT      = 0x02,
		GOT_ITERCOUNT = 0x04
	} got = 0;

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

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

	enumerator =
	    [[chal componentsSeparatedByString: @","] objectEnumerator];
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262







-
+







		}
	}

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

	// Add c=<base64(GS2Header+channelBindingData)>
	tmpArray = [OFDataArray dataArrayWithItemSize: 1];
	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]];
274
275
276
277
278
279
280
281

282
283
284
285
286
287
288
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288







-
+







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

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

	saltedPassword = [self XMPP_hiWithData: tmpArray
					  salt: salt
				iterationCount: iterCount];

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
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







-
+











-
+














-
+









-
+


-
+








-
+







	[authMessage addNItems: [ret count]
		    fromCArray: [ret cArray]];

	/*
	 * IETF RFC 5802:
	 * ClientKey := HMAC(SaltedPassword, "Client Key")
	 */
	tmpArray = [OFDataArray dataArrayWithItemSize: 1];
	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 dataArrayWithItemSize: 1];
	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 dataArrayWithItemSize: 1];
	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 dataArrayWithItemSize: 1];
	tmpArray = [OFDataArray dataArray];
	[tmpArray addNItems: [hashType digestSize]
		 fromCArray: serverKey];
	serverSignature = [[OFDataArray alloc] initWithItemSize: 1];
	serverSignature = [[OFDataArray alloc] init];
	[serverSignature addNItems: [hashType digestSize]
			fromCArray: [self XMPP_HMACWithKey: tmpArray
						      data: authMessage]];

	/*
	 * IETF RFC 5802:
	 * ClientProof := ClientKey XOR ClientSignature
	 */
	tmpArray = [OFDataArray dataArrayWithItemSize: 1];
	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: ","];
424
425
426
427
428
429
430
431

432
433
434
435
436
437
438
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438







-
+







				    length: 64];
}

- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key
			data: (OFDataArray*)data
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDataArray *k = [OFDataArray dataArrayWithItemSize: 1];
	OFDataArray *k = [OFDataArray dataArray];
	size_t i, kSize, blockSize = [hashType blockSize];
	uint8_t *kI = NULL, *kO = NULL;
	OFHash *hashI, *hashO;

	if ([key itemSize] * [key count] > blockSize) {
		hashI = [[[hashType alloc] init] autorelease];
		[hashI updateWithBuffer: [key cArray]
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
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







-
+














-
+












		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 dataArrayWithItemSize: 1];
			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 dataArrayWithItemSize: 1];
		ret = [OFDataArray dataArray];
		[ret addNItems: digestSize
		    fromCArray: result];
	} @finally {
		[self freeMemory: result];
	}

	[ret retain];
	[pool release];

	return [ret autorelease];
}
@end