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.
Well, just to be simple, follow this steps
Copy your .cer file to your project bundle
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.
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.