Restore space-based indentation

This commit is contained in:
Justin Spahr-Summers 2014-10-06 13:26:28 -07:00
Родитель 5291311e1e
Коммит c0e505c0b5
1 изменённых файлов: 87 добавлений и 87 удалений

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

@ -580,97 +580,97 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
} }
if (![challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { if (![challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if ([challenge previousFailureCount] == 0 && self.credential != nil) { if ([challenge previousFailureCount] == 0 && self.credential != nil) {
[[challenge sender] useCredential:self.credential forAuthenticationChallenge:challenge]; [[challenge sender] useCredential:self.credential forAuthenticationChallenge:challenge];
} }
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
return; return;
} }
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust; SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
SecPolicyRef policy = SecPolicyCreateBasicX509(); SecPolicyRef policy = SecPolicyCreateBasicX509();
CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust); CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:certificateCount]; NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:certificateCount];
for (CFIndex i = 0; i < certificateCount; i++) { for (CFIndex i = 0; i < certificateCount; i++) {
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i); SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);
if (self.SSLPinningMode == AFSSLPinningModeCertificate) { if (self.SSLPinningMode == AFSSLPinningModeCertificate) {
[trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)]; [trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];
} else if (self.SSLPinningMode == AFSSLPinningModePublicKey) { } else if (self.SSLPinningMode == AFSSLPinningModePublicKey) {
SecCertificateRef someCertificates[] = {certificate}; SecCertificateRef someCertificates[] = {certificate};
CFArrayRef certificates = CFArrayCreate(NULL, (const void **)someCertificates, 1, NULL); CFArrayRef certificates = CFArrayCreate(NULL, (const void **)someCertificates, 1, NULL);
SecTrustRef trust = NULL; SecTrustRef trust = NULL;
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) { 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) { if (status == errSecSuccess) {
[trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)]; [trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
} }
CFRelease(trust); CFRelease(trust);
} }
CFRelease(certificates); CFRelease(certificates);
} }
} }
CFRelease(policy); CFRelease(policy);
switch (self.SSLPinningMode) { switch (self.SSLPinningMode) {
case AFSSLPinningModePublicKey: { case AFSSLPinningModePublicKey: {
NSArray *pinnedPublicKeys = [self.class pinnedPublicKeys]; NSArray *pinnedPublicKeys = [self.class pinnedPublicKeys];
for (id publicKey in trustChain) { for (id publicKey in trustChain) {
for (id pinnedPublicKey in pinnedPublicKeys) { for (id pinnedPublicKey in pinnedPublicKeys) {
if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)publicKey, (__bridge SecKeyRef)pinnedPublicKey)) { if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)publicKey, (__bridge SecKeyRef)pinnedPublicKey)) {
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
return; return;
} }
} }
} }
[[challenge sender] cancelAuthenticationChallenge:challenge]; [[challenge sender] cancelAuthenticationChallenge:challenge];
break; break;
} }
case AFSSLPinningModeCertificate: { case AFSSLPinningModeCertificate: {
for (id serverCertificateData in trustChain) { for (id serverCertificateData in trustChain) {
if ([[self.class pinnedCertificates] containsObject:serverCertificateData]) { if ([[self.class pinnedCertificates] containsObject:serverCertificateData]) {
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
return; return;
} }
} }
[[challenge sender] cancelAuthenticationChallenge:challenge]; [[challenge sender] cancelAuthenticationChallenge:challenge];
break; break;
} }
case AFSSLPinningModeNone: { case AFSSLPinningModeNone: {
SecTrustResultType result = 0; SecTrustResultType result = 0;
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 (self.allowsInvalidSSLCertificate || (status == errSecSuccess && (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed))) { if (self.allowsInvalidSSLCertificate || (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];
return; return;
} }
if ([[challenge sender] respondsToSelector:@selector(performDefaultHandlingForAuthenticationChallenge:)]) { if ([[challenge sender] respondsToSelector:@selector(performDefaultHandlingForAuthenticationChallenge:)]) {
[[challenge sender] performDefaultHandlingForAuthenticationChallenge:challenge]; [[challenge sender] performDefaultHandlingForAuthenticationChallenge:challenge];
} else { } else {
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
} }
} }
} }
} }
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection __unused *)connection { - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection __unused *)connection {