Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 6 | 6 |
| 7 #include <openssl/ssl.h> | 7 #include <openssl/ssl.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 18 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 19 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 19 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 22 #include "chrome/browser/safe_browsing/ui_manager.h" | 22 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/navigation_handle.h" | |
| 26 #include "content/public/browser/render_frame_host.h" | |
| 25 #include "content/public/browser/security_style_explanation.h" | 27 #include "content/public/browser/security_style_explanation.h" |
| 26 #include "content/public/browser/security_style_explanations.h" | 28 #include "content/public/browser/security_style_explanations.h" |
| 27 #include "content/public/browser/ssl_status.h" | 29 #include "content/public/browser/ssl_status.h" |
| 28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/origin_util.h" | 31 #include "content/public/common/origin_util.h" |
| 30 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 31 #include "net/cert/x509_certificate.h" | 33 #include "net/cert/x509_certificate.h" |
| 32 #include "net/ssl/ssl_cipher_suite_names.h" | 34 #include "net/ssl/ssl_cipher_suite_names.h" |
| 33 #include "net/ssl/ssl_connection_status_flags.h" | 35 #include "net/ssl/ssl_connection_status_flags.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 g_browser_process->safe_browsing_service(); | 155 g_browser_process->safe_browsing_service(); |
| 154 if (!sb_service) | 156 if (!sb_service) |
| 155 return; | 157 return; |
| 156 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager(); | 158 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager(); |
| 157 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents( | 159 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents( |
| 158 entry->GetURL(), false, entry, web_contents, false)) { | 160 entry->GetURL(), false, entry, web_contents, false)) { |
| 159 state->fails_malware_check = true; | 161 state->fails_malware_check = true; |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 165 // Logs a message to the console if the security level has been | |
| 166 // downgraded to HTTP_SHOW_WARNING. Returns true if the console message | |
| 167 // was logged, false otherwise. | |
| 168 bool MaybeLogHttpWarning( | |
| 169 content::WebContents* web_contents, | |
| 170 const security_state::SecurityStateModel::SecurityInfo* const | |
| 171 security_info) { | |
| 172 if (security_info->security_level == | |
| 173 security_state::SecurityStateModel::HTTP_SHOW_WARNING) { | |
| 174 web_contents->GetMainFrame()->AddMessageToConsole( | |
| 175 content::CONSOLE_MESSAGE_LEVEL_WARNING, | |
| 176 "In Chrome M56 (Jan 2017), this page will be marked " | |
| 177 "as \"not secure\" in the URL bar. For more " | |
| 178 "information see https://goo.gl/zmWq3m"); | |
| 179 return true; | |
| 180 } | |
| 181 return false; | |
| 182 } | |
| 183 | |
| 163 } // namespace | 184 } // namespace |
| 164 | 185 |
| 165 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( | 186 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( |
| 166 content::WebContents* web_contents) | 187 content::WebContents* web_contents) |
| 167 : web_contents_(web_contents), | 188 : web_contents_(web_contents), |
| 168 security_state_model_(new SecurityStateModel()) { | 189 security_state_model_(new SecurityStateModel()), |
| 190 logged_http_warning_on_current_navigation_(false) { | |
| 169 security_state_model_->SetClient(this); | 191 security_state_model_->SetClient(this); |
| 192 WebContentsObserver::Observe(web_contents_); | |
| 170 } | 193 } |
| 171 | 194 |
| 172 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} | 195 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} |
| 173 | 196 |
| 174 // static | 197 // static |
| 175 blink::WebSecurityStyle ChromeSecurityStateModelClient::GetSecurityStyle( | 198 blink::WebSecurityStyle ChromeSecurityStateModelClient::GetSecurityStyle( |
| 176 const security_state::SecurityStateModel::SecurityInfo& security_info, | 199 const security_state::SecurityStateModel::SecurityInfo& security_info, |
| 177 content::SecurityStyleExplanations* security_style_explanations) { | 200 content::SecurityStyleExplanations* security_style_explanations) { |
| 178 const blink::WebSecurityStyle security_style = | 201 const blink::WebSecurityStyle security_style = |
| 179 SecurityLevelToSecurityStyle(security_info.security_level); | 202 SecurityLevelToSecurityStyle(security_info.security_level); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 "Public-Key Pinning Bypassed", | 313 "Public-Key Pinning Bypassed", |
| 291 "Public-key pinning was bypassed by a local root certificate.")); | 314 "Public-key pinning was bypassed by a local root certificate.")); |
| 292 } | 315 } |
| 293 | 316 |
| 294 return security_style; | 317 return security_style; |
| 295 } | 318 } |
| 296 | 319 |
| 297 void ChromeSecurityStateModelClient::GetSecurityInfo( | 320 void ChromeSecurityStateModelClient::GetSecurityInfo( |
| 298 SecurityStateModel::SecurityInfo* result) const { | 321 SecurityStateModel::SecurityInfo* result) const { |
| 299 security_state_model_->GetSecurityInfo(result); | 322 security_state_model_->GetSecurityInfo(result); |
| 323 if (!logged_http_warning_on_current_navigation_) { | |
| 324 logged_http_warning_on_current_navigation_ = | |
| 325 MaybeLogHttpWarning(web_contents_, result); | |
| 326 } | |
|
meacer
2016/10/13 17:41:01
I'm sure there is a good reason, but it feels a bi
estark
2016/10/13 17:59:17
Yeah, I agree it's kinda gross, see my first comme
| |
| 300 } | 327 } |
| 301 | 328 |
| 302 bool ChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() { | 329 bool ChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() { |
| 303 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 304 policy::PolicyCertService* service = | 331 policy::PolicyCertService* service = |
| 305 policy::PolicyCertServiceFactory::GetForProfile( | 332 policy::PolicyCertServiceFactory::GetForProfile( |
| 306 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); | 333 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); |
| 307 if (service && service->UsedPolicyCertificates()) | 334 if (service && service->UsedPolicyCertificates()) |
| 308 return true; | 335 return true; |
| 309 #endif | 336 #endif |
| 310 return false; | 337 return false; |
| 311 } | 338 } |
| 312 | 339 |
| 313 bool ChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) { | 340 bool ChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) { |
| 314 return content::IsOriginSecure(url); | 341 return content::IsOriginSecure(url); |
| 315 } | 342 } |
| 316 | 343 |
| 344 void ChromeSecurityStateModelClient::DidFinishNavigation( | |
| 345 content::NavigationHandle* navigation_handle) { | |
| 346 if (navigation_handle->IsInMainFrame()) { | |
| 347 logged_http_warning_on_current_navigation_ = false; | |
| 348 } | |
|
meacer
2016/10/13 17:41:01
Should we clear this bit when there is a new navig
estark
2016/10/13 17:59:17
(will revisit this comment once I settle the quest
estark
2016/10/14 17:57:06
I think it's more correct to clear the flag when t
| |
| 349 } | |
| 350 | |
| 317 void ChromeSecurityStateModelClient::GetVisibleSecurityState( | 351 void ChromeSecurityStateModelClient::GetVisibleSecurityState( |
| 318 SecurityStateModel::VisibleSecurityState* state) { | 352 SecurityStateModel::VisibleSecurityState* state) { |
| 319 content::NavigationEntry* entry = | 353 content::NavigationEntry* entry = |
| 320 web_contents_->GetController().GetVisibleEntry(); | 354 web_contents_->GetController().GetVisibleEntry(); |
| 321 if (!entry) { | 355 if (!entry) { |
| 322 *state = SecurityStateModel::VisibleSecurityState(); | 356 *state = SecurityStateModel::VisibleSecurityState(); |
| 323 return; | 357 return; |
| 324 } | 358 } |
| 325 | 359 |
| 326 if (!entry->GetSSL().initialized) { | 360 if (!entry->GetSSL().initialized) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 355 !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS); | 389 !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS); |
| 356 state->displayed_password_field_on_http = | 390 state->displayed_password_field_on_http = |
| 357 !!(ssl.content_status & | 391 !!(ssl.content_status & |
| 358 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 392 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 359 state->displayed_credit_card_field_on_http = | 393 state->displayed_credit_card_field_on_http = |
| 360 !!(ssl.content_status & | 394 !!(ssl.content_status & |
| 361 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | 395 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); |
| 362 | 396 |
| 363 CheckSafeBrowsingStatus(entry, web_contents_, state); | 397 CheckSafeBrowsingStatus(entry, web_contents_, state); |
| 364 } | 398 } |
| OLD | NEW |