Skip to content

Commit

Permalink
Removed ambiguous array creation. According to documentation SecTrust…
Browse files Browse the repository at this point in the history
…CreateWithCertificates takes SecCertificateRef object or an array of certificates.
  • Loading branch information
sgl0v authored and kcharwood committed Oct 11, 2016
1 parent 719a3bf commit 9fea224
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions AFNetworking/AFSecurityPolicy.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
static id AFPublicKeyForCertificate(NSData *certificate) {
id allowedPublicKey = nil;
SecCertificateRef allowedCertificate;
SecCertificateRef allowedCertificates[1];
CFArrayRef tempCertificates = nil;
SecPolicyRef policy = nil;
SecTrustRef allowedTrust = nil;
SecTrustResultType result;

allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificate);
__Require_Quiet(allowedCertificate != NULL, _out);

allowedCertificates[0] = allowedCertificate;
tempCertificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);

policy = SecPolicyCreateBasicX509();
__Require_noErr_Quiet(SecTrustCreateWithCertificates(tempCertificates, policy, &allowedTrust), _out);
__Require_noErr_Quiet(SecTrustCreateWithCertificates(allowedCertificate, policy, &allowedTrust), _out);
__Require_noErr_Quiet(SecTrustEvaluate(allowedTrust, &result), _out);

allowedPublicKey = (__bridge_transfer id)SecTrustCopyPublicKey(allowedTrust);
Expand All @@ -78,10 +73,6 @@ static id AFPublicKeyForCertificate(NSData *certificate) {
CFRelease(policy);
}

if (tempCertificates) {
CFRelease(tempCertificates);
}

if (allowedCertificate) {
CFRelease(allowedCertificate);
}
Expand Down

0 comments on commit 9fea224

Please sign in to comment.