Hi,
How do I perform SSL authentication with p12 certificate for a webview request as we do for NSUrlSession. I am able to handle the authentication with the certificate using the delegate "didReceiveChallenge". Please look at the below code snippet which i used for NSUrlSession:
NSString *strAuthenticationMethod = challenge.protectionSpace.authenticationMethod;
NSLog(@"authentication method: %@", strAuthenticationMethod);
NSURLCredential *credential = nil;
if([strAuthenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate])
{
credential = [self getCredentialsForClientTrust]; // This function will give me a NSURLCredential object for my p12 certificate
if(credential)
{
NSLog(@"credentials obtained%@",credential);
completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
}
else{
NSLog(@"failed to get credentials %@",credential);
completionHandler(NSURLSessionAuthChallengeUseCredential,nil);
}
}
else
{
completionHandler(NSURLSessionAuthChallengeUseCredential,nil);
}This works perfectly, but how do I perform this operation for a webview request?
Thanks!!
I am looking for UIWebView
Ah, that explains things; I was confused because I misunderstood the context of the code snippet you posted.
UIWebView does not support an authentication handling delegate callback. In general I recommend that folks move to WKWebView, which does have such a callback; that callback provides a well-supported and easy way to handle authenticating challenges that the view encounters.
Unfortunately, WKWebView’s authentication challenge support is broken for
NSURLAuthenticationMethodClientCertificate challenges (r. 22659960). The only way to work around this is to:
stick with UIWebView )-:
use an NSURLProtocol to intercept the network requests made by the web view and recursively dispatch them so that your code sees the authentication challenges
The CustomHTTPProtocol sample code shows the basic strategy (although it shows how to handle
NSURLAuthenticationMethodServerTrust challenges, which is a bit pointless these days because WKWebView’s support for those challenges works just fine).
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"