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

Side by Side Diff: components/security_state/content/content_utils.cc

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: sync. Created 4 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 2016 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 "components/security_state/content/content_utils.h"
6 6
7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/command_line.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "components/security_state/core/security_state.h"
15 #include "chrome/browser/browser_process.h" 15 #include "components/strings/grit/components_chromium_strings.h"
16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 16 #include "components/strings/grit/components_strings.h"
17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
20 #include "chrome/browser/safe_browsing/ui_manager.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h"
23 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/navigation_handle.h"
25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/security_style_explanation.h" 18 #include "content/public/browser/security_style_explanation.h"
27 #include "content/public/browser/security_style_explanations.h" 19 #include "content/public/browser/security_style_explanations.h"
28 #include "content/public/browser/ssl_status.h" 20 #include "content/public/browser/ssl_status.h"
29 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/origin_util.h" 22 #include "content/public/common/content_client.h"
31 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
32 #include "net/cert/x509_certificate.h" 24 #include "net/cert/x509_certificate.h"
33 #include "net/ssl/ssl_cipher_suite_names.h" 25 #include "net/ssl/ssl_cipher_suite_names.h"
34 #include "net/ssl/ssl_connection_status_flags.h" 26 #include "net/ssl/ssl_connection_status_flags.h"
35 #include "third_party/boringssl/src/include/openssl/ssl.h" 27 #include "third_party/boringssl/src/include/openssl/ssl.h"
36 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
37 29
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModelClient); 30 namespace security_state {
39
40 using safe_browsing::SafeBrowsingUIManager;
41 using security_state::SecurityStateModel;
42 31
43 namespace { 32 namespace {
44 33
45 // Note: This is a lossy operation. Not all of the policies that can be 34 // Note: This is a lossy operation. Not all of the policies that can be
46 // expressed by a SecurityLevel (a //chrome concept) can be expressed by 35 // expressed by a SecurityLevel can be expressed by a blink::WebSecurityStyle.
47 // a blink::WebSecurityStyle.
48 blink::WebSecurityStyle SecurityLevelToSecurityStyle( 36 blink::WebSecurityStyle SecurityLevelToSecurityStyle(
49 SecurityStateModel::SecurityLevel security_level) { 37 security_state::SecurityLevel security_level) {
50 switch (security_level) { 38 switch (security_level) {
51 case SecurityStateModel::NONE: 39 case security_state::NONE:
52 case SecurityStateModel::HTTP_SHOW_WARNING: 40 case security_state::HTTP_SHOW_WARNING:
53 return blink::WebSecurityStyleUnauthenticated; 41 return blink::WebSecurityStyleUnauthenticated;
54 case SecurityStateModel::SECURITY_WARNING: 42 case security_state::SECURITY_WARNING:
55 case SecurityStateModel::SECURE_WITH_POLICY_INSTALLED_CERT: 43 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT:
56 return blink::WebSecurityStyleWarning; 44 return blink::WebSecurityStyleWarning;
57 case SecurityStateModel::EV_SECURE: 45 case security_state::EV_SECURE:
58 case SecurityStateModel::SECURE: 46 case security_state::SECURE:
59 return blink::WebSecurityStyleAuthenticated; 47 return blink::WebSecurityStyleAuthenticated;
60 case SecurityStateModel::DANGEROUS: 48 case security_state::DANGEROUS:
61 return blink::WebSecurityStyleAuthenticationBroken; 49 return blink::WebSecurityStyleAuthenticationBroken;
62 } 50 }
63 51
64 NOTREACHED(); 52 NOTREACHED();
65 return blink::WebSecurityStyleUnknown; 53 return blink::WebSecurityStyleUnknown;
66 } 54 }
67 55
68 void AddConnectionExplanation( 56 void AddConnectionExplanation(
69 const security_state::SecurityStateModel::SecurityInfo& security_info, 57 const security_state::SecurityInfo& security_info,
70 content::SecurityStyleExplanations* security_style_explanations) { 58 content::SecurityStyleExplanations* security_style_explanations) {
71
72 // Avoid showing TLS details when we couldn't even establish a TLS connection 59 // Avoid showing TLS details when we couldn't even establish a TLS connection
73 // (e.g. for net errors) or if there was no real connection (some tests). We 60 // (e.g. for net errors) or if there was no real connection (some tests). We
74 // check the |connection_status| to see if there was a connection. 61 // check the |connection_status| to see if there was a connection.
75 if (security_info.connection_status == 0) { 62 if (security_info.connection_status == 0) {
76 return; 63 return;
77 } 64 }
78 65
79 int ssl_version = 66 int ssl_version =
80 net::SSLConnectionStatusToVersion(security_info.connection_status); 67 net::SSLConnectionStatusToVersion(security_info.connection_status);
81 const char* protocol; 68 const char* protocol;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 description_replacements.push_back(cipher_name); 128 description_replacements.push_back(cipher_name);
142 129
143 security_style_explanations->info_explanations.push_back( 130 security_style_explanations->info_explanations.push_back(
144 content::SecurityStyleExplanation( 131 content::SecurityStyleExplanation(
145 l10n_util::GetStringUTF8(IDS_OBSOLETE_SSL_SUMMARY), 132 l10n_util::GetStringUTF8(IDS_OBSOLETE_SSL_SUMMARY),
146 base::UTF16ToUTF8( 133 base::UTF16ToUTF8(
147 l10n_util::GetStringFUTF16(IDS_OBSOLETE_SSL_DESCRIPTION, 134 l10n_util::GetStringFUTF16(IDS_OBSOLETE_SSL_DESCRIPTION,
148 description_replacements, nullptr)))); 135 description_replacements, nullptr))));
149 } 136 }
150 137
151 // Check to see whether the security state should be downgraded to reflect
152 // a Safe Browsing verdict.
153 void CheckSafeBrowsingStatus(content::NavigationEntry* entry,
154 content::WebContents* web_contents,
155 SecurityStateModel::VisibleSecurityState* state) {
156 safe_browsing::SafeBrowsingService* sb_service =
157 g_browser_process->safe_browsing_service();
158 if (!sb_service)
159 return;
160 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager();
161 safe_browsing::SBThreatType threat_type;
162 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents(
163 entry->GetURL(), false, entry, web_contents, false, &threat_type)) {
164 switch (threat_type) {
165 case safe_browsing::SB_THREAT_TYPE_SAFE:
166 break;
167 case safe_browsing::SB_THREAT_TYPE_URL_PHISHING:
168 case safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL:
169 state->malicious_content_status = security_state::SecurityStateModel::
170 MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING;
171 break;
172 case safe_browsing::SB_THREAT_TYPE_URL_MALWARE:
173 case safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL:
174 state->malicious_content_status = security_state::SecurityStateModel::
175 MALICIOUS_CONTENT_STATUS_MALWARE;
176 break;
177 case safe_browsing::SB_THREAT_TYPE_URL_UNWANTED:
178 state->malicious_content_status = security_state::SecurityStateModel::
179 MALICIOUS_CONTENT_STATUS_UNWANTED_SOFTWARE;
180 break;
181 case safe_browsing::SB_THREAT_TYPE_BINARY_MALWARE_URL:
182 case safe_browsing::SB_THREAT_TYPE_EXTENSION:
183 case safe_browsing::SB_THREAT_TYPE_BLACKLISTED_RESOURCE:
184 case safe_browsing::SB_THREAT_TYPE_API_ABUSE:
185 // These threat types are not currently associated with
186 // interstitials, and thus resources with these threat types are
187 // not ever whitelisted or pending whitelisting.
188 NOTREACHED();
189 break;
190 }
191 }
192 }
193
194 } // namespace 138 } // namespace
195 139
196 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( 140 std::unique_ptr<security_state::VisibleSecurityState> GetVisibleSecurityState(
197 content::WebContents* web_contents) 141 content::WebContents* web_contents) {
198 : content::WebContentsObserver(web_contents), 142 auto state = base::MakeUnique<security_state::VisibleSecurityState>();
199 web_contents_(web_contents), 143
200 security_state_model_(new SecurityStateModel()), 144 content::NavigationEntry* entry =
201 logged_http_warning_on_current_navigation_(false) { 145 web_contents->GetController().GetVisibleEntry();
202 security_state_model_->SetClient(this); 146 if (!entry || !entry->GetSSL().initialized)
147 return state;
148
149 state->connection_info_initialized = true;
150 state->url = entry->GetURL();
151 const content::SSLStatus& ssl = entry->GetSSL();
152 state->certificate = ssl.certificate;
153 state->cert_status = ssl.cert_status;
154 state->connection_status = ssl.connection_status;
155 state->key_exchange_group = ssl.key_exchange_group;
156 state->security_bits = ssl.security_bits;
157 state->pkp_bypassed = ssl.pkp_bypassed;
158 state->sct_verify_statuses.clear();
159 state->sct_verify_statuses.insert(state->sct_verify_statuses.begin(),
160 ssl.sct_statuses.begin(),
161 ssl.sct_statuses.end());
162 state->displayed_mixed_content =
163 !!(ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT);
164 state->ran_mixed_content =
165 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
166 state->displayed_content_with_cert_errors =
167 !!(ssl.content_status &
168 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS);
169 state->ran_content_with_cert_errors =
170 !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS);
171 state->displayed_password_field_on_http =
172 !!(ssl.content_status &
173 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
174 state->displayed_credit_card_field_on_http =
175 !!(ssl.content_status &
176 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
177
178 return state;
203 } 179 }
204 180
205 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} 181 blink::WebSecurityStyle GetSecurityStyle(
206 182 const security_state::SecurityInfo& security_info,
207 // static
208 blink::WebSecurityStyle ChromeSecurityStateModelClient::GetSecurityStyle(
209 const security_state::SecurityStateModel::SecurityInfo& security_info,
210 content::SecurityStyleExplanations* security_style_explanations) { 183 content::SecurityStyleExplanations* security_style_explanations) {
211 const blink::WebSecurityStyle security_style = 184 const blink::WebSecurityStyle security_style =
212 SecurityLevelToSecurityStyle(security_info.security_level); 185 SecurityLevelToSecurityStyle(security_info.security_level);
213 186
214 if (security_info.security_level == 187 if (security_info.security_level == security_state::HTTP_SHOW_WARNING) {
215 security_state::SecurityStateModel::HTTP_SHOW_WARNING) {
216 // If the HTTP_SHOW_WARNING field trial is in use, display an 188 // If the HTTP_SHOW_WARNING field trial is in use, display an
217 // unauthenticated explanation explaining why the omnibox warning is 189 // unauthenticated explanation explaining why the omnibox warning is
218 // present. 190 // present.
219 security_style_explanations->unauthenticated_explanations.push_back( 191 security_style_explanations->unauthenticated_explanations.push_back(
220 content::SecurityStyleExplanation( 192 content::SecurityStyleExplanation(
221 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), 193 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT),
222 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT_DESCRIPTION))); 194 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT_DESCRIPTION)));
223 } else if (security_info.security_level == 195 } else if (security_info.security_level == security_state::NONE &&
224 security_state::SecurityStateModel::NONE &&
225 (security_info.displayed_password_field_on_http || 196 (security_info.displayed_password_field_on_http ||
226 security_info.displayed_credit_card_field_on_http)) { 197 security_info.displayed_credit_card_field_on_http)) {
227 // If the HTTP_SHOW_WARNING field trial isn't in use yet, display an 198 // If the HTTP_SHOW_WARNING field trial isn't in use yet, display an
228 // informational note that the omnibox will contain a warning for 199 // informational note that the omnibox will contain a warning for
229 // this site in a future version of Chrome. 200 // this site in a future version of Chrome.
230 security_style_explanations->info_explanations.push_back( 201 security_style_explanations->info_explanations.push_back(
231 content::SecurityStyleExplanation( 202 content::SecurityStyleExplanation(
232 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), 203 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT),
233 l10n_util::GetStringUTF8( 204 l10n_util::GetStringUTF8(
234 IDS_PRIVATE_USER_DATA_INPUT_FUTURE_DESCRIPTION))); 205 IDS_PRIVATE_USER_DATA_INPUT_FUTURE_DESCRIPTION)));
235 } 206 }
236 207
237 security_style_explanations->ran_insecure_content_style = 208 security_style_explanations->ran_insecure_content_style =
238 SecurityLevelToSecurityStyle( 209 SecurityLevelToSecurityStyle(security_state::kRanInsecureContentLevel);
239 SecurityStateModel::kRanInsecureContentLevel);
240 security_style_explanations->displayed_insecure_content_style = 210 security_style_explanations->displayed_insecure_content_style =
241 SecurityLevelToSecurityStyle( 211 SecurityLevelToSecurityStyle(
242 SecurityStateModel::kDisplayedInsecureContentLevel); 212 security_state::kDisplayedInsecureContentLevel);
243 213
244 // Check if the page is HTTP; if so, no more explanations are needed. Note 214 // Check if the page is HTTP; if so, no more explanations are needed. Note
245 // that SecurityStyleUnauthenticated does not necessarily mean that 215 // that SecurityStyleUnauthenticated does not necessarily mean that
246 // the page is loaded over HTTP, because the security style merely 216 // the page is loaded over HTTP, because the security style merely
247 // represents how the embedder wishes to display the security state of 217 // represents how the embedder wishes to display the security state of
248 // the page, and the embedder can choose to display HTTPS page as HTTP 218 // the page, and the embedder can choose to display HTTPS page as HTTP
249 // if it wants to (for example, displaying deprecated crypto 219 // if it wants to (for example, displaying deprecated crypto
250 // algorithms with the same UI treatment as HTTP pages). 220 // algorithms with the same UI treatment as HTTP pages).
251 security_style_explanations->scheme_is_cryptographic = 221 security_style_explanations->scheme_is_cryptographic =
252 security_info.scheme_is_cryptographic; 222 security_info.scheme_is_cryptographic;
253 if (!security_info.scheme_is_cryptographic) { 223 if (!security_info.scheme_is_cryptographic) {
254 return security_style; 224 return security_style;
255 } 225 }
256 226
257 if (security_info.sha1_deprecation_status == 227 if (security_info.sha1_deprecation_status ==
258 SecurityStateModel::DEPRECATED_SHA1_MAJOR) { 228 security_state::DEPRECATED_SHA1_MAJOR) {
259 security_style_explanations->broken_explanations.push_back( 229 security_style_explanations->broken_explanations.push_back(
260 content::SecurityStyleExplanation( 230 content::SecurityStyleExplanation(
261 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1), 231 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1),
262 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION), 232 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION),
263 !!security_info.certificate)); 233 !!security_info.certificate));
264 } else if (security_info.sha1_deprecation_status == 234 } else if (security_info.sha1_deprecation_status ==
265 SecurityStateModel::DEPRECATED_SHA1_MINOR) { 235 security_state::DEPRECATED_SHA1_MINOR) {
266 security_style_explanations->unauthenticated_explanations.push_back( 236 security_style_explanations->unauthenticated_explanations.push_back(
267 content::SecurityStyleExplanation( 237 content::SecurityStyleExplanation(
268 l10n_util::GetStringUTF8(IDS_MINOR_SHA1), 238 l10n_util::GetStringUTF8(IDS_MINOR_SHA1),
269 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION), 239 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION),
270 !!security_info.certificate)); 240 !!security_info.certificate));
271 } 241 }
272 242
273 // Record the presence of mixed content (HTTP subresources on an HTTPS 243 // Record the presence of mixed content (HTTP subresources on an HTTPS
274 // page). 244 // page).
275 security_style_explanations->ran_mixed_content = 245 security_style_explanations->ran_mixed_content =
276 security_info.mixed_content_status == 246 security_info.mixed_content_status ==
277 SecurityStateModel::CONTENT_STATUS_RAN || 247 security_state::CONTENT_STATUS_RAN ||
278 security_info.mixed_content_status == 248 security_info.mixed_content_status ==
279 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 249 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
280 security_style_explanations->displayed_mixed_content = 250 security_style_explanations->displayed_mixed_content =
281 security_info.mixed_content_status == 251 security_info.mixed_content_status ==
282 SecurityStateModel::CONTENT_STATUS_DISPLAYED || 252 security_state::CONTENT_STATUS_DISPLAYED ||
283 security_info.mixed_content_status == 253 security_info.mixed_content_status ==
284 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 254 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
285 255
286 bool is_cert_status_error = net::IsCertStatusError(security_info.cert_status); 256 bool is_cert_status_error = net::IsCertStatusError(security_info.cert_status);
287 bool is_cert_status_minor_error = 257 bool is_cert_status_minor_error =
288 net::IsCertStatusMinorError(security_info.cert_status); 258 net::IsCertStatusMinorError(security_info.cert_status);
289 259
290 // If the main resource was loaded no certificate errors or only minor 260 // If the main resource was loaded no certificate errors or only minor
291 // certificate errors, then record the presence of subresources with 261 // certificate errors, then record the presence of subresources with
292 // certificate errors. Subresource certificate errors aren't recorded 262 // certificate errors. Subresource certificate errors aren't recorded
293 // when the main resource was loaded with major certificate errors 263 // when the main resource was loaded with major certificate errors
294 // because, in the common case, these subresource certificate errors 264 // because, in the common case, these subresource certificate errors
295 // would be duplicative with the main resource's error. 265 // would be duplicative with the main resource's error.
296 if (!is_cert_status_error || is_cert_status_minor_error) { 266 if (!is_cert_status_error || is_cert_status_minor_error) {
297 security_style_explanations->ran_content_with_cert_errors = 267 security_style_explanations->ran_content_with_cert_errors =
298 security_info.content_with_cert_errors_status == 268 security_info.content_with_cert_errors_status ==
299 SecurityStateModel::CONTENT_STATUS_RAN || 269 security_state::CONTENT_STATUS_RAN ||
300 security_info.content_with_cert_errors_status == 270 security_info.content_with_cert_errors_status ==
301 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 271 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
302 security_style_explanations->displayed_content_with_cert_errors = 272 security_style_explanations->displayed_content_with_cert_errors =
303 security_info.content_with_cert_errors_status == 273 security_info.content_with_cert_errors_status ==
304 SecurityStateModel::CONTENT_STATUS_DISPLAYED || 274 security_state::CONTENT_STATUS_DISPLAYED ||
305 security_info.content_with_cert_errors_status == 275 security_info.content_with_cert_errors_status ==
306 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 276 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
307 } 277 }
308 278
309 if (is_cert_status_error) { 279 if (is_cert_status_error) {
310 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString( 280 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(
311 net::MapCertStatusToNetError(security_info.cert_status))); 281 net::MapCertStatusToNetError(security_info.cert_status)));
312 282
313 content::SecurityStyleExplanation explanation( 283 content::SecurityStyleExplanation explanation(
314 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), 284 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
315 l10n_util::GetStringFUTF8( 285 l10n_util::GetStringFUTF8(
316 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), 286 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
317 !!security_info.certificate); 287 !!security_info.certificate);
318 288
319 if (is_cert_status_minor_error) { 289 if (is_cert_status_minor_error) {
320 security_style_explanations->unauthenticated_explanations.push_back( 290 security_style_explanations->unauthenticated_explanations.push_back(
321 explanation); 291 explanation);
322 } else { 292 } else {
323 security_style_explanations->broken_explanations.push_back(explanation); 293 security_style_explanations->broken_explanations.push_back(explanation);
324 } 294 }
325 } else { 295 } else {
326 // If the certificate does not have errors and is not using 296 // If the certificate does not have errors and is not using
327 // deprecated SHA1, then add an explanation that the certificate is 297 // deprecated SHA1, then add an explanation that the certificate is
328 // valid. 298 // valid.
329 if (security_info.sha1_deprecation_status == 299 if (security_info.sha1_deprecation_status ==
330 SecurityStateModel::NO_DEPRECATED_SHA1) { 300 security_state::NO_DEPRECATED_SHA1) {
331 security_style_explanations->secure_explanations.push_back( 301 security_style_explanations->secure_explanations.push_back(
332 content::SecurityStyleExplanation( 302 content::SecurityStyleExplanation(
333 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), 303 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE),
334 l10n_util::GetStringUTF8( 304 l10n_util::GetStringUTF8(
335 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), 305 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION),
336 !!security_info.certificate)); 306 !!security_info.certificate));
337 } 307 }
338 } 308 }
339 309
340 AddConnectionExplanation(security_info, security_style_explanations); 310 AddConnectionExplanation(security_info, security_style_explanations);
341 311
342 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed; 312 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed;
343 if (security_info.pkp_bypassed) { 313 if (security_info.pkp_bypassed) {
344 security_style_explanations->info_explanations.push_back( 314 security_style_explanations->info_explanations.push_back(
345 content::SecurityStyleExplanation( 315 content::SecurityStyleExplanation(
346 "Public-Key Pinning Bypassed", 316 "Public-Key Pinning Bypassed",
347 "Public-key pinning was bypassed by a local root certificate.")); 317 "Public-key pinning was bypassed by a local root certificate."));
348 } 318 }
349 319
350 return security_style; 320 return security_style;
351 } 321 }
352 322
353 void ChromeSecurityStateModelClient::GetSecurityInfo( 323 } // namespace security_state
354 SecurityStateModel::SecurityInfo* result) const {
355 security_state_model_->GetSecurityInfo(result);
356 }
357
358 void ChromeSecurityStateModelClient::VisibleSecurityStateChanged() {
359 if (logged_http_warning_on_current_navigation_)
360 return;
361
362 security_state::SecurityStateModel::SecurityInfo security_info;
363 GetSecurityInfo(&security_info);
364 if (!security_info.displayed_password_field_on_http &&
365 !security_info.displayed_credit_card_field_on_http) {
366 return;
367 }
368
369 std::string warning;
370 bool warning_is_user_visible = false;
371 switch (security_info.security_level) {
372 case security_state::SecurityStateModel::HTTP_SHOW_WARNING:
373 warning =
374 "This page includes a password or credit card input in a non-secure "
375 "context. A warning has been added to the URL bar. For more "
376 "information, see https://goo.gl/zmWq3m.";
377 warning_is_user_visible = true;
378 break;
379 case security_state::SecurityStateModel::NONE:
380 case security_state::SecurityStateModel::DANGEROUS:
381 warning =
382 "This page includes a password or credit card input in a non-secure "
383 "context. A warning will be added to the URL bar in Chrome 56 (Jan "
384 "2017). For more information, see https://goo.gl/zmWq3m.";
385 break;
386 default:
387 return;
388 }
389
390 logged_http_warning_on_current_navigation_ = true;
391 web_contents_->GetMainFrame()->AddMessageToConsole(
392 content::CONSOLE_MESSAGE_LEVEL_WARNING, warning);
393
394 if (security_info.displayed_credit_card_field_on_http) {
395 UMA_HISTOGRAM_BOOLEAN(
396 "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard",
397 warning_is_user_visible);
398 }
399 if (security_info.displayed_password_field_on_http) {
400 UMA_HISTOGRAM_BOOLEAN(
401 "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password",
402 warning_is_user_visible);
403 }
404 }
405
406 void ChromeSecurityStateModelClient::DidFinishNavigation(
407 content::NavigationHandle* navigation_handle) {
408 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) {
409 // Only reset the console message flag for main-frame navigations,
410 // and not for same-page navigations like reference fragments and pushState.
411 logged_http_warning_on_current_navigation_ = false;
412 }
413 }
414
415 bool ChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() {
416 #if defined(OS_CHROMEOS)
417 policy::PolicyCertService* service =
418 policy::PolicyCertServiceFactory::GetForProfile(
419 Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
420 if (service && service->UsedPolicyCertificates())
421 return true;
422 #endif
423 return false;
424 }
425
426 bool ChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) {
427 return content::IsOriginSecure(url);
428 }
429
430 void ChromeSecurityStateModelClient::GetVisibleSecurityState(
431 SecurityStateModel::VisibleSecurityState* state) {
432 content::NavigationEntry* entry =
433 web_contents_->GetController().GetVisibleEntry();
434 if (!entry) {
435 *state = SecurityStateModel::VisibleSecurityState();
436 return;
437 }
438
439 if (!entry->GetSSL().initialized) {
440 *state = SecurityStateModel::VisibleSecurityState();
441 // Connection security information is still being initialized, but malware
442 // status might already be known.
443 CheckSafeBrowsingStatus(entry, web_contents_, state);
444 return;
445 }
446
447 state->connection_info_initialized = true;
448 state->url = entry->GetURL();
449 const content::SSLStatus& ssl = entry->GetSSL();
450 state->certificate = ssl.certificate;
451 state->cert_status = ssl.cert_status;
452 state->connection_status = ssl.connection_status;
453 state->key_exchange_group = ssl.key_exchange_group;
454 state->security_bits = ssl.security_bits;
455 state->pkp_bypassed = ssl.pkp_bypassed;
456 state->sct_verify_statuses.clear();
457 state->sct_verify_statuses.insert(state->sct_verify_statuses.begin(),
458 ssl.sct_statuses.begin(),
459 ssl.sct_statuses.end());
460 state->displayed_mixed_content =
461 !!(ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT);
462 state->ran_mixed_content =
463 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
464 state->displayed_content_with_cert_errors =
465 !!(ssl.content_status &
466 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS);
467 state->ran_content_with_cert_errors =
468 !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS);
469 state->displayed_password_field_on_http =
470 !!(ssl.content_status &
471 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
472 state->displayed_credit_card_field_on_http =
473 !!(ssl.content_status &
474 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
475
476 CheckSafeBrowsingStatus(entry, web_contents_, state);
477 }
OLDNEW
« no previous file with comments | « components/security_state/content/content_utils.h ('k') | components/security_state/content/content_utils_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698