Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: ios/web/web_state/ui/crw_wk_web_view_web_controller.mm

Issue 1230033005: WKWebView: Added cert verification API to web controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
index b64f4bb5890827ffdc533fedba842e435b106a79..3b7fab13d4c8d0f8cc38ba5c49a3b1e4f05f8ef1 100644
--- a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
+++ b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
@@ -17,6 +17,7 @@
#import "ios/web/crw_network_activity_indicator_manager.h"
#import "ios/web/navigation/crw_session_controller.h"
#include "ios/web/navigation/web_load_params.h"
+#include "ios/web/net/cert_verifier_block_adapter.h"
#include "ios/web/public/web_client.h"
#import "ios/web/public/web_state/js/crw_js_injection_manager.h"
#import "ios/web/public/web_state/ui/crw_native_content_provider.h"
@@ -35,6 +36,8 @@
#import "ios/web/web_state/web_view_internal_creation_util.h"
#import "ios/web/webui/crw_web_ui_manager.h"
#import "net/base/mac/url_conversions.h"
+#include "net/cert/cert_verify_result.h"
+#include "net/ssl/ssl_config_service.h"
#if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
#include "ios/web/public/cert_store.h"
@@ -125,6 +128,9 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
// CRWWebUIManager object for loading WebUI pages.
base::scoped_nsobject<CRWWebUIManager> _webUIManager;
+
+ // Cert verification object which wraps net::CertVerifier.
+ net::CertVerifierBlockAdapter _certVerifier;
}
// Response's MIME type of the last known navigation.
@@ -227,6 +233,13 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
// Attempts to handle a script message. Returns YES on success, NO otherwise.
- (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage;
+// Verifies the given |cert| for the given |host| and calls |block| on
+// completion. |block| can not be null and may be called either synchronously or
+// asynchronously.
+- (void)verifyCert:(scoped_refptr<net::X509Certificate>)cert
+ forHost:(NSString*)host
+ completionHandler:(void (^)(scoped_ptr<net::CertVerifyResult>, int))block;
davidben 2015/07/31 18:58:46 [Shouldn't these be indented such that the colons
Eugene But (OOO till 7-30) 2015/08/01 00:25:40 This indentation is correct. When the first keywor
+
// Used to decide whether a load that generates errors with the
// NSURLErrorCancelled code should be cancelled.
- (BOOL)shouldAbortLoadForCancelledError:(NSError*)error;
@@ -833,6 +846,18 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
: [super selectorToHandleJavaScriptCommand:command];
}
+- (void)verifyCert:(scoped_refptr<net::X509Certificate>)cert
+ forHost:(NSString*)host
+ completionHandler:(void (^)(scoped_ptr<net::CertVerifyResult>, int))block {
+ DCHECK(block);
+ std::string hostname = base::SysNSStringToUTF8(host);
+ net::CertVerifierBlockAdapter::Params params(cert, hostname);
+ params.ocsp_response = ""; // Not provided by iOS API.
Ryan Sleevi 2015/08/01 01:36:22 = "" is unnscessary (you should have a default cto
Eugene But (OOO till 7-30) 2015/08/05 16:13:43 I just want to be explicit that ocsp_response is e
Ryan Sleevi 2015/08/06 03:07:08 We developed a clang tool to excise this pattern f
Eugene But (OOO till 7-30) 2015/08/07 02:27:19 Thanks, I did not know about clang changes. Replac
+ params.flags = net::CertVerifier::VERIFY_CERT_IO_ENABLED;
Ryan Sleevi 2015/08/01 01:36:22 This doesn't seem correct. See https://code.googl
Eugene But (OOO till 7-30) 2015/08/05 16:13:43 Done, thanks for the link.
+ params.crl_set = net::SSLConfigService::GetCRLSet().Pass();
+ _certVerifier.Verify(params, block);
+}
+
- (BOOL)shouldAbortLoadForCancelledError:(NSError*)error {
DCHECK_EQ(error.code, NSURLErrorCancelled);
// Do not abort the load if it is for an app specific URL, as such errors
@@ -1166,8 +1191,21 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
completionHandler:
(void (^)(NSURLSessionAuthChallengeDisposition disposition,
NSURLCredential *credential))completionHandler {
davidben 2015/07/31 18:58:46 Isn't this supposed to check the protectionSpace.a
Eugene But (OOO till 7-30) 2015/08/01 00:25:40 challenge.protectionSpace.serverTrust returns nil
davidben 2015/08/03 18:06:32 This is unreasonable to rely on.
Eugene But (OOO till 7-30) 2015/08/05 16:13:43 I guess auth method, other than NSURLAuthenticatio
- NOTIMPLEMENTED();
- completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
+ SecTrustRef trust = challenge.protectionSpace.serverTrust;
+ scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust);
+ [self verifyCert:cert
+ forHost:challenge.protectionSpace.host
+ completionHandler:^(scoped_ptr<net::CertVerifyResult> result,
+ int status) {
+ DCHECK(result || status);
+ if (result && !net::IsCertStatusError(result->cert_status)) {
Ryan Sleevi 2015/08/01 01:36:22 This doesn't seem right either - normally you'd al
Eugene But (OOO till 7-30) 2015/08/05 16:13:43 Done.
+ // Cert is valid.
+ } else {
+ // Cert is invalid.
davidben 2015/07/31 18:58:46 The docs point to this sample code: https://devel
Eugene But (OOO till 7-30) 2015/08/01 00:25:40 Thanks for the link. Accepting bad SSL cert is not
+ }
+ NOTIMPLEMENTED();
+ completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
davidben 2015/07/31 18:58:46 Is this supposed to be NSURLSessionAuthChallengeRe
Eugene But (OOO till 7-30) 2015/08/01 00:25:40 NSURLSessionAuthChallengeRejectProtectionSpace is
Eugene But (OOO till 7-30) 2015/08/05 16:13:43 Changed to NSURLSessionAuthChallengePerformDefault
+ }];
}
- (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698