case AFSSLPinningModeCertificate: {
NSMutableArray *pinnedCertificates = [NSMutableArray array];
for (NSData *certificateData in self.pinnedCertificates) {
[pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];
}
SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates);
if (!AFServerTrustIsValid(serverTrust)) {
return NO;
}
if (!self.validatesCertificateChain) {
return YES;
}
NSUInteger trustedCertificateCount = 0;
for (NSData *trustChainCertificate in serverCertificates) {
if ([self.pinnedCertificates containsObject:trustChainCertificate]) {
trustedCertificateCount++;
}
}
return trustedCertificateCount == [serverCertificates count];
}
在AFSecurityPolicy.m 中,SecCertificateCreateWithData 返回空值((__bridge CFDataRef)certificateData 可以拿到NSBundle存放的.cer证书),导致程序崩溃.
是因为证书出了问题吗?
http://www.cocoachina.com/bbs...
Same request, has no one else encountered this?
I just encountered this problem today and solved it. The reason for returning empty is because the server gives you a base64-encrypted certificate for iOS. The client needs to decrypt the certificate into plain text. For the specific method, please see the link http://www.jianshu.com/p/ 7446...