AFNetworking Public Key for Trusted Certificate

I am using AFNetworking 2.3.1, I have a trusted certificate for which I would like to bind a public key.

I have crt , key , pfx , so I assume I should add them to my package.

 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { return [self processError:[operation response]]; }]; [operation start]; 

Now, how can I tell AFNetworking to use AFSSLPinningModePublicKey mode?
(I do not see the setSSLPinningMode method from AFHTTPRequestOperation )

And how do I tell AFNetworking to use the added key? I can not find any example in the documentation.

+5
source share
2 answers

In AFNetworking, the AFSecurityPolicy object has values ​​for security features, including SSL pin mode.

You can set securityPolicy to AFHTTPRequestOperation:

 AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]; operation.securityPolicy = securityPolicy; 

Your certificate must have the extension cer not crt and must be in DER format. Add it to your kit. You can convert it to the correct format in the terminal with the following command:

openssl x509 -in domain.crt -out domain.cer -outform der

You should not include keys in your application suite, only a certificate is required.

+10
source
 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; /**** SSL Pinning ****/ AFSecurityPolicy *securityPolicy = [[self alloc] init]; securityPolicy.SSLPinningMode = AFSSLPinningModePublicKey; [manager setSecurityPolicy:securityPolicy]; /**** SSL Pinning ****/ [manager GET:WEBSITE_URL parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary* responseObject) { //..... beautiful code here } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //..... beautiful code here }]; 

Hope for this help

Check out the link here: Alternatively, contact AFNetworking Documents

+4
source

Source: https://habr.com/ru/post/972860/


All Articles