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

Side by Side Diff: chrome/browser/ssl/security_state_model.cc

Issue 1470813002: Add SecurityStateModelClient interface and implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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_delegate.h"
12 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/cert_store.h" 17 #include "content/public/browser/cert_store.h"
17 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/origin_util.h" 21 #include "content/public/common/origin_util.h"
21 #include "net/ssl/ssl_cipher_suite_names.h" 22 #include "net/ssl/ssl_cipher_suite_names.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 109
109 return SecurityStateModel::NO_MIXED_CONTENT; 110 return SecurityStateModel::NO_MIXED_CONTENT;
110 } 111 }
111 112
112 SecurityStateModel::SecurityLevel GetSecurityLevelForRequest( 113 SecurityStateModel::SecurityLevel GetSecurityLevelForRequest(
113 const GURL& url, 114 const GURL& url,
114 const content::SSLStatus& ssl, 115 const content::SSLStatus& ssl,
115 Profile* profile, 116 Profile* profile,
116 scoped_refptr<net::X509Certificate> cert, 117 scoped_refptr<net::X509Certificate> cert,
117 SecurityStateModel::SHA1DeprecationStatus sha1_status, 118 SecurityStateModel::SHA1DeprecationStatus sha1_status,
118 SecurityStateModel::MixedContentStatus mixed_content_status) { 119 SecurityStateModel::MixedContentStatus mixed_content_status,
120 bool used_known_mitm_certificate) {
119 switch (ssl.security_style) { 121 switch (ssl.security_style) {
120 case content::SECURITY_STYLE_UNKNOWN: 122 case content::SECURITY_STYLE_UNKNOWN:
121 return SecurityStateModel::NONE; 123 return SecurityStateModel::NONE;
122 124
123 case content::SECURITY_STYLE_UNAUTHENTICATED: { 125 case content::SECURITY_STYLE_UNAUTHENTICATED: {
124 if (!content::IsOriginSecure(url) && url.IsStandard()) 126 if (!content::IsOriginSecure(url) && url.IsStandard())
125 return GetSecurityLevelForNonSecureFieldTrial(); 127 return GetSecurityLevelForNonSecureFieldTrial();
126 return SecurityStateModel::NONE; 128 return SecurityStateModel::NONE;
127 } 129 }
128 130
129 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: 131 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN:
130 return SecurityStateModel::SECURITY_ERROR; 132 return SecurityStateModel::SECURITY_ERROR;
131 133
132 case content::SECURITY_STYLE_WARNING: 134 case content::SECURITY_STYLE_WARNING:
133 NOTREACHED(); 135 NOTREACHED();
134 return SecurityStateModel::SECURITY_WARNING; 136 return SecurityStateModel::SECURITY_WARNING;
135 137
136 case content::SECURITY_STYLE_AUTHENTICATED: { 138 case content::SECURITY_STYLE_AUTHENTICATED: {
137 #if defined(OS_CHROMEOS) 139 if (used_known_mitm_certificate)
138 // Report if there is a policy cert first, before reporting any other
139 // authenticated-but-with-errors cases. A policy cert is a strong
140 // indicator of a MITM being present (the enterprise), while the
141 // other authenticated-but-with-errors indicate something may
142 // be wrong, or may be wrong in the future, but is unclear now.
143 policy::PolicyCertService* service =
144 policy::PolicyCertServiceFactory::GetForProfile(profile);
145 if (service && service->UsedPolicyCertificates())
146 return SecurityStateModel::SECURITY_POLICY_WARNING; 140 return SecurityStateModel::SECURITY_POLICY_WARNING;
147 #endif
148 141
149 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MAJOR) 142 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MAJOR)
150 return SecurityStateModel::SECURITY_ERROR; 143 return SecurityStateModel::SECURITY_ERROR;
151 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MINOR) 144 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MINOR)
152 return SecurityStateModel::NONE; 145 return SecurityStateModel::NONE;
153 146
154 // Active mixed content is downgraded to the BROKEN style and 147 // Active mixed content is downgraded to the BROKEN style and
155 // handled above. 148 // handled above.
156 DCHECK_NE(SecurityStateModel::RAN_MIXED_CONTENT, mixed_content_status); 149 DCHECK_NE(SecurityStateModel::RAN_MIXED_CONTENT, mixed_content_status);
157 DCHECK_NE(SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, 150 DCHECK_NE(SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 visible_url_ = GURL(); 208 visible_url_ = GURL();
216 visible_ssl_status_ = content::SSLStatus(); 209 visible_ssl_status_ = content::SSLStatus();
217 return security_info_; 210 return security_info_;
218 } 211 }
219 212
220 if (entry->GetURL() == visible_url_ && 213 if (entry->GetURL() == visible_url_ &&
221 entry->GetSSL().Equals(visible_ssl_status_)) { 214 entry->GetSSL().Equals(visible_ssl_status_)) {
222 // A cert must be present in the CertStore in order for the site to 215 // A cert must be present in the CertStore in order for the site to
223 // be considered EV_SECURE, and the cert might have been removed 216 // be considered EV_SECURE, and the cert might have been removed
224 // since the security level was last computed. 217 // since the security level was last computed.
218 scoped_refptr<net::X509Certificate> cert;
225 if (security_info_.security_level == EV_SECURE && 219 if (security_info_.security_level == EV_SECURE &&
226 !GetCertForSSLStatus(visible_ssl_status_)) { 220 !delegate_->RetrieveCert(&cert)) {
blundell 2015/11/23 16:06:17 Should this method be going away in this CL?
estark 2015/11/23 16:23:39 Not quite yet, but it will be going away in one of
227 security_info_.security_level = SECURE; 221 security_info_.security_level = SECURE;
228 } 222 }
229 return security_info_; 223 return security_info_;
230 } 224 }
231 225
232 SecurityInfoForRequest( 226 SecurityInfoForRequest(
233 entry->GetURL(), entry->GetSSL(), 227 entry->GetURL(), entry->GetSSL(),
234 Profile::FromBrowserContext(web_contents_->GetBrowserContext()), 228 Profile::FromBrowserContext(web_contents_->GetBrowserContext()),
235 &security_info_); 229 delegate_->UsedKnownMITMCertificate(), &security_info_);
236 visible_url_ = entry->GetURL(); 230 visible_url_ = entry->GetURL();
237 visible_ssl_status_ = entry->GetSSL(); 231 visible_ssl_status_ = entry->GetSSL();
238 return security_info_; 232 return security_info_;
239 } 233 }
240 234
241 // static 235 // static
242 void SecurityStateModel::SecurityInfoForRequest(const GURL& url, 236 void SecurityStateModel::SecurityInfoForRequest(
243 const content::SSLStatus& ssl, 237 const GURL& url,
244 Profile* profile, 238 const content::SSLStatus& ssl,
245 SecurityInfo* security_info) { 239 Profile* profile,
240 bool used_known_mitm_certificate,
241 SecurityInfo* security_info) {
246 scoped_refptr<net::X509Certificate> cert = GetCertForSSLStatus(ssl); 242 scoped_refptr<net::X509Certificate> cert = GetCertForSSLStatus(ssl);
247 security_info->cert_id = ssl.cert_id; 243 security_info->cert_id = ssl.cert_id;
248 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl); 244 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl);
249 security_info->mixed_content_status = GetMixedContentStatus(ssl); 245 security_info->mixed_content_status = GetMixedContentStatus(ssl);
250 security_info->security_bits = ssl.security_bits; 246 security_info->security_bits = ssl.security_bits;
251 security_info->connection_status = ssl.connection_status; 247 security_info->connection_status = ssl.connection_status;
252 security_info->cert_status = ssl.cert_status; 248 security_info->cert_status = ssl.cert_status;
253 security_info->scheme_is_cryptographic = url.SchemeIsCryptographic(); 249 security_info->scheme_is_cryptographic = url.SchemeIsCryptographic();
254 security_info->is_secure_protocol_and_ciphersuite = 250 security_info->is_secure_protocol_and_ciphersuite =
255 (net::SSLConnectionStatusToVersion(ssl.connection_status) >= 251 (net::SSLConnectionStatusToVersion(ssl.connection_status) >=
256 net::SSL_CONNECTION_VERSION_TLS1_2 && 252 net::SSL_CONNECTION_VERSION_TLS1_2 &&
257 net::IsSecureTLSCipherSuite( 253 net::IsSecureTLSCipherSuite(
258 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))); 254 net::SSLConnectionStatusToCipherSuite(ssl.connection_status)));
259 255
260 security_info->sct_verify_statuses.clear(); 256 security_info->sct_verify_statuses.clear();
261 for (const auto& sct : ssl.signed_certificate_timestamp_ids) { 257 for (const auto& sct : ssl.signed_certificate_timestamp_ids) {
262 security_info->sct_verify_statuses.push_back(sct.status); 258 security_info->sct_verify_statuses.push_back(sct.status);
263 } 259 }
264 260
265 security_info->security_level = GetSecurityLevelForRequest( 261 security_info->security_level = GetSecurityLevelForRequest(
266 url, ssl, profile, cert, security_info->sha1_deprecation_status, 262 url, ssl, profile, cert, security_info->sha1_deprecation_status,
267 security_info->mixed_content_status); 263 security_info->mixed_content_status, used_known_mitm_certificate);
268 } 264 }
269 265
270 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents) 266 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents)
271 : web_contents_(web_contents) {} 267 : web_contents_(web_contents),
268 delegate_(new ChromeSecurityStateModelDelegate(web_contents)) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698