Permalink
Browse files

Improving debug logging for digest-md5 auth

  • Loading branch information...
1 parent 28fa10f commit efdca3ea97da440ee92323c21e2718d729ce231f @robbiehanson committed May 2, 2012
Showing with 37 additions and 2 deletions.
  1. +37 −2 Authentication/Digest-MD5/XMPPDigestMD5Authentication.m
View
39 Authentication/Digest-MD5/XMPPDigestMD5Authentication.m
@@ -35,6 +35,16 @@ @interface XMPPDigestMD5Authentication ()
NSString *password;
}
+// The properties are hooks (primarily for testing)
+
+@property (nonatomic, strong) NSString *realm;
+@property (nonatomic, strong) NSString *nonce;
+@property (nonatomic, strong) NSString *qop;
+@property (nonatomic, strong) NSString *cnonce;
+@property (nonatomic, strong) NSString *digestURI;
+@property (nonatomic, strong) NSString *username;
+@property (nonatomic, strong) NSString *password;
+
- (NSDictionary *)dictionaryFromChallenge:(NSXMLElement *)challenge;
- (NSString *)base64EncodedFullResponse;
@@ -51,6 +61,14 @@ + (NSString *)mechanismName
return @"DIGEST-MD5";
}
+@synthesize realm;
+@synthesize nonce;
+@synthesize qop;
+@synthesize cnonce;
+@synthesize digestURI;
+@synthesize username;
+@synthesize password;
+
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)inPassword
{
if ((self = [super init]))
@@ -119,7 +137,9 @@ - (XMPPHandleAuthResponse)handleAuth1:(NSXMLElement *)authResponse
else
digestURI = [NSString stringWithFormat:@"xmpp/%@", serverHostName];
- cnonce = [XMPPStream generateUUID];
+ if (cnonce == nil)
+ cnonce = [XMPPStream generateUUID];
+
username = [myJID user];
// Create and send challenge response element
@@ -234,22 +254,37 @@ - (NSString *)response
NSString *HA1str = [NSString stringWithFormat:@"%@:%@:%@", username, realm, password];
NSString *HA2str = [NSString stringWithFormat:@"AUTHENTICATE:%@", digestURI];
+ XMPPLogVerbose(@"HA1str: %@", HA1str);
+ XMPPLogVerbose(@"HA2str: %@", HA2str);
+
NSData *HA1dataA = [[HA1str dataUsingEncoding:NSUTF8StringEncoding] md5Digest];
NSData *HA1dataB = [[NSString stringWithFormat:@":%@:%@", nonce, cnonce] dataUsingEncoding:NSUTF8StringEncoding];
+ XMPPLogVerbose(@"HA1dataA: %@", HA1dataA);
+ XMPPLogVerbose(@"HA1dataB: %@", HA1dataB);
+
NSMutableData *HA1data = [NSMutableData dataWithCapacity:([HA1dataA length] + [HA1dataB length])];
[HA1data appendData:HA1dataA];
[HA1data appendData:HA1dataB];
+ XMPPLogVerbose(@"HA1data: %@", HA1data);
+
NSString *HA1 = [[HA1data md5Digest] hexStringValue];
NSString *HA2 = [[[HA2str dataUsingEncoding:NSUTF8StringEncoding] md5Digest] hexStringValue];
+ XMPPLogVerbose(@"HA1: %@", HA1);
+ XMPPLogVerbose(@"HA2: %@", HA2);
+
NSString *responseStr = [NSString stringWithFormat:@"%@:%@:00000001:%@:auth:%@",
HA1, nonce, cnonce, HA2];
+ XMPPLogVerbose(@"responseStr: %@", responseStr);
+
NSString *response = [[[responseStr dataUsingEncoding:NSUTF8StringEncoding] md5Digest] hexStringValue];
+ XMPPLogVerbose(@"response: %@", response);
+
return response;
}
@@ -266,7 +301,7 @@ - (NSString *)base64EncodedFullResponse
[buffer appendFormat:@"response=%@,", [self response]];
[buffer appendFormat:@"charset=utf-8"];
- XMPPLogSend(@"decoded response: %@", buffer);
+ XMPPLogVerbose(@"%@: Decoded response: %@", THIS_FILE, buffer);
NSData *utf8data = [buffer dataUsingEncoding:NSUTF8StringEncoding];

0 comments on commit efdca3e

Please sign in to comment.