search

Home  >  Q&A  >  body text

ios - AFNetWorking Https SecCertificateCreateWithData 返回nil

        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证书),导致程序崩溃.
是因为证书出了问题吗?

伊谢尔伦伊谢尔伦2772 days ago632

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:55:05

    http://www.cocoachina.com/bbs...

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:55:05

    Same request, has no one else encountered this?

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:55:05

    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...

    reply
    0
  • Cancelreply