Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bypass kCFStreamErrorDomainSSL error for self-signed certificates on iOS 7

I am trying to load a HTTPS web page, which has a self-signed certificate, in to an UIWebView. Using tips like this one, or this one, it works under iOS 6. The same does not work in iOS 7.

As per the linked-to Stack Overflow questions, I'm also using an NSURLConnection to first try and get past the self-signed certificate -- this all before even trying to load the URL in the UIWebView.

When trying the same in iOS 7, I get the following error:

2014-02-12 16:00:08.367 WebView[24176:5307] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2014-02-12 16:00:08.370 WebView[24176:70b] An SSL error has occurred and a secure connection to the server cannot be made.

Is there a work-around to get this to work in iOS 7? At the moment I'm using the first example.

like image 982
Diego Barros Avatar asked Feb 12 '14 05:02

Diego Barros


People also ask

Why can't I setup a self signed certificate on my iPhone?

For newer iOS (such as 11.4.1), a self signed certificate is "Not Trusted" therefore the account cannot be setup and will not be enabled by default.

How to bypass SSL certificate pinning on iOS?

The simplest method to bypass SSL certificate pinning is to install software that does all the hard work for us. The tools listed below are easy to setup and get running. Installation instructions are listed on each of the webpages. However, with these methods, a jailbroken iOS device is required.

Did Apple remove the ability to trust self-signed SSL certificates?

It appears that Apple has removed (or hidden) the ability to trust SSL certificates that are self-signed. We host our own mail server with a self-signed certificate and previously we could manually trust the certificate on iOS devices.

How to fix SSL certificate errors on iOS devices?

Installing your own CA is the first step to getting rid of SSL errors. Installing your CA is relatively easy inside of iOS. The first step is to get the CA onto the device. This could be done through opening an email attachment or downloading the certificate. First off, configure your mobile device and web proxy to be able to intercept web traffic.


Video Answer


1 Answers

Please follow the link:

in UiWebView - NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -108)

BOOL _Authenticated;
NSURLRequest *_FailedRequest;
#pragma UIWebViewDelegate

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType {
    BOOL result = _Authenticated;
    if (!_Authenticated) {
        _FailedRequest = request;
        NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [urlConnection start];
    }
    return result;
}

#pragma NSURLConnectionDelegate

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        NSURL* baseURL = [NSURL URLWithString:@"your url"];
        if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) {
            NSLog(@"trusting connection to host %@", challenge.protectionSpace.host);
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        } else
            NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host);
    }
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)pResponse {
    _Authenticated = YES;
    [connection cancel];
    [webvw loadRequest:_FailedRequest];
}
like image 152
Manab Kumar Mal Avatar answered Oct 27 '22 03:10

Manab Kumar Mal