Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CB-3576] Privately signed https links don't work in InAppBrowser #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CordovaLib/Classes/CDVInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@end

@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate>{
@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate, NSURLConnectionDataDelegate>{
@private
NSString* _userAgent;
NSString* _prevUserAgent;
Expand All @@ -57,6 +57,8 @@
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> 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;
Expand All @@ -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;

Expand Down
36 changes: 34 additions & 2 deletions CordovaLib/Classes/CDVInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -355,6 +357,7 @@ - (void)browserExit
@implementation CDVInAppBrowserViewController

@synthesize currentURL;
@synthesize validateSsl;

- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -773,6 +804,7 @@ - (id)init
self.keyboarddisplayrequiresuseraction = YES;
self.suppressesincrementalrendering = NO;
self.hidden = NO;
self.validatessl = YES;
}

return self;
Expand Down