OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 12 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 16 #include "components/security_state/content/content_utils.h" |
| 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/navigation_handle.h" |
| 19 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/origin_util.h" |
| 22 #include "net/base/net_errors.h" |
| 23 #include "net/cert/x509_certificate.h" |
| 24 #include "net/ssl/ssl_cipher_suite_names.h" |
| 25 #include "net/ssl/ssl_connection_status_flags.h" |
| 26 #include "third_party/boringssl/src/include/openssl/ssl.h" |
| 27 #include "ui/base/l10n/l10n_util.h" |
| 28 |
| 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper); |
| 30 |
| 31 using safe_browsing::SafeBrowsingUIManager; |
| 32 using security_state::SecurityStateModel; |
| 33 |
| 34 SecurityStateTabHelper::SecurityStateTabHelper( |
| 35 content::WebContents* web_contents) |
| 36 : content::WebContentsObserver(web_contents), |
| 37 model_(new security_state::SecurityStateModel()), |
| 38 logged_http_warning_on_current_navigation_(false) {} |
| 39 |
| 40 SecurityStateTabHelper::~SecurityStateTabHelper() {} |
| 41 |
| 42 void SecurityStateTabHelper::GetSecurityInfo( |
| 43 SecurityStateModel::SecurityInfo* result) const { |
| 44 model_->GetSecurityInfo(result, GetVisibleSecurityState(), |
| 45 UsedPolicyInstalledCertificate(), |
| 46 base::Bind(&content::IsOriginSecure)); |
| 47 } |
| 48 |
| 49 void SecurityStateTabHelper::VisibleSecurityStateChanged() { |
| 50 if (logged_http_warning_on_current_navigation_) |
| 51 return; |
| 52 |
| 53 security_state::SecurityStateModel::SecurityInfo security_info; |
| 54 GetSecurityInfo(&security_info); |
| 55 if (!security_info.displayed_private_user_data_input_on_http) |
| 56 return; |
| 57 |
| 58 std::string warning; |
| 59 bool warning_is_user_visible = false; |
| 60 switch (security_info.security_level) { |
| 61 case security_state::SecurityStateModel::HTTP_SHOW_WARNING: |
| 62 warning = |
| 63 "This page includes a password or credit card input in a non-secure " |
| 64 "context. A warning has been added to the URL bar. For more " |
| 65 "information, see https://goo.gl/zmWq3m."; |
| 66 warning_is_user_visible = true; |
| 67 break; |
| 68 case security_state::SecurityStateModel::NONE: |
| 69 case security_state::SecurityStateModel::DANGEROUS: |
| 70 warning = |
| 71 "This page includes a password or credit card input in a non-secure " |
| 72 "context. A warning will be added to the URL bar in Chrome 56 (Jan " |
| 73 "2017). For more information, see https://goo.gl/zmWq3m."; |
| 74 break; |
| 75 default: |
| 76 return; |
| 77 } |
| 78 |
| 79 logged_http_warning_on_current_navigation_ = true; |
| 80 web_contents()->GetMainFrame()->AddMessageToConsole( |
| 81 content::CONSOLE_MESSAGE_LEVEL_WARNING, warning); |
| 82 UMA_HISTOGRAM_BOOLEAN("Security.HTTPBad.UserWarnedAboutSensitiveInput", |
| 83 warning_is_user_visible); |
| 84 } |
| 85 |
| 86 void SecurityStateTabHelper::DidFinishNavigation( |
| 87 content::NavigationHandle* navigation_handle) { |
| 88 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) { |
| 89 // Only reset the console message flag for main-frame navigations, |
| 90 // and not for same-page navigations like reference fragments and pushState. |
| 91 logged_http_warning_on_current_navigation_ = false; |
| 92 } |
| 93 } |
| 94 |
| 95 bool SecurityStateTabHelper::UsedPolicyInstalledCertificate() const { |
| 96 #if defined(OS_CHROMEOS) |
| 97 policy::PolicyCertService* service = |
| 98 policy::PolicyCertServiceFactory::GetForProfile( |
| 99 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| 100 if (service && service->UsedPolicyCertificates()) |
| 101 return true; |
| 102 #endif |
| 103 return false; |
| 104 } |
| 105 |
| 106 bool SecurityStateTabHelper::GetMalwareStatus() const { |
| 107 content::NavigationEntry* entry = |
| 108 web_contents()->GetController().GetVisibleEntry(); |
| 109 if (!entry) |
| 110 return false; |
| 111 safe_browsing::SafeBrowsingService* sb_service = |
| 112 g_browser_process->safe_browsing_service(); |
| 113 if (!sb_service) |
| 114 return false; |
| 115 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager(); |
| 116 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents( |
| 117 entry->GetURL(), false, entry, web_contents(), false)) { |
| 118 return true; |
| 119 } |
| 120 return false; |
| 121 } |
| 122 |
| 123 std::unique_ptr<security_state::SecurityStateModel::VisibleSecurityState> |
| 124 SecurityStateTabHelper::GetVisibleSecurityState() const { |
| 125 auto state = |
| 126 security_state_content_utils::GetVisibleSecurityState(web_contents()); |
| 127 |
| 128 // Malware status might already be known even if connection security |
| 129 // information is still being initialized, thus no need to check for that. |
| 130 state->fails_malware_check = GetMalwareStatus(); |
| 131 |
| 132 return state; |
| 133 } |
OLD | NEW |