简体   繁体   English

使用AFNetworking 2.3.1的自签名SSL证书

[英]self-signed SSL certificate using AFNetworking 2.3.1

I'm trying to use a self-signed certificate .cer in my iOS app. 我正在尝试在我的iOS应用程序中使用自签名证书.cer I followed this nice tutorial : http://initwithfunk.com/blog/2014/03/12/afnetworking-ssl-pinning-with-self-signed-certificates/ 我遵循了这个不错的教程: http : //initwithfunk.com/blog/2014/03/12/afnetworking-ssl-pinning-with-self-signed-certificates/

I added my .cer file tu the project. 我在项目中添加了.cer文件。 And init my AFHTTPRequestOperationManager : 然后初始化我的AFHTTPRequestOperationManager:

self.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
self.securityPolicy.allowInvalidCertificates = YES;

But I always get this -1012 error : 但是我总是会收到-1012错误:

Error The operation couldn't be completed. 错误操作无法完成。 (NSURLErrorDomain error -1012.) (NSURLErrorDomain错误-1012。)

I checked the + (NSArray *)defaultPinnedCertificates its correctly load my .cer . 我检查了+ (NSArray *)defaultPinnedCertificates正确加载了.cer

but evaluateServerTrust:forDomain: always return NO : evaluateServerTrust:forDomain:始终返回NO:

return trustedCertificateCount == [serverCertificates count];

[serverCertificates count] = 2 and trustedCertificateCount = 1. [serverCertificates count] = 2, trustedCertificateCount = 1。

What does this means? 这是什么意思? Can you help me please? 你能帮我吗?

AFSecurityPolicy 's default behaviour is to validate the certificate chain. AFSecurityPolicy的默认行为是验证证书链。 You should add all intermediate certificates, or disable validation of the chain: 您应该添加所有中间证书,或禁用链验证:

self.securityPolicy.validatesCertificateChain = NO;

Adding intermediate certificates is the preferred approach. 添加中间证书是首选方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM