简体   繁体   中英

Connect iOS app with Apache Server using SSL certificate?

I am using AFNetworking 2.0, and I have enabled certificate authentication on the Apache server. I have placed a .crt file in the xcode project. and whenever I try to establish a https connection to the server I get the following error:

The operation couldn't be completed. (NSURLErrorDomain error -1012.)

Here is the code for calling the server :

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]];
[manager POST:@"https://www.example.com/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //success
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //failure
}];

By default AFNetworking only pins against .cer files.

Rename your certificate so that it is .cer rather than .crt and it should work.

You can see if it's working by looking at the pinned certificates:

NSLog(@"Using %d pinned certificates", [manager.securityPolicy.pinnedCertificates count]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM