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证书),导致程序崩溃.
是因为证书出了问题吗?
黄舟2017-04-17 17:55:05
正好今天也遇到这个问题 解决了 返回空 是因为 服务端给你的是经过base64加密的证书 iOS 客户端需要 解密成明文的证书 具体方法 看链接 http://www.jianshu.com/p/7446...