Implement SASL EXTERNAL

This commit is contained in:
Florian Zeitz 2012-01-25 16:42:29 +01:00
parent 71b02af421
commit ee08eadf81
3 changed files with 36 additions and 1 deletions

View file

@ -9,6 +9,7 @@ SRCS = XMPPAuthenticator.m \
XMPPCallback.m \ XMPPCallback.m \
XMPPConnection.m \ XMPPConnection.m \
XMPPExceptions.m \ XMPPExceptions.m \
XMPPEXTERNALAuth.m \
XMPPIQ.m \ XMPPIQ.m \
XMPPJID.m \ XMPPJID.m \
XMPPMessage.m \ XMPPMessage.m \

View file

@ -73,6 +73,7 @@
OFXMLParser *parser, *oldParser; OFXMLParser *parser, *oldParser;
OFXMLElementBuilder *elementBuilder, *oldElementBuilder; OFXMLElementBuilder *elementBuilder, *oldElementBuilder;
OFString *username, *password, *server, *resource; OFString *username, *password, *server, *resource;
OFString *privateKeyFile, *certificateFile;
OFString *domain, *domainToASCII; OFString *domain, *domainToASCII;
XMPPJID *JID; XMPPJID *JID;
uint16_t port; uint16_t port;
@ -88,6 +89,7 @@
#ifdef OF_HAVE_PROPERTIES #ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *username, *password, *server, *domain, *resource; @property (copy) OFString *username, *password, *server, *domain, *resource;
@property (copy) OFString *privateKeyFile, *certificateFile;
@property (copy, readonly) XMPPJID *JID; @property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port; @property (assign) uint16_t port;
@property (assign) id <XMPPConnectionDelegate> delegate; @property (assign) id <XMPPConnectionDelegate> delegate;

View file

@ -39,6 +39,7 @@
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPCallback.h" #import "XMPPCallback.h"
#import "XMPPSRVLookup.h" #import "XMPPSRVLookup.h"
#import "XMPPEXTERNALAuth.h"
#import "XMPPSCRAMAuth.h" #import "XMPPSCRAMAuth.h"
#import "XMPPPLAINAuth.h" #import "XMPPPLAINAuth.h"
#import "XMPPStanza.h" #import "XMPPStanza.h"
@ -82,6 +83,8 @@
[elementBuilder release]; [elementBuilder release];
[username release]; [username release];
[password release]; [password release];
[privateKeyFile release];
[certificateFile release];
[server release]; [server release];
[domain release]; [domain release];
[resource release]; [resource release];
@ -220,6 +223,26 @@
return [[password copy] autorelease]; return [[password copy] autorelease];
} }
- (void)setPrivateKeyFile: (OFString*)file
{
OF_SETTER(privateKeyFile, file, YES, YES)
}
- (OFString*)privateKeyFile
{
OF_GETTER(privateKeyFile, YES)
}
- (void)setCertificateFile: (OFString*)file
{
OF_SETTER(certificateFile, file, YES, YES)
}
- (OFString*)certificateFile
{
OF_GETTER(certificateFile, YES)
}
- (void)connect - (void)connect
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
@ -673,7 +696,9 @@ withCallbackBlock: (xmpp_callback_block)callback;
@selector(connectionWillUpgradeToTLS:)]) @selector(connectionWillUpgradeToTLS:)])
[delegate connectionWillUpgradeToTLS: self]; [delegate connectionWillUpgradeToTLS: self];
newSock = [[SSLSocket alloc] initWithSocket: sock]; newSock = [[SSLSocket alloc] initWithSocket: sock
privateKeyFile: privateKeyFile
certificateFile: certificateFile];
[sock release]; [sock release];
sock = newSock; sock = newSock;
@ -819,6 +844,13 @@ withCallbackBlock: (xmpp_callback_block)callback;
while ((mech = [enumerator nextObject]) != nil) while ((mech = [enumerator nextObject]) != nil)
[mechanisms addObject: [mech stringValue]]; [mechanisms addObject: [mech stringValue]];
if (privateKeyFile && certificateFile &&
[mechanisms containsObject: @"EXTERNAL"]) {
authModule = [[XMPPEXTERNALAuth alloc] init];
[self XMPP_sendAuth: @"EXTERNAL"];
return;
}
if ([mechanisms containsObject: @"SCRAM-SHA-1-PLUS"]) { if ([mechanisms containsObject: @"SCRAM-SHA-1-PLUS"]) {
authModule = [[XMPPSCRAMAuth alloc] authModule = [[XMPPSCRAMAuth alloc]
initWithAuthcid: username initWithAuthcid: username