I am handling https authentication for server based on its name but i want to trust server based on a certificate which server gives me. how can i do this ,any help ??
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust])
{
// we only trust our own domain
if ([challenge.protectionSpace.host isEqualToString:@"www.serverpage.com"])
{
NSURLCredential *credential =
[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
I searched web and found most of the answers are just accepting any server authentication without validating .