0

I want to use https based services in my application. I'm using AFNetworking library for calling web-APIs. I'm able to call https APIs by adding NSAppTransportSecurity and AllowArbitaryLoads to True. But i don't have to use SSL certificate while using this.

Can anybody help me with the full procedure of integrating SSL with AFNetworking so that all the requests pass through it securely.

Pinank Lakhani
  • 1,109
  • 2
  • 11
  • 31
  • check this i think this is useful for you=> http://stackoverflow.com/questions/12967220/i-want-to-allow-invalid-ssl-certificates-with-afnetworking – Raju Aug 30 '16 at 06:05

1 Answers1

0

You can do this:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager.securityPolicy setValidatesDomainName:NO];
[manager.securityPolicy setAllowInvalidCertificates:YES];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {

}];
[dataTask resume];

UPDATE:

If you wish to validate your certificate you can do this instead:

Add your certificate to your app's bundle.

Then do this:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
[manager.securityPolicy setValidatesDomainName:NO];
[manager.securityPolicy setAllowInvalidCertificates:YES];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {

}];
[dataTask resume];
The Mach System
  • 6,703
  • 3
  • 16
  • 20
  • From where should i have to give path of my certificate. And [manager.securityPolicy setAllowInvalidCertificates:YES]; Is one of way to avoid use of certificate. But i want to make my connection secure. – Pinank Lakhani Aug 11 '16 at 05:52