| 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/security_state_model.h" | 5 #include "chrome/browser/ssl/security_state_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | 12 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/cert_store.h" | 17 #include "content/public/browser/cert_store.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/origin_util.h" | 21 #include "content/public/common/origin_util.h" |
| 22 #include "net/ssl/ssl_cipher_suite_names.h" | 22 #include "net/ssl/ssl_cipher_suite_names.h" |
| 23 #include "net/ssl/ssl_connection_status_flags.h" | 23 #include "net/ssl/ssl_connection_status_flags.h" |
| 24 | 24 |
| 25 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 26 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 26 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 27 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 27 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateModel); | |
| 31 | |
| 32 namespace { | 30 namespace { |
| 33 | 31 |
| 34 SecurityStateModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() { | 32 SecurityStateModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() { |
| 35 std::string choice = | 33 std::string choice = |
| 36 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 34 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 37 switches::kMarkNonSecureAs); | 35 switches::kMarkNonSecureAs); |
| 38 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); | 36 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); |
| 39 | 37 |
| 40 // Do not change this enum. It is used in the histogram. | 38 // Do not change this enum. It is used in the histogram. |
| 41 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS }; | 39 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS }; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 mixed_content_status(SecurityStateModel::NO_MIXED_CONTENT), | 185 mixed_content_status(SecurityStateModel::NO_MIXED_CONTENT), |
| 188 scheme_is_cryptographic(false), | 186 scheme_is_cryptographic(false), |
| 189 cert_status(0), | 187 cert_status(0), |
| 190 cert_id(0), | 188 cert_id(0), |
| 191 security_bits(-1), | 189 security_bits(-1), |
| 192 connection_status(0), | 190 connection_status(0), |
| 193 is_secure_protocol_and_ciphersuite(false) {} | 191 is_secure_protocol_and_ciphersuite(false) {} |
| 194 | 192 |
| 195 SecurityStateModel::SecurityInfo::~SecurityInfo() {} | 193 SecurityStateModel::SecurityInfo::~SecurityInfo() {} |
| 196 | 194 |
| 195 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents) |
| 196 : web_contents_(web_contents) {} |
| 197 |
| 197 SecurityStateModel::~SecurityStateModel() {} | 198 SecurityStateModel::~SecurityStateModel() {} |
| 198 | 199 |
| 199 const SecurityStateModel::SecurityInfo& SecurityStateModel::GetSecurityInfo() | 200 const SecurityStateModel::SecurityInfo& SecurityStateModel::GetSecurityInfo() |
| 200 const { | 201 const { |
| 201 content::NavigationEntry* entry = | 202 content::NavigationEntry* entry = |
| 202 web_contents_->GetController().GetVisibleEntry(); | 203 web_contents_->GetController().GetVisibleEntry(); |
| 203 if (!entry) { | 204 if (!entry) { |
| 204 security_info_ = SecurityInfo(); | 205 security_info_ = SecurityInfo(); |
| 205 visible_url_ = GURL(); | 206 visible_url_ = GURL(); |
| 206 visible_ssl_status_ = content::SSLStatus(); | 207 visible_ssl_status_ = content::SSLStatus(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 223 | 224 |
| 224 SecurityInfoForRequest( | 225 SecurityInfoForRequest( |
| 225 entry->GetURL(), entry->GetSSL(), | 226 entry->GetURL(), entry->GetSSL(), |
| 226 Profile::FromBrowserContext(web_contents_->GetBrowserContext()), cert, | 227 Profile::FromBrowserContext(web_contents_->GetBrowserContext()), cert, |
| 227 client_->UsedPolicyInstalledCertificate(), &security_info_); | 228 client_->UsedPolicyInstalledCertificate(), &security_info_); |
| 228 visible_url_ = entry->GetURL(); | 229 visible_url_ = entry->GetURL(); |
| 229 visible_ssl_status_ = entry->GetSSL(); | 230 visible_ssl_status_ = entry->GetSSL(); |
| 230 return security_info_; | 231 return security_info_; |
| 231 } | 232 } |
| 232 | 233 |
| 234 void SecurityStateModel::SetClient(SecurityStateModelClient* client) { |
| 235 client_ = client; |
| 236 } |
| 237 |
| 233 // static | 238 // static |
| 234 void SecurityStateModel::SecurityInfoForRequest( | 239 void SecurityStateModel::SecurityInfoForRequest( |
| 235 const GURL& url, | 240 const GURL& url, |
| 236 const content::SSLStatus& ssl, | 241 const content::SSLStatus& ssl, |
| 237 Profile* profile, | 242 Profile* profile, |
| 238 const scoped_refptr<net::X509Certificate>& cert, | 243 const scoped_refptr<net::X509Certificate>& cert, |
| 239 bool used_policy_installed_certificate, | 244 bool used_policy_installed_certificate, |
| 240 SecurityInfo* security_info) { | 245 SecurityInfo* security_info) { |
| 241 security_info->cert_id = ssl.cert_id; | 246 security_info->cert_id = ssl.cert_id; |
| 242 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl); | 247 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 253 | 258 |
| 254 security_info->sct_verify_statuses.clear(); | 259 security_info->sct_verify_statuses.clear(); |
| 255 for (const auto& sct : ssl.signed_certificate_timestamp_ids) { | 260 for (const auto& sct : ssl.signed_certificate_timestamp_ids) { |
| 256 security_info->sct_verify_statuses.push_back(sct.status); | 261 security_info->sct_verify_statuses.push_back(sct.status); |
| 257 } | 262 } |
| 258 | 263 |
| 259 security_info->security_level = GetSecurityLevelForRequest( | 264 security_info->security_level = GetSecurityLevelForRequest( |
| 260 url, ssl, profile, cert, security_info->sha1_deprecation_status, | 265 url, ssl, profile, cert, security_info->sha1_deprecation_status, |
| 261 security_info->mixed_content_status, used_policy_installed_certificate); | 266 security_info->mixed_content_status, used_policy_installed_certificate); |
| 262 } | 267 } |
| 263 | |
| 264 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents) | |
| 265 : web_contents_(web_contents), | |
| 266 client_(new ChromeSecurityStateModelClient(web_contents)) {} | |
| OLD | NEW |