| 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 "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 MarkHttpAs histogram. |
| 23 enum MarkHttpStatus { NEUTRAL, NON_SECURE, HTTP_SHOW_WARNING, LAST_STATUS }; |
| 24 |
| 25 // If |switch_or_field_trial_group| corresponds to a valid |
| 26 // MarkNonSecureAs group, sets |*level| and |*histogram_status| to the |
| 27 // appropriate values and returns true. Otherwise, returns false. |
| 28 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 29 std::string switch_or_field_trial_group, |
| 30 bool displayed_sensitive_input_on_http, |
| 31 SecurityStateModel::SecurityLevel* level, |
| 32 MarkHttpStatus* histogram_status) { |
| 33 if (switch_or_field_trial_group == switches::kMarkNonSecureAsNeutral) { |
| 34 *level = SecurityStateModel::NONE; |
| 35 *histogram_status = NEUTRAL; |
| 36 return true; |
| 37 } |
| 38 |
| 39 if (switch_or_field_trial_group == switches::kMarkNonSecureAsNonSecure) { |
| 40 *level = SecurityStateModel::SECURITY_ERROR; |
| 41 *histogram_status = NON_SECURE; |
| 42 return true; |
| 43 } |
| 44 |
| 45 if (switch_or_field_trial_group == |
| 46 switches::kMarkNonSecureWithPasswordsOrCcAsNonSecure) { |
| 47 if (displayed_sensitive_input_on_http) { |
| 48 *level = SecurityStateModel::HTTP_SHOW_WARNING; |
| 49 *histogram_status = HTTP_SHOW_WARNING; |
| 50 } else { |
| 51 *level = SecurityStateModel::NONE; |
| 52 *histogram_status = NEUTRAL; |
| 53 } |
| 54 return true; |
| 55 } |
| 56 |
| 57 return false; |
| 58 } |
| 59 |
| 60 SecurityStateModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial( |
| 61 bool displayed_sensitive_input_on_http) { |
| 22 std::string choice = | 62 std::string choice = |
| 23 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 63 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 24 switches::kMarkNonSecureAs); | 64 switches::kMarkNonSecureAs); |
| 25 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); | 65 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); |
| 26 | 66 |
| 27 // Do not change this enum. It is used in the histogram. | 67 const char kEnumeration[] = "MarkHttpAs"; |
| 28 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS }; | |
| 29 const char kEnumeration[] = "MarkNonSecureAs"; | |
| 30 | 68 |
| 31 SecurityStateModel::SecurityLevel level = SecurityStateModel::NONE; | 69 SecurityStateModel::SecurityLevel level = SecurityStateModel::NONE; |
| 32 MarkNonSecureStatus status; | 70 MarkHttpStatus status; |
| 33 | 71 |
| 34 if (choice == switches::kMarkNonSecureAsNeutral) { | 72 // If the command-line switch is set, then it takes precedence over |
| 35 status = NEUTRAL; | 73 // the field trial group. |
| 36 level = SecurityStateModel::NONE; | 74 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 37 } else if (choice == switches::kMarkNonSecureAsNonSecure) { | 75 choice, displayed_sensitive_input_on_http, &level, &status)) { |
| 38 status = NON_SECURE; | 76 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 39 level = SecurityStateModel::SECURITY_ERROR; | 77 group, displayed_sensitive_input_on_http, &level, &status)) { |
| 40 } else if (group == switches::kMarkNonSecureAsNeutral || | 78 // If neither the command-line switch nor field trial group is set, then |
| 41 group == switches::kMarkNonSecureWithPasswordsOrCcAsNonSecure) { | 79 // nonsecure defaults to neutral. |
| 42 status = NEUTRAL; | 80 status = NEUTRAL; |
| 43 level = SecurityStateModel::NONE; | 81 level = SecurityStateModel::NONE; |
| 44 } else if (group == switches::kMarkNonSecureAsNonSecure) { | 82 } |
| 45 status = NON_SECURE; | |
| 46 level = SecurityStateModel::SECURITY_ERROR; | |
| 47 } else { | |
| 48 status = NEUTRAL; | |
| 49 level = SecurityStateModel::NONE; | |
| 50 } | 83 } |
| 51 | 84 |
| 52 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); | 85 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); |
| 53 return level; | 86 return level; |
| 54 } | 87 } |
| 55 | 88 |
| 56 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus( | 89 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus( |
| 57 scoped_refptr<net::X509Certificate> cert, | 90 scoped_refptr<net::X509Certificate> cert, |
| 58 const SecurityStateModel::VisibleSecurityState& visible_security_state) { | 91 const SecurityStateModel::VisibleSecurityState& visible_security_state) { |
| 59 if (!cert || | 92 if (!cert || |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 128 |
| 96 // Override the connection security information if the website failed the | 129 // Override the connection security information if the website failed the |
| 97 // browser's malware checks. | 130 // browser's malware checks. |
| 98 if (visible_security_state.fails_malware_check) | 131 if (visible_security_state.fails_malware_check) |
| 99 return SecurityStateModel::SECURITY_ERROR; | 132 return SecurityStateModel::SECURITY_ERROR; |
| 100 | 133 |
| 101 GURL url = visible_security_state.url; | 134 GURL url = visible_security_state.url; |
| 102 switch (visible_security_state.initial_security_level) { | 135 switch (visible_security_state.initial_security_level) { |
| 103 case SecurityStateModel::NONE: | 136 case SecurityStateModel::NONE: |
| 104 case SecurityStateModel::HTTP_SHOW_WARNING: { | 137 case SecurityStateModel::HTTP_SHOW_WARNING: { |
| 105 if (!client->IsOriginSecure(url) && url.IsStandard()) | 138 if (!client->IsOriginSecure(url) && url.IsStandard()) { |
| 106 return GetSecurityLevelForNonSecureFieldTrial(); | 139 return GetSecurityLevelForNonSecureFieldTrial( |
| 140 visible_security_state.displayed_password_field_on_http || |
| 141 visible_security_state.displayed_credit_card_field_on_http); |
| 142 } |
| 107 return SecurityStateModel::NONE; | 143 return SecurityStateModel::NONE; |
| 108 } | 144 } |
| 109 | 145 |
| 110 case SecurityStateModel::SECURITY_ERROR: | 146 case SecurityStateModel::SECURITY_ERROR: |
| 111 return SecurityStateModel::SECURITY_ERROR; | 147 return SecurityStateModel::SECURITY_ERROR; |
| 112 | 148 |
| 113 case SecurityStateModel::SECURITY_WARNING: | 149 case SecurityStateModel::SECURITY_WARNING: |
| 114 case SecurityStateModel::SECURITY_POLICY_WARNING: | 150 case SecurityStateModel::SECURITY_POLICY_WARNING: |
| 115 return visible_security_state.initial_security_level; | 151 return visible_security_state.initial_security_level; |
| 116 | 152 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 fails_malware_check(false), | 328 fails_malware_check(false), |
| 293 connection_info_initialized(false), | 329 connection_info_initialized(false), |
| 294 cert_status(0), | 330 cert_status(0), |
| 295 connection_status(0), | 331 connection_status(0), |
| 296 key_exchange_group(0), | 332 key_exchange_group(0), |
| 297 security_bits(-1), | 333 security_bits(-1), |
| 298 displayed_mixed_content(false), | 334 displayed_mixed_content(false), |
| 299 ran_mixed_content(false), | 335 ran_mixed_content(false), |
| 300 displayed_content_with_cert_errors(false), | 336 displayed_content_with_cert_errors(false), |
| 301 ran_content_with_cert_errors(false), | 337 ran_content_with_cert_errors(false), |
| 302 pkp_bypassed(false) {} | 338 pkp_bypassed(false), |
| 339 displayed_password_field_on_http(false), |
| 340 displayed_credit_card_field_on_http(false) {} |
| 303 | 341 |
| 304 SecurityStateModel::VisibleSecurityState::~VisibleSecurityState() {} | 342 SecurityStateModel::VisibleSecurityState::~VisibleSecurityState() {} |
| 305 | 343 |
| 306 bool SecurityStateModel::VisibleSecurityState::operator==( | 344 bool SecurityStateModel::VisibleSecurityState::operator==( |
| 307 const SecurityStateModel::VisibleSecurityState& other) const { | 345 const SecurityStateModel::VisibleSecurityState& other) const { |
| 308 return (url == other.url && | 346 return (url == other.url && |
| 309 initial_security_level == other.initial_security_level && | 347 initial_security_level == other.initial_security_level && |
| 310 fails_malware_check == other.fails_malware_check && | 348 fails_malware_check == other.fails_malware_check && |
| 311 !!certificate == !!other.certificate && | 349 !!certificate == !!other.certificate && |
| 312 (certificate ? certificate->Equals(other.certificate.get()) : true) && | 350 (certificate ? certificate->Equals(other.certificate.get()) : true) && |
| 313 connection_status == other.connection_status && | 351 connection_status == other.connection_status && |
| 314 key_exchange_group == other.key_exchange_group && | 352 key_exchange_group == other.key_exchange_group && |
| 315 security_bits == other.security_bits && | 353 security_bits == other.security_bits && |
| 316 sct_verify_statuses == other.sct_verify_statuses && | 354 sct_verify_statuses == other.sct_verify_statuses && |
| 317 displayed_mixed_content == other.displayed_mixed_content && | 355 displayed_mixed_content == other.displayed_mixed_content && |
| 318 ran_mixed_content == other.ran_mixed_content && | 356 ran_mixed_content == other.ran_mixed_content && |
| 319 displayed_content_with_cert_errors == | 357 displayed_content_with_cert_errors == |
| 320 other.displayed_content_with_cert_errors && | 358 other.displayed_content_with_cert_errors && |
| 321 ran_content_with_cert_errors == other.ran_content_with_cert_errors && | 359 ran_content_with_cert_errors == other.ran_content_with_cert_errors && |
| 322 pkp_bypassed == other.pkp_bypassed); | 360 pkp_bypassed == other.pkp_bypassed && |
| 361 displayed_password_field_on_http == |
| 362 other.displayed_password_field_on_http && |
| 363 displayed_credit_card_field_on_http == |
| 364 other.displayed_credit_card_field_on_http); |
| 323 } | 365 } |
| 324 | 366 |
| 325 } // namespace security_state | 367 } // namespace security_state |
| OLD | NEW |