How do I ignore an "invalid" SSL certificate in Objective-C?
Posted
by
ipwnstuff
on Stack Overflow
See other posts from Stack Overflow
or by ipwnstuff
Published on 2012-06-20T01:41:18Z
Indexed on
2012/06/20
3:16 UTC
Read the original article
Hit count: 166
objective-c
Currently I have:
NSArray* array = [NSArray arrayWithObjects:@"auth.login",@"username",@"password", nil];
NSData* packed_array = [array messagePack];
NSURL* url = [NSURL URLWithString:@"https://192.168.1.149:3790/api/1.0"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"RPC Server" forHTTPHeaderField:@"Host"];
[request setValue:@"binary/message-pack" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",[packed_array length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:packed_array];
NSURLResponse *response;
NSError *error;
responseData = [NSMutableData dataWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]];
NSLog(@"response data: %@",[responseData messagePackParse]);
NSLog(@"error: %@",error);
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"called canAuthenticateAgainstProtectionSpace");
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSLog(@"called didReceiveAuthenticationChallenge");
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
Which returns "Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid"…
"
How should I be implementing the answer from this question?
© Stack Overflow or respective owner