I have the following problem:
I have a UIWebView
which is loading the website correctly but the server wants an authentication from the client (UIWebView
) too. I've added the ssl certificate
with the following code I got from another site:
shouldStartLoadWithRequest:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType (UIWebViewNavigationType)navigationType;
{
if(![self authenticated])
{
[self setAuthenticated:NO];
[self setUrlConnection:[[NSURLConnection alloc] initWithRequest:[self requestObj] delegate:self]];
[[self urlConnection] start];
return NO;
}
return YES;
}
didReceiveAuthenticationChallenge:
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0)
{
[self setAuthenticated:YES];
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
else [[challenge sender] cancelAuthenticationChallenge:challenge];
}
didReceiveResponse:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
{
[self setAuthenticated:YES];
[[self webView] loadRequest:[self requestObj]];
[[self urlConnection] cancel];
}
canAuthenticateAgainstProtectionSpace:
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
Now the server needed an authentication from the client (certificate) with a specific DN
name. I found iOS Client Certificates and Mobile Device Management but the code didn't helped me and didn't solved my problem.
Is it possible to append an PKCS12 file to my UIWebView so if the server wants an authentication from the client the UIWebView
show him this file?
I always get the error
2016-04-20 12:20:50.880 App [469:126255] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2016-04-20 12:20:51.454 App [469:126252] CFNetwork SSLHandshake failed (-9824 -> -9829)
2016-04-20 12:20:51.456 App [469:126252] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9829)