From 54ffeac46b6af17b0484808bd4a89ad2bd3e6cc5 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Wed, 9 Mar 2011 04:32:14 +0100 Subject: [PATCH] Add basic STARTTLS support --- src/Makefile | 2 +- src/XMPPConnection.m | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 2eaf232..3202eac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ all: objfw-compile -Wall --lib 0.0 -o objxmpp *.m \ - `pkg-config --cflags --libs libidn` + `pkg-config --cflags --libs libidn` -lobjgnutls clean: rm -f *.o *.so *.dylib *.dll diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index 5d57ebc..8f8d4ad 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -26,6 +26,8 @@ #include #include +#import + #import "XMPPConnection.h" #import "XMPPSCRAMAuth.h" #import "XMPPPLAINAuth.h" @@ -37,6 +39,7 @@ #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 @@ -271,6 +274,9 @@ { 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; @@ -292,6 +298,10 @@ if (bind != nil) [self _sendResourceBind]; + + if (starttls != nil) + [self sendStanza: [OFXMLElement elementWithName: @"starttls" + namespace: NS_STARTTLS]]; } - (void)elementBuilder: (OFXMLElementBuilder*)b @@ -307,6 +317,21 @@ 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;