How to assign a .cer file in AFNetworking?

≡放荡痞女 提交于 2020-01-01 05:19:29

问题


I am using AFNetworking to develop iPhone application that establish HTTPS connections ,I want use self-signed cert or trusted cert I can define ,but I cannot find any function(API) in AFNetworking can do this.

And I saw this page : How to use NSURLConnection to connect with SSL for an untrusted cert? .But I want to know how to assign a cer file?

Thanks.


回答1:


Well, just to be simple, follow this steps

  1. Copy your .cer file to your project bundle

  2. Assuming you are using

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] init...

    Invoke the following after that line:

    [operation setSSLPinningMode:AFSSLPinningModeCertificate]

This will instruct AF to do Certificate Pinning, no need to set anything else.




回答2:


Just copy cer file in your project bundle. In AFURLConnectionOperation.m file, line 215:

NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];

It will assign cer file automatically.

And make sure that Prefix.pch has follows:

#define _AFNETWORKING_PIN_SSL_CERTIFICATES_

and

#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_

if untrusted cert.



来源:https://stackoverflow.com/questions/13659218/how-to-assign-a-cer-file-in-afnetworking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!