Fixed SSL Pinning
- SSL Pinning switch case was not being applied if a .cer file was found in the bundle. - SSL Public Key pinning was broken because we didn't make a call to SecTrustEvaluate before SecTrustCopyPublicKey
This commit is contained in:
parent
06a9c63ead
commit
ebccca44da
1 changed files with 47 additions and 48 deletions
|
|
@ -218,7 +218,13 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
OSStatus status = SecTrustCreateWithCertificates(certificates, policy, &allowedTrust);
|
OSStatus status = SecTrustCreateWithCertificates(certificates, policy, &allowedTrust);
|
||||||
NSAssert(status == noErr, @"SecTrustCreateWithCertificates error: %ld", (long int)status);
|
NSAssert(status == noErr, @"SecTrustCreateWithCertificates error: %ld", (long int)status);
|
||||||
|
|
||||||
|
SecTrustResultType result = 0;
|
||||||
|
status = SecTrustEvaluate(allowedTrust, &result);
|
||||||
|
NSAssert(status == noErr, @"SecTrustEvaluate error: %ld", (long int)status);
|
||||||
|
|
||||||
SecKeyRef allowedPublicKey = SecTrustCopyPublicKey(allowedTrust);
|
SecKeyRef allowedPublicKey = SecTrustCopyPublicKey(allowedTrust);
|
||||||
|
|
||||||
|
NSCParameterAssert(allowedPublicKey);
|
||||||
[publicKeys addObject:(__bridge_transfer id)allowedPublicKey];
|
[publicKeys addObject:(__bridge_transfer id)allowedPublicKey];
|
||||||
|
|
||||||
CFRelease(allowedTrust);
|
CFRelease(allowedTrust);
|
||||||
|
|
@ -543,13 +549,6 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
|
||||||
{
|
{
|
||||||
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||||
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
|
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
|
||||||
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, 0);
|
|
||||||
NSData *certificateData = (__bridge_transfer NSData *)SecCertificateCopyData(certificate);
|
|
||||||
|
|
||||||
if ([[[self class] pinnedCertificates] containsObject:certificateData]) {
|
|
||||||
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
|
|
||||||
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
|
||||||
} else {
|
|
||||||
switch (self.SSLPinningMode) {
|
switch (self.SSLPinningMode) {
|
||||||
case AFSSLPinningModePublicKey: {
|
case AFSSLPinningModePublicKey: {
|
||||||
id publicKey = (__bridge_transfer id)SecTrustCopyPublicKey(serverTrust);
|
id publicKey = (__bridge_transfer id)SecTrustCopyPublicKey(serverTrust);
|
||||||
|
|
@ -595,7 +594,7 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue