ObjXMPP  Check-in [3a3855f187]

Overview
Comment:Add basic STARTTLS support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3a3855f187247db3a7199899b6dba4e46e6439b9493a00ab7da79ab97d7a3366
User & Date: florob@babelmonkeys.de on 2011-03-09 03:32:14
Other Links: manifest | tags
Context
2011-03-10
21:14
Stop caching authentication mechanisms check-in: 991c7aeff2 user: florob@babelmonkeys.de tags: trunk
2011-03-09
03:32
Add basic STARTTLS support check-in: 3a3855f187 user: florob@babelmonkeys.de tags: trunk
2011-02-26
14:13
Clean up exceptions. check-in: 5df36353c6 user: js tags: trunk
Changes

Modified src/Makefile from [aed6ade7ee] to [61a2f5a5b5].

1
2
3
4
5
6
all:
	objfw-compile -Wall --lib 0.0 -o objxmpp *.m \
		`pkg-config --cflags --libs libidn`

clean:
	rm -f *.o *.so *.dylib *.dll


|



1
2
3
4
5
6
all:
	objfw-compile -Wall --lib 0.0 -o objxmpp *.m \
		`pkg-config --cflags --libs libidn` -lobjgnutls

clean:
	rm -f *.o *.so *.dylib *.dll

Modified src/XMPPConnection.m from [134b7975a7] to [365d927559].

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

#include <assert.h>

#include <stringprep.h>
#include <idna.h>



#import "XMPPConnection.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h"
#import "XMPPExceptions.h"

#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define NS_CLIENT @"jabber:client"
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"

#define NS_STREAM @"http://etherx.jabber.org/streams"

@implementation XMPPConnection
@synthesize username, password, server, resource, JID, port, useTLS, delegate;

- init
{







>
>











>







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
49
 */

#include <assert.h>

#include <stringprep.h>
#include <idna.h>

#import <ObjGnuTLS/ObjGnuTLS.h>

#import "XMPPConnection.h"
#import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h"
#import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h"
#import "XMPPExceptions.h"

#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define NS_CLIENT @"jabber:client"
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define NS_STREAM @"http://etherx.jabber.org/streams"

@implementation XMPPConnection
@synthesize username, password, server, resource, JID, port, useTLS, delegate;

- init
{
267
268
269
270
271
272
273



274
275
276
277
278
279
280
	}
}

- (void)_handleFeatures: (OFXMLElement*)elem
{
	OFArray *mechs = [elem elementsForName: @"mechanisms"
				     namespace: NS_SASL];



	OFXMLElement *bind = [elem elementsForName: @"bind"
					 namespace: NS_BIND].firstObject;

	for (OFXMLElement *mech in [mechs.firstObject children])
		[mechanisms addObject: [mech.children.firstObject stringValue]];

	if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {







>
>
>







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
	}
}

- (void)_handleFeatures: (OFXMLElement*)elem
{
	OFArray *mechs = [elem elementsForName: @"mechanisms"
				     namespace: NS_SASL];
	OFXMLElement *starttls = [elem
	    elementsForName: @"starttls"
		  namespace: NS_STARTTLS].firstObject;
	OFXMLElement *bind = [elem elementsForName: @"bind"
					 namespace: NS_BIND].firstObject;

	for (OFXMLElement *mech in [mechs.firstObject children])
		[mechanisms addObject: [mech.children.firstObject stringValue]];

	if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
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
		    initWithAuthcid: username
			   password: password];
		[self _sendAuth: @"PLAIN"];
	}

	if (bind != nil)
		[self _sendResourceBind];




}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	elem.defaultNamespace = NS_CLIENT;
	[elem setPrefix: @"stream"
	   forNamespace: NS_STREAM];

	if ([elem.name isEqual: @"features"] &&
	    [elem.namespace isEqual: NS_STREAM]) {
		[self _handleFeatures: elem];
		return;
	}
















	if ([elem.namespace isEqual: NS_SASL]) {
		if ([elem.name isEqual: @"challenge"]) {
			OFXMLElement *responseTag;
			OFDataArray *challenge =
			    [OFDataArray dataArrayWithBase64EncodedString:
				[elem.children.firstObject stringValue]];







>
>
>
>














>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
		    initWithAuthcid: username
			   password: password];
		[self _sendAuth: @"PLAIN"];
	}

	if (bind != nil)
		[self _sendResourceBind];

	if (starttls != nil)
		[self sendStanza: [OFXMLElement elementWithName: @"starttls"
						      namespace: NS_STARTTLS]];
}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	elem.defaultNamespace = NS_CLIENT;
	[elem setPrefix: @"stream"
	   forNamespace: NS_STREAM];

	if ([elem.name isEqual: @"features"] &&
	    [elem.namespace isEqual: NS_STREAM]) {
		[self _handleFeatures: elem];
		return;
	}

	if ([elem.namespace isEqual: NS_STARTTLS]) {
		if ([elem.name isEqual: @"proceed"]) {
			/* FIXME: Catch errors here */
			sock = [[GTLSSocket alloc] initWithSocket: sock];

			/* Stream restart */
			[mechanisms release];
			mechanisms = [[OFMutableArray alloc] init];
			parser.delegate = self;
			[self _startStream];
		} else if ([elem.name isEqual: @"failure"])
			/* TODO: Find/create an exception to throw here */
			@throw [OFException newWithClass: isa];
	}

	if ([elem.namespace isEqual: NS_SASL]) {
		if ([elem.name isEqual: @"challenge"]) {
			OFXMLElement *responseTag;
			OFDataArray *challenge =
			    [OFDataArray dataArrayWithBase64EncodedString:
				[elem.children.firstObject stringValue]];