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 368587eab562249bab292466ff34a608391942d3..ed03c4d070fc220d65397e770a6226f161ac9096 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 |
@@ -11,6 +11,7 @@ |
#include "base/json/json_reader.h" |
#import "base/mac/scoped_nsobject.h" |
#include "base/macros.h" |
+#include "base/metrics/histogram_macros.h" |
#include "base/strings/sys_string_conversions.h" |
#include "base/values.h" |
#import "ios/net/http_response_headers_util.h" |
@@ -82,6 +83,14 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
} // namespace |
+#if !defined(__IPHONE_9_0) |
+// Predeclare iOS9 API so calls are compiled on iOS8 bots. |
+// TODO(eugenebut): cleanup this (crbug.com/523365). |
+@interface WKWebView (CRWIOS9API) |
+@property(nonatomic, readonly, copy) NSArray* certificateChain; |
+@end |
+#endif |
+ |
@interface CRWWKWebViewWebController () <WKNavigationDelegate, |
WKScriptMessageHandler, |
WKUIDelegate> { |
@@ -250,6 +259,12 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
// Clears all activity indicator tasks for this web controller. |
- (void)clearActivityIndicatorTasks; |
+// Obtains SSL status from given |certChain| and updates navigation items with |
+// given |certID| and |host|. |
+- (void)updateSSLStatusForNavigationItemsWithCertID:(int)certID |
+ host:(NSString*)host |
+ usingCertChain:(NSArray*)certChain; |
+ |
#if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
// Updates SSL status for the current navigation item based on the information |
// provided by web view. |
@@ -864,12 +879,54 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
clearNetworkTasksForGroup:[self activityIndicatorGroupID]]; |
} |
+- (void)updateSSLStatusForNavigationItemsWithCertID:(int)certID |
davidben
2015/10/05 22:19:11
Yikes. What exactly do you all use cert IDs for? I
Eugene But (OOO till 7-30)
2015/10/06 03:10:09
Fetching CertStatus is asynchronous operation, so
stuartmorgan
2015/10/06 22:02:36
Per offline discussion, let's have the navigation
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
Done.
davidben
2015/10/07 20:16:29
Oh, actually, I'd missed that you don't use conten
Eugene But (OOO till 7-30)
2015/10/08 16:53:32
We want to keep web::SSLStatus as close as possibl
|
+ host:(NSString*)host |
+ usingCertChain:(NSArray*)certChain { |
+ base::WeakNSObject<CRWWKWebViewWebController> weakSelf(self); |
+ void (^SSLStatusResponse)(web::SecurityStyle, net::CertStatus) = ^( |
+ web::SecurityStyle style, net::CertStatus certStatus) { |
+ base::scoped_nsobject<CRWWKWebViewWebController> strongSelf( |
+ [weakSelf retain]); |
+ if (!strongSelf || [strongSelf isBeingDestroyed]) { |
+ return; |
+ } |
+ |
+ web::NavigationManager* navigationManager = |
+ [strongSelf webStateImpl]->GetNavigationManager(); |
+ int currentItemIndex = navigationManager->GetCurrentEntryIndex(); |
+ |
+ bool updatedCurrentItem = false; |
+ std::string GURLHost = base::SysNSStringToUTF8(host); |
+ for (int i = 0; i < navigationManager->GetEntryCount(); i++) { |
+ web::NavigationItem* item = navigationManager->GetItemAtIndex(i); |
+ web::SSLStatus& SSLStatus = item->GetSSL(); |
+ if (SSLStatus.cert_id == certID && item->GetURL().host() == GURLHost) { |
+ web::SSLStatus previousSSLStatus = item->GetSSL(); |
+ SSLStatus.cert_status = certStatus; |
+ SSLStatus.security_style = style; |
+ if (currentItemIndex == i && !previousSSLStatus.Equals(SSLStatus)) { |
+ updatedCurrentItem = true; |
+ } |
+ } |
+ } |
+ |
+ if (updatedCurrentItem) { |
+ [strongSelf didUpdateSSLStatusForCurrentNavigationItem]; |
+ } |
+ }; |
+ |
+ [_certVerificationController |
+ querySSLStatusForTrust:web::CreateServerTrustFromChain(certChain, host) |
+ host:host |
+ completionHandler:SSLStatusResponse]; |
+} |
+ |
#if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
+ |
- (void)updateSSLStatusForCurrentNavigationItem { |
if ([self isBeingDestroyed]) |
return; |
- DCHECK(self.webStateImpl); |
web::NavigationItem* item = |
self.webStateImpl->GetNavigationManagerImpl().GetLastCommittedItem(); |
if (!item) |
@@ -877,34 +934,58 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
web::SSLStatus previousSSLStatus = item->GetSSL(); |
web::SSLStatus& SSLStatus = item->GetSSL(); |
- if (item->GetURL().SchemeIsCryptographic()) { |
- // TODO(eugenebut): Do not set security style to authenticated once |
- // proceeding with bad ssl cert is implemented. |
- SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATED; |
- SSLStatus.content_status = [_wkWebView hasOnlySecureContent] |
- ? web::SSLStatus::NORMAL_CONTENT |
- : web::SSLStatus::DISPLAYED_INSECURE_CONTENT; |
- |
- if (base::ios::IsRunningOnIOS9OrLater()) { |
- scoped_refptr<net::X509Certificate> cert(web::CreateCertFromChain( |
- [_wkWebView performSelector:@selector(certificateChain)])); |
- if (cert) { |
- SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert( |
- cert.get(), self.certGroupID); |
- } else { |
- SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; |
- SSLStatus.cert_id = 0; |
+ |
+ // Starting from iOS9 WKWebView blocks active mixed content, so if |
+ // |hasOnlySecureContent| returns NO it means passive content. |
+ // On iOS8 there is no way to determine if web view has active mixed content. |
+ SSLStatus.content_status = [_wkWebView hasOnlySecureContent] |
+ ? web::SSLStatus::NORMAL_CONTENT |
+ : web::SSLStatus::DISPLAYED_INSECURE_CONTENT; |
+ |
+ // Retrieve top level frame certificate. |
+ scoped_refptr<net::X509Certificate> cert; |
+ if (base::ios::IsRunningOnIOS9OrLater() && |
+ item->GetURL().SchemeIsCryptographic()) { |
+ NSArray* chain = [_wkWebView certificateChain]; |
+ cert = web::CreateCertFromChain(chain); |
+ if (cert) { |
+ UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
+ true); |
+ int oldCertID = SSLStatus.cert_id; |
+ SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert( |
+ cert.get(), self.certGroupID); |
+ NSString* host = [_wkWebView URL].host; |
+ if (oldCertID != SSLStatus.cert_id || |
davidben
2015/10/05 22:19:11
I don't believe this can ever be false. Looking at
Eugene But (OOO till 7-30)
2015/10/06 03:10:09
This can be false and w/o this check cert status w
davidben
2015/10/07 20:16:29
Ah, you're right. I'd missed that.
|
+ item->GetURL().host() != base::SysNSStringToUTF8(host)) { |
+ [self updateSSLStatusForNavigationItemsWithCertID:SSLStatus.cert_id |
+ host:host |
+ usingCertChain:chain]; |
davidben
2015/10/05 22:19:11
Why update all navigation entries? This is confusi
Eugene But (OOO till 7-30)
2015/10/06 03:10:09
Replied above. I did not find a good way to find c
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
Actually there is a way to update only requested e
|
} |
} |
- } else { |
- SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; |
+ } |
+ |
+ if (!cert) { |
SSLStatus.cert_id = 0; |
+ if (!item->GetURL().SchemeIsCryptographic()) { |
+ // HTTP or other non-secure connection. |
+ SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; |
+ } else if (base::ios::IsRunningOnIOS9OrLater()) { |
+ // HTTPS, iOS9 and no certificate (this use-case has not been observed). |
+ UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
+ false); |
davidben
2015/10/05 22:19:11
UMA_HISTOGRAM macros expand to a fair amount of co
Eugene But (OOO till 7-30)
2015/10/06 03:10:09
Moved to a separate function.
|
+ SSLStatus.security_style = web::SECURITY_STYLE_UNKNOWN; |
+ } else { |
+ // HTTPS, iOS8. |
+ // iOS8 cannot load unauthenticated HTTPS content. |
+ SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATED; |
+ } |
} |
if (!previousSSLStatus.Equals(SSLStatus)) { |
[self didUpdateSSLStatusForCurrentNavigationItem]; |
} |
} |
+ |
#endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
- (void)registerLoadRequest:(const GURL&)url { |