How to assign .cer file in AFNetworking?

I use AFNetworking to develop an iPhone application that establishes HTTPS connections, I want to use a self-signed certificate or a trusted certificate that I can define, but I can not find any function (API) in AFNetworking, it can do this.

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

Thanks.

+6
source share
2 answers

Well, just to be simple, follow these steps

  • Copy your .cer file to your project

  • Assuming you are using

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

    Call the following after this line:

    [operation setSSLPinningMode:AFSSLPinningModeCertificate]

This will instruct you to log in to print the certificate; you do not need to install anything.

+3
source

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

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

It will automatically assign a cer file.

And make sure Prefix.pch:

 #define _AFNETWORKING_PIN_SSL_CERTIFICATES_ 

and

 #define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ 

if not trusted certificate.

+2
source

All Articles