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

Side by Side Diff: components/security_state/security_state_model.cc

Issue 2350273002: Add SSLStatus flags to feed HTTP_WARNING security level (Closed)
Patch Set: fix comment typos Created 4 years, 3 months 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 "components/security_state/security_state_model.h" 5 #include "components/security_state/security_state_model.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "components/security_state/security_state_model_client.h" 12 #include "components/security_state/security_state_model_client.h"
13 #include "components/security_state/switches.h" 13 #include "components/security_state/switches.h"
14 #include "net/ssl/ssl_cipher_suite_names.h" 14 #include "net/ssl/ssl_cipher_suite_names.h"
15 #include "net/ssl/ssl_connection_status_flags.h" 15 #include "net/ssl/ssl_connection_status_flags.h"
16 16
17 namespace security_state { 17 namespace security_state {
18 18
19 namespace { 19 namespace {
20 20
21 SecurityStateModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() { 21 // Do not change or reorder this enum, and add new values at the end. It is used
22 // in the MarkNonSecureAs histogram.
23 enum MarkNonSecureStatus {
24 NEUTRAL,
25 DUBIOUS,
felt 2016/09/20 06:09:41 since you're updating the histogram anyway, what d
estark 2016/09/20 17:53:33 Done.
26 NON_SECURE,
27 HTTP_WARNING,
28 LAST_STATUS
29 };
30
31 // If |switch_or_field_trial_group| corresponds to a valid
32 // MarkNonSecureAs group, sets |*level| and |*histogram_status| to the
33 // appropriate values and returns true. Otherwise, returns false.
34 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
35 std::string switch_or_field_trial_group,
36 bool displayed_nonsecure_password_field,
37 bool displayed_nonsecure_credit_card_field,
38 SecurityStateModel::SecurityLevel* level,
39 MarkNonSecureStatus* histogram_status) {
40 if (switch_or_field_trial_group == switches::kMarkNonSecureAsNeutral) {
41 *level = SecurityStateModel::NONE;
42 *histogram_status = NEUTRAL;
43 return true;
44 }
45
46 if (switch_or_field_trial_group == switches::kMarkNonSecureAsNonSecure) {
47 *level = SecurityStateModel::SECURITY_ERROR;
48 *histogram_status = NON_SECURE;
49 return true;
50 }
51
52 if (switch_or_field_trial_group ==
53 switches::kMarkNonSecureWithPasswordsOrCcAsNonSecure) {
54 if (displayed_nonsecure_password_field ||
55 displayed_nonsecure_credit_card_field) {
56 *level = SecurityStateModel::HTTP_WARNING;
57 *histogram_status = HTTP_WARNING;
58 } else {
59 *level = SecurityStateModel::NONE;
60 *histogram_status = NEUTRAL;
61 }
62 return true;
63 }
64
65 return false;
66 }
67
68 SecurityStateModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial(
69 bool displayed_nonsecure_password_field,
70 bool displayed_nonsecure_credit_card_field) {
22 std::string choice = 71 std::string choice =
23 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 72 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
24 switches::kMarkNonSecureAs); 73 switches::kMarkNonSecureAs);
25 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); 74 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs");
26 75
27 // Do not change this enum. It is used in the histogram.
28 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS };
29 const char kEnumeration[] = "MarkNonSecureAs"; 76 const char kEnumeration[] = "MarkNonSecureAs";
30 77
31 SecurityStateModel::SecurityLevel level = SecurityStateModel::NONE; 78 SecurityStateModel::SecurityLevel level = SecurityStateModel::NONE;
32 MarkNonSecureStatus status; 79 MarkNonSecureStatus status;
33 80
34 if (choice == switches::kMarkNonSecureAsNeutral) { 81 // If the command-line switch is set, then it takes precedence over
35 status = NEUTRAL; 82 // the field trial group.
36 level = SecurityStateModel::NONE; 83 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
37 } else if (choice == switches::kMarkNonSecureAsNonSecure) { 84 choice, displayed_nonsecure_password_field,
38 status = NON_SECURE; 85 displayed_nonsecure_credit_card_field, &level, &status)) {
39 level = SecurityStateModel::SECURITY_ERROR; 86 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
40 } else if (group == switches::kMarkNonSecureAsNeutral || 87 group, displayed_nonsecure_password_field,
41 group == switches::kMarkNonSecureWithPasswordsOrCcAsNonSecure) { 88 displayed_nonsecure_credit_card_field, &level, &status)) {
42 status = NEUTRAL; 89 // If neither the command-line switch nor field trial group is set, then
43 level = SecurityStateModel::NONE; 90 // nonsecure defaults to neutral.
44 } else if (group == switches::kMarkNonSecureAsNonSecure) { 91 status = NEUTRAL;
45 status = NON_SECURE; 92 level = SecurityStateModel::NONE;
46 level = SecurityStateModel::SECURITY_ERROR; 93 }
47 } else {
48 status = NEUTRAL;
49 level = SecurityStateModel::NONE;
50 } 94 }
51 95
52 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); 96 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS);
53 return level; 97 return level;
54 } 98 }
55 99
56 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus( 100 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus(
57 scoped_refptr<net::X509Certificate> cert, 101 scoped_refptr<net::X509Certificate> cert,
58 const SecurityStateModel::VisibleSecurityState& visible_security_state) { 102 const SecurityStateModel::VisibleSecurityState& visible_security_state) {
59 if (!cert || 103 if (!cert ||
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 139
96 // Override the connection security information if the website failed the 140 // Override the connection security information if the website failed the
97 // browser's malware checks. 141 // browser's malware checks.
98 if (visible_security_state.fails_malware_check) 142 if (visible_security_state.fails_malware_check)
99 return SecurityStateModel::SECURITY_ERROR; 143 return SecurityStateModel::SECURITY_ERROR;
100 144
101 GURL url = visible_security_state.url; 145 GURL url = visible_security_state.url;
102 switch (visible_security_state.initial_security_level) { 146 switch (visible_security_state.initial_security_level) {
103 case SecurityStateModel::NONE: 147 case SecurityStateModel::NONE:
104 case SecurityStateModel::HTTP_WARNING: { 148 case SecurityStateModel::HTTP_WARNING: {
105 if (!client->IsOriginSecure(url) && url.IsStandard()) 149 if (!client->IsOriginSecure(url) && url.IsStandard()) {
106 return GetSecurityLevelForNonSecureFieldTrial(); 150 return GetSecurityLevelForNonSecureFieldTrial(
151 visible_security_state.displayed_nonsecure_password_field,
152 visible_security_state.displayed_nonsecure_credit_card_field);
153 }
107 return SecurityStateModel::NONE; 154 return SecurityStateModel::NONE;
108 } 155 }
109 156
110 case SecurityStateModel::SECURITY_ERROR: 157 case SecurityStateModel::SECURITY_ERROR:
111 return SecurityStateModel::SECURITY_ERROR; 158 return SecurityStateModel::SECURITY_ERROR;
112 159
113 case SecurityStateModel::SECURITY_WARNING: 160 case SecurityStateModel::SECURITY_WARNING:
114 case SecurityStateModel::SECURITY_POLICY_WARNING: 161 case SecurityStateModel::SECURITY_POLICY_WARNING:
115 return visible_security_state.initial_security_level; 162 return visible_security_state.initial_security_level;
116 163
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 fails_malware_check(false), 339 fails_malware_check(false),
293 connection_info_initialized(false), 340 connection_info_initialized(false),
294 cert_status(0), 341 cert_status(0),
295 connection_status(0), 342 connection_status(0),
296 key_exchange_group(0), 343 key_exchange_group(0),
297 security_bits(-1), 344 security_bits(-1),
298 displayed_mixed_content(false), 345 displayed_mixed_content(false),
299 ran_mixed_content(false), 346 ran_mixed_content(false),
300 displayed_content_with_cert_errors(false), 347 displayed_content_with_cert_errors(false),
301 ran_content_with_cert_errors(false), 348 ran_content_with_cert_errors(false),
302 pkp_bypassed(false) {} 349 pkp_bypassed(false),
350 displayed_nonsecure_password_field(false),
351 displayed_nonsecure_credit_card_field(false) {}
303 352
304 SecurityStateModel::VisibleSecurityState::~VisibleSecurityState() {} 353 SecurityStateModel::VisibleSecurityState::~VisibleSecurityState() {}
305 354
306 bool SecurityStateModel::VisibleSecurityState::operator==( 355 bool SecurityStateModel::VisibleSecurityState::operator==(
307 const SecurityStateModel::VisibleSecurityState& other) const { 356 const SecurityStateModel::VisibleSecurityState& other) const {
308 return (url == other.url && 357 return (url == other.url &&
309 initial_security_level == other.initial_security_level && 358 initial_security_level == other.initial_security_level &&
310 fails_malware_check == other.fails_malware_check && 359 fails_malware_check == other.fails_malware_check &&
311 !!certificate == !!other.certificate && 360 !!certificate == !!other.certificate &&
312 (certificate ? certificate->Equals(other.certificate.get()) : true) && 361 (certificate ? certificate->Equals(other.certificate.get()) : true) &&
313 connection_status == other.connection_status && 362 connection_status == other.connection_status &&
314 key_exchange_group == other.key_exchange_group && 363 key_exchange_group == other.key_exchange_group &&
315 security_bits == other.security_bits && 364 security_bits == other.security_bits &&
316 sct_verify_statuses == other.sct_verify_statuses && 365 sct_verify_statuses == other.sct_verify_statuses &&
317 displayed_mixed_content == other.displayed_mixed_content && 366 displayed_mixed_content == other.displayed_mixed_content &&
318 ran_mixed_content == other.ran_mixed_content && 367 ran_mixed_content == other.ran_mixed_content &&
319 displayed_content_with_cert_errors == 368 displayed_content_with_cert_errors ==
320 other.displayed_content_with_cert_errors && 369 other.displayed_content_with_cert_errors &&
321 ran_content_with_cert_errors == other.ran_content_with_cert_errors && 370 ran_content_with_cert_errors == other.ran_content_with_cert_errors &&
322 pkp_bypassed == other.pkp_bypassed); 371 pkp_bypassed == other.pkp_bypassed &&
372 displayed_nonsecure_password_field ==
373 other.displayed_nonsecure_password_field &&
374 displayed_nonsecure_credit_card_field ==
375 other.displayed_nonsecure_credit_card_field);
323 } 376 }
324 377
325 } // namespace security_state 378 } // namespace security_state
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698