From 35a7b29286e4498b112c9dab81a185e0645f5f10 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 13 Mar 2012 09:02:42 -0700 Subject: [PATCH] [Issue #246] Making AFURLConnectionOperation behavior consistent for _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ in -connection:didReceiveAuthenticationChallenge: --- AFNetworking/AFURLConnectionOperation.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 013e871..172595a 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -381,6 +381,7 @@ canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace return YES; } #endif + if (self.authenticationAgainstProtectionSpace) { return self.authenticationAgainstProtectionSpace(connection, protectionSpace); } else if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] || [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) { @@ -393,15 +394,16 @@ canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { +#ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + return; + } +#endif + if (self.authenticationChallenge) { self.authenticationChallenge(connection, challenge); } else { -#ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ - if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { - [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; - return; - } -#endif if ([challenge previousFailureCount] == 0) { NSURLCredential *credential = nil;