Added return status checks when handling connection's authentication challenge

This commit is contained in:
Sylvain Guillope 2013-06-28 00:31:37 -04:00
Родитель 02abb706d3
Коммит b60848af94
1 изменённых файлов: 15 добавлений и 13 удалений

Просмотреть файл

@ -187,13 +187,13 @@ static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
@synthesize lock = _lock; @synthesize lock = _lock;
+ (void)networkRequestThreadEntryPoint:(id)__unused object { + (void)networkRequestThreadEntryPoint:(id)__unused object {
@autoreleasepool { @autoreleasepool {
[[NSThread currentThread] setName:@"AFNetworking"]; [[NSThread currentThread] setName:@"AFNetworking"];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];
[runLoop run]; [runLoop run];
} }
} }
+ (NSThread *)networkRequestThread { + (NSThread *)networkRequestThread {
@ -627,15 +627,17 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
OSStatus status = SecTrustCreateWithCertificates(certificates, policy, &trust); OSStatus status = SecTrustCreateWithCertificates(certificates, policy, &trust);
NSAssert(status == errSecSuccess, @"SecTrustCreateWithCertificates error: %ld", (long int)status); NSAssert(status == errSecSuccess, @"SecTrustCreateWithCertificates error: %ld", (long int)status);
if (status == errSecSuccess && trust) {
SecTrustResultType result; SecTrustResultType result;
status = SecTrustEvaluate(trust, &result); status = SecTrustEvaluate(trust, &result);
NSAssert(status == errSecSuccess, @"SecTrustEvaluate error: %ld", (long int)status); NSAssert(status == errSecSuccess, @"SecTrustEvaluate error: %ld", (long int)status);
if (status == errSecSuccess) {
[trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)]; [trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
}
CFRelease(trust); }
CFRelease(certificates);
if (trust) CFRelease(trust);
if (certificates) CFRelease(certificates);
} }
} }
@ -679,7 +681,7 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
OSStatus status = SecTrustEvaluate(serverTrust, &result); OSStatus status = SecTrustEvaluate(serverTrust, &result);
NSAssert(status == errSecSuccess, @"SecTrustEvaluate error: %ld", (long int)status); NSAssert(status == errSecSuccess, @"SecTrustEvaluate error: %ld", (long int)status);
if (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed) { if (status == errSecSuccess && (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed)) {
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
} else { } else {