diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index aba6002..523f5e6 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -128,9 +128,11 @@ NSCoding, NSCopying> @property (readonly, nonatomic, strong) NSError *error; /** - The flag to determine if the connection should accept an invalid SSL certificate. If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is set, this property defaults to YES for backwards compatibility support. Otherwise, this property defaults to NO. + Whether the connection should accept an invalid SSL certificate. + + If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is set, this property defaults to `YES` for backwards compatibility. Otherwise, this property defaults to `NO`. */ -@property (nonatomic,assign) BOOL allowInvalidSSLCertificate; +@property (nonatomic, assign) BOOL allowInvalidSSLCertificate; ///---------------------------- /// @name Getting Response Data diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 82ca163..395cd1a 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -257,8 +257,8 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat self.outputStream = [NSOutputStream outputStreamToMemory]; self.state = AFOperationReadyState; - - //This ifdef has been added for backwards compatibility purposes + + // #ifdef included for backwards-compatibility #ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ self.allowInvalidSSLCertificate = YES; #endif @@ -611,11 +611,10 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe break; } case AFSSLPinningModeNone: { - if(self.allowInvalidSSLCertificate == YES){ + if (self.allowInvalidSSLCertificate){ NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; - } - else { + } else { SecTrustResultType result = 0; OSStatus status = SecTrustEvaluate(serverTrust, &result); NSAssert(status == errSecSuccess, @"SecTrustEvaluate error: %ld", (long int)status); @@ -656,13 +655,12 @@ canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { - if(self.allowInvalidSSLCertificate == YES + if (self.allowInvalidSSLCertificate && [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; return; } - if (self.authenticationChallenge) { self.authenticationChallenge(connection, challenge); } else {