diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h index 248274a38..03f6cd26f 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.h +++ b/CordovaLib/Classes/CDVInAppBrowser.h @@ -38,7 +38,7 @@ @end -@interface CDVInAppBrowserViewController : UIViewController { +@interface CDVInAppBrowserViewController : UIViewController { @private NSString* _userAgent; NSString* _prevUserAgent; @@ -57,6 +57,8 @@ @property (nonatomic, weak) id orientationDelegate; @property (nonatomic, weak) CDVInAppBrowser* navigationDelegate; @property (nonatomic) NSURL* currentURL; +@property (nonatomic, weak) NSURLRequest* urlRequest; +@property (nonatomic, assign) BOOL validateSsl; - (void)close; - (void)navigateTo:(NSURL*)url; @@ -83,6 +85,7 @@ @property (nonatomic, assign) BOOL keyboarddisplayrequiresuseraction; @property (nonatomic, assign) BOOL suppressesincrementalrendering; @property (nonatomic, assign) BOOL hidden; +@property (nonatomic, assign) BOOL validatessl; + (CDVInAppBrowserOptions*)parseOptions:(NSString*)options; diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m index b832e2399..50f78efef 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.m +++ b/CordovaLib/Classes/CDVInAppBrowser.m @@ -139,6 +139,8 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options self.inAppBrowserViewController.webView.keyboardDisplayRequiresUserAction = browserOptions.keyboarddisplayrequiresuseraction; self.inAppBrowserViewController.webView.suppressesIncrementalRendering = browserOptions.suppressesincrementalrendering; } + // SSL certificate error option + [self.inAppBrowserViewController setValidateSsl:browserOptions.validatessl]; if (! browserOptions.hidden) { if (self.viewController.modalViewController != self.inAppBrowserViewController) { @@ -355,6 +357,7 @@ - (void)browserExit @implementation CDVInAppBrowserViewController @synthesize currentURL; +@synthesize validateSsl; - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent { @@ -677,11 +680,22 @@ - (void)webViewDidStartLoad:(UIWebView*)theWebView - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]]; - + BOOL isSecuredUrl = [[request.URL scheme] isEqualToString:@"https"]; + if (isTopLevelNavigation) { self.currentURL = request.URL; } - return [self.navigationDelegate webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; + + if (isSecuredUrl && self.validateSsl == NO) { + // Ignore SSL certificate validation. This option can be used for loading self-signed https URLs + // in the InAppBrowser. Stop the default load request and load the URL through NSURLConnection + self.urlRequest = request; + NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; + NSLog(@"Ignoring SSL certificate validation and loading URL: %@", [[connection currentRequest] URL]); + return NO; + } else { + return [self.navigationDelegate webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; + } } - (void)webViewDidFinishLoad:(UIWebView*)theWebView @@ -727,6 +741,23 @@ - (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error [self.navigationDelegate webView:theWebView didFailLoadWithError:error]; } +# pragma mark - NSURLConnectionDataDelegate methods + +- (void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } + [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; +} + +- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response +{ + self.validateSsl = YES; + [connection cancel]; + [self.webView loadRequest:self.urlRequest]; +} + #pragma mark CDVScreenOrientationDelegate - (BOOL)shouldAutorotate @@ -773,6 +804,7 @@ - (id)init self.keyboarddisplayrequiresuseraction = YES; self.suppressesincrementalrendering = NO; self.hidden = NO; + self.validatessl = YES; } return self;