| 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/core/security_state.h" | 5 #include "components/security_state/core/security_state.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 12 #include "components/security_state/core/switches.h" | 13 #include "components/security_state/core/switches.h" |
| 13 #include "net/ssl/ssl_cipher_suite_names.h" | 14 #include "net/ssl/ssl_cipher_suite_names.h" |
| 14 #include "net/ssl/ssl_connection_status_flags.h" | 15 #include "net/ssl/ssl_connection_status_flags.h" |
| 15 | 16 |
| 16 namespace security_state { | 17 namespace security_state { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // These values are written to logs. New enum values can be added, but existing | 21 // These values are written to logs. New enum values can be added, but existing |
| 21 // enums must never be renumbered or deleted and reused. | 22 // enums must never be renumbered or deleted and reused. |
| 22 enum MarkHttpStatus { | 23 enum MarkHttpStatus { |
| 23 NEUTRAL = 0, // Deprecated | 24 NEUTRAL = 0, // Deprecated |
| 24 NON_SECURE = 1, | 25 NON_SECURE = 1, |
| 25 HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS = 2, | 26 HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS = 2, |
| 26 NON_SECURE_AFTER_EDITING = 3, | 27 NON_SECURE_AFTER_EDITING = 3, |
| 27 NON_SECURE_WHILE_INCOGNITO = 4, | 28 NON_SECURE_WHILE_INCOGNITO = 4, |
| 28 NON_SECURE_WHILE_INCOGNITO_OR_EDITING = 5, | 29 NON_SECURE_WHILE_INCOGNITO_OR_EDITING = 5, |
| 29 LAST_STATUS | 30 LAST_STATUS |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 // If |switch_or_field_trial_group| corresponds to a valid | 33 // If |switch_or_field_trial_group| corresponds to a valid |
| 33 // MarkHttpAs group, sets |*level| and |*histogram_status| to the | 34 // MarkHttpAs setting, sets |*level| and |*histogram_status| to the |
| 34 // appropriate values and returns true. Otherwise, returns false. | 35 // appropriate values and returns true. Otherwise, returns false. |
| 35 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( | 36 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 36 std::string switch_or_field_trial_group, | 37 std::string switch_or_field_trial_group, |
| 37 bool displayed_sensitive_input_on_http, | 38 bool displayed_sensitive_input_on_http, |
| 39 bool is_incognito, |
| 38 SecurityLevel* level, | 40 SecurityLevel* level, |
| 39 MarkHttpStatus* histogram_status) { | 41 MarkHttpStatus* histogram_status) { |
| 40 if (switch_or_field_trial_group != switches::kMarkHttpAsDangerous) | 42 if (switch_or_field_trial_group == |
| 41 return false; | 43 switches::kMarkHttpAsNonSecureWhileIncognito) { |
| 42 *level = DANGEROUS; | 44 *histogram_status = NON_SECURE_WHILE_INCOGNITO; |
| 43 *histogram_status = NON_SECURE; | 45 *level = (is_incognito || displayed_sensitive_input_on_http) |
| 44 return true; | 46 ? security_state::HTTP_SHOW_WARNING |
| 47 : NONE; |
| 48 return true; |
| 49 } |
| 50 if (switch_or_field_trial_group == |
| 51 switches::kMarkHttpAsNonSecureWhileIncognitoOrEditing) { |
| 52 *histogram_status = NON_SECURE_WHILE_INCOGNITO_OR_EDITING; |
| 53 *level = (is_incognito || displayed_sensitive_input_on_http) |
| 54 ? security_state::HTTP_SHOW_WARNING |
| 55 : NONE; |
| 56 return true; |
| 57 } |
| 58 if (switch_or_field_trial_group == switches::kMarkHttpAsDangerous) { |
| 59 *histogram_status = NON_SECURE; |
| 60 *level = DANGEROUS; |
| 61 return true; |
| 62 } |
| 63 |
| 64 return false; |
| 45 } | 65 } |
| 46 | 66 |
| 47 SecurityLevel GetSecurityLevelForNonSecureFieldTrial( | 67 SecurityLevel GetSecurityLevelForNonSecureFieldTrial( |
| 48 bool displayed_sensitive_input_on_http) { | 68 bool displayed_sensitive_input_on_http, |
| 69 bool is_incognito) { |
| 49 std::string choice = | 70 std::string choice = |
| 50 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 71 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 51 switches::kMarkHttpAs); | 72 switches::kMarkHttpAs); |
| 52 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); | 73 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); |
| 53 | 74 |
| 54 const char kEnumeration[] = "SSL.MarkHttpAsStatus"; | 75 const char kEnumeration[] = "SSL.MarkHttpAsStatus"; |
| 55 | 76 |
| 56 SecurityLevel level = NONE; | 77 SecurityLevel level = NONE; |
| 57 MarkHttpStatus status; | 78 MarkHttpStatus status; |
| 58 | 79 |
| 59 // If the command-line switch is set, then it takes precedence over | 80 // If the command-line switch is set, then it takes precedence over |
| 60 // the field trial group. | 81 // the field trial group. |
| 61 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( | 82 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 62 choice, displayed_sensitive_input_on_http, &level, &status)) { | 83 choice, displayed_sensitive_input_on_http, is_incognito, &level, |
| 84 &status)) { |
| 63 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( | 85 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 64 group, displayed_sensitive_input_on_http, &level, &status)) { | 86 group, displayed_sensitive_input_on_http, is_incognito, &level, |
| 87 &status)) { |
| 65 status = HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS; | 88 status = HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS; |
| 66 level = displayed_sensitive_input_on_http | 89 level = displayed_sensitive_input_on_http |
| 67 ? security_state::HTTP_SHOW_WARNING | 90 ? security_state::HTTP_SHOW_WARNING |
| 68 : NONE; | 91 : NONE; |
| 69 } | 92 } |
| 70 } | 93 } |
| 71 | 94 |
| 72 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); | 95 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); |
| 73 return level; | 96 return level; |
| 74 } | 97 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 144 |
| 122 // Choose the appropriate security level for requests to HTTP and remaining | 145 // Choose the appropriate security level for requests to HTTP and remaining |
| 123 // pseudo URLs (blob:, filesystem:). filesystem: is a standard scheme so does | 146 // pseudo URLs (blob:, filesystem:). filesystem: is a standard scheme so does |
| 124 // not need to be explicitly listed here. | 147 // not need to be explicitly listed here. |
| 125 // TODO(meacer): Remove special case for blob (crbug.com/684751). | 148 // TODO(meacer): Remove special case for blob (crbug.com/684751). |
| 126 if (!is_cryptographic_with_certificate) { | 149 if (!is_cryptographic_with_certificate) { |
| 127 if (!is_origin_secure_callback.Run(url) && | 150 if (!is_origin_secure_callback.Run(url) && |
| 128 (url.IsStandard() || url.SchemeIs(url::kBlobScheme))) { | 151 (url.IsStandard() || url.SchemeIs(url::kBlobScheme))) { |
| 129 return GetSecurityLevelForNonSecureFieldTrial( | 152 return GetSecurityLevelForNonSecureFieldTrial( |
| 130 visible_security_state.displayed_password_field_on_http || | 153 visible_security_state.displayed_password_field_on_http || |
| 131 visible_security_state.displayed_credit_card_field_on_http); | 154 visible_security_state.displayed_credit_card_field_on_http, |
| 155 visible_security_state.is_incognito); |
| 132 } | 156 } |
| 133 return NONE; | 157 return NONE; |
| 134 } | 158 } |
| 135 | 159 |
| 136 // Downgrade the security level for active insecure subresources. | 160 // Downgrade the security level for active insecure subresources. |
| 137 if (mixed_content_status == CONTENT_STATUS_RAN || | 161 if (mixed_content_status == CONTENT_STATUS_RAN || |
| 138 mixed_content_status == CONTENT_STATUS_DISPLAYED_AND_RAN || | 162 mixed_content_status == CONTENT_STATUS_DISPLAYED_AND_RAN || |
| 139 content_with_cert_errors_status == CONTENT_STATUS_RAN || | 163 content_with_cert_errors_status == CONTENT_STATUS_RAN || |
| 140 content_with_cert_errors_status == CONTENT_STATUS_DISPLAYED_AND_RAN) { | 164 content_with_cert_errors_status == CONTENT_STATUS_DISPLAYED_AND_RAN) { |
| 141 return kRanInsecureContentLevel; | 165 return kRanInsecureContentLevel; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 255 } |
| 232 | 256 |
| 233 security_info->contained_mixed_form = | 257 security_info->contained_mixed_form = |
| 234 visible_security_state.contained_mixed_form; | 258 visible_security_state.contained_mixed_form; |
| 235 | 259 |
| 236 security_info->security_level = GetSecurityLevelForRequest( | 260 security_info->security_level = GetSecurityLevelForRequest( |
| 237 visible_security_state, used_policy_installed_certificate, | 261 visible_security_state, used_policy_installed_certificate, |
| 238 is_origin_secure_callback, security_info->sha1_in_chain, | 262 is_origin_secure_callback, security_info->sha1_in_chain, |
| 239 security_info->mixed_content_status, | 263 security_info->mixed_content_status, |
| 240 security_info->content_with_cert_errors_status); | 264 security_info->content_with_cert_errors_status); |
| 265 |
| 266 security_info->incognito_downgraded_security_level = |
| 267 (visible_security_state.is_incognito && |
| 268 security_info->security_level == HTTP_SHOW_WARNING && |
| 269 security_state::IsHttpWarningForIncognitoEnabled()); |
| 241 } | 270 } |
| 242 | 271 |
| 243 } // namespace | 272 } // namespace |
| 244 | 273 |
| 274 bool IsHttpWarningForIncognitoEnabled() { |
| 275 std::string choice = |
| 276 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 277 switches::kMarkHttpAs); |
| 278 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); |
| 279 SecurityLevel level = NONE; |
| 280 MarkHttpStatus status; |
| 281 |
| 282 // If the command-line switch is set, then it takes precedence over |
| 283 // the field trial group. |
| 284 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 285 choice, false, true, &level, &status)) { |
| 286 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( |
| 287 group, false, true, &level, &status)) { |
| 288 return false; |
| 289 } |
| 290 } |
| 291 |
| 292 return (status == NON_SECURE_WHILE_INCOGNITO || |
| 293 status == NON_SECURE_WHILE_INCOGNITO_OR_EDITING); |
| 294 } |
| 295 |
| 245 const base::Feature kHttpFormWarningFeature{"HttpFormWarning", | 296 const base::Feature kHttpFormWarningFeature{"HttpFormWarning", |
| 246 base::FEATURE_DISABLED_BY_DEFAULT}; | 297 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 247 | 298 |
| 248 SecurityInfo::SecurityInfo() | 299 SecurityInfo::SecurityInfo() |
| 249 : security_level(NONE), | 300 : security_level(NONE), |
| 250 malicious_content_status(MALICIOUS_CONTENT_STATUS_NONE), | 301 malicious_content_status(MALICIOUS_CONTENT_STATUS_NONE), |
| 251 sha1_in_chain(false), | 302 sha1_in_chain(false), |
| 252 mixed_content_status(CONTENT_STATUS_NONE), | 303 mixed_content_status(CONTENT_STATUS_NONE), |
| 253 content_with_cert_errors_status(CONTENT_STATUS_NONE), | 304 content_with_cert_errors_status(CONTENT_STATUS_NONE), |
| 254 scheme_is_cryptographic(false), | 305 scheme_is_cryptographic(false), |
| 255 cert_status(0), | 306 cert_status(0), |
| 256 security_bits(-1), | 307 security_bits(-1), |
| 257 connection_status(0), | 308 connection_status(0), |
| 258 key_exchange_group(0), | 309 key_exchange_group(0), |
| 259 obsolete_ssl_status(net::OBSOLETE_SSL_NONE), | 310 obsolete_ssl_status(net::OBSOLETE_SSL_NONE), |
| 260 pkp_bypassed(false), | 311 pkp_bypassed(false), |
| 261 displayed_password_field_on_http(false), | 312 displayed_password_field_on_http(false), |
| 262 displayed_credit_card_field_on_http(false), | 313 displayed_credit_card_field_on_http(false), |
| 263 contained_mixed_form(false), | 314 contained_mixed_form(false), |
| 264 cert_missing_subject_alt_name(false) {} | 315 cert_missing_subject_alt_name(false), |
| 316 incognito_downgraded_security_level(false) {} |
| 265 | 317 |
| 266 SecurityInfo::~SecurityInfo() {} | 318 SecurityInfo::~SecurityInfo() {} |
| 267 | 319 |
| 268 void GetSecurityInfo( | 320 void GetSecurityInfo( |
| 269 std::unique_ptr<VisibleSecurityState> visible_security_state, | 321 std::unique_ptr<VisibleSecurityState> visible_security_state, |
| 270 bool used_policy_installed_certificate, | 322 bool used_policy_installed_certificate, |
| 271 IsOriginSecureCallback is_origin_secure_callback, | 323 IsOriginSecureCallback is_origin_secure_callback, |
| 272 SecurityInfo* result) { | 324 SecurityInfo* result) { |
| 273 SecurityInfoForRequest(*visible_security_state, | 325 SecurityInfoForRequest(*visible_security_state, |
| 274 used_policy_installed_certificate, | 326 used_policy_installed_certificate, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 286 connection_status(0), | 338 connection_status(0), |
| 287 key_exchange_group(0), | 339 key_exchange_group(0), |
| 288 security_bits(-1), | 340 security_bits(-1), |
| 289 displayed_mixed_content(false), | 341 displayed_mixed_content(false), |
| 290 contained_mixed_form(false), | 342 contained_mixed_form(false), |
| 291 ran_mixed_content(false), | 343 ran_mixed_content(false), |
| 292 displayed_content_with_cert_errors(false), | 344 displayed_content_with_cert_errors(false), |
| 293 ran_content_with_cert_errors(false), | 345 ran_content_with_cert_errors(false), |
| 294 pkp_bypassed(false), | 346 pkp_bypassed(false), |
| 295 displayed_password_field_on_http(false), | 347 displayed_password_field_on_http(false), |
| 296 displayed_credit_card_field_on_http(false) {} | 348 displayed_credit_card_field_on_http(false), |
| 349 is_incognito(false) {} |
| 297 | 350 |
| 298 VisibleSecurityState::~VisibleSecurityState() {} | 351 VisibleSecurityState::~VisibleSecurityState() {} |
| 299 | 352 |
| 300 bool VisibleSecurityState::operator==(const VisibleSecurityState& other) const { | 353 bool VisibleSecurityState::operator==(const VisibleSecurityState& other) const { |
| 301 return (url == other.url && | 354 return (url == other.url && |
| 302 malicious_content_status == other.malicious_content_status && | 355 malicious_content_status == other.malicious_content_status && |
| 303 !!certificate == !!other.certificate && | 356 !!certificate == !!other.certificate && |
| 304 (certificate ? certificate->Equals(other.certificate.get()) : true) && | 357 (certificate ? certificate->Equals(other.certificate.get()) : true) && |
| 305 connection_status == other.connection_status && | 358 connection_status == other.connection_status && |
| 306 key_exchange_group == other.key_exchange_group && | 359 key_exchange_group == other.key_exchange_group && |
| 307 security_bits == other.security_bits && | 360 security_bits == other.security_bits && |
| 308 displayed_mixed_content == other.displayed_mixed_content && | 361 displayed_mixed_content == other.displayed_mixed_content && |
| 309 ran_mixed_content == other.ran_mixed_content && | 362 ran_mixed_content == other.ran_mixed_content && |
| 310 displayed_content_with_cert_errors == | 363 displayed_content_with_cert_errors == |
| 311 other.displayed_content_with_cert_errors && | 364 other.displayed_content_with_cert_errors && |
| 312 ran_content_with_cert_errors == other.ran_content_with_cert_errors && | 365 ran_content_with_cert_errors == other.ran_content_with_cert_errors && |
| 313 pkp_bypassed == other.pkp_bypassed && | 366 pkp_bypassed == other.pkp_bypassed && |
| 314 displayed_password_field_on_http == | 367 displayed_password_field_on_http == |
| 315 other.displayed_password_field_on_http && | 368 other.displayed_password_field_on_http && |
| 316 displayed_credit_card_field_on_http == | 369 displayed_credit_card_field_on_http == |
| 317 other.displayed_credit_card_field_on_http && | 370 other.displayed_credit_card_field_on_http && |
| 318 contained_mixed_form == other.contained_mixed_form); | 371 contained_mixed_form == other.contained_mixed_form && |
| 372 is_incognito == other.is_incognito); |
| 319 } | 373 } |
| 320 | 374 |
| 321 } // namespace security_state | 375 } // namespace security_state |
| OLD | NEW |