| 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 "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_client.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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 level = SecurityStateModel::SECURITY_ERROR; | 58 level = SecurityStateModel::SECURITY_ERROR; |
| 58 } else { | 59 } else { |
| 59 status = NEUTRAL; | 60 status = NEUTRAL; |
| 60 level = SecurityStateModel::NONE; | 61 level = SecurityStateModel::NONE; |
| 61 } | 62 } |
| 62 | 63 |
| 63 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); | 64 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); |
| 64 return level; | 65 return level; |
| 65 } | 66 } |
| 66 | 67 |
| 67 scoped_refptr<net::X509Certificate> GetCertForSSLStatus( | |
| 68 const content::SSLStatus& ssl) { | |
| 69 scoped_refptr<net::X509Certificate> cert; | |
| 70 return content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, &cert) | |
| 71 ? cert | |
| 72 : nullptr; | |
| 73 } | |
| 74 | |
| 75 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus( | 68 SecurityStateModel::SHA1DeprecationStatus GetSHA1DeprecationStatus( |
| 76 scoped_refptr<net::X509Certificate> cert, | 69 scoped_refptr<net::X509Certificate> cert, |
| 77 const content::SSLStatus& ssl) { | 70 const content::SSLStatus& ssl) { |
| 78 if (!cert || !(ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT)) | 71 if (!cert || !(ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT)) |
| 79 return SecurityStateModel::NO_DEPRECATED_SHA1; | 72 return SecurityStateModel::NO_DEPRECATED_SHA1; |
| 80 | 73 |
| 81 // The internal representation of the dates for UI treatment of SHA-1. | 74 // The internal representation of the dates for UI treatment of SHA-1. |
| 82 // See http://crbug.com/401365 for details. | 75 // See http://crbug.com/401365 for details. |
| 83 static const int64_t kJanuary2017 = INT64_C(13127702400000000); | 76 static const int64_t kJanuary2017 = INT64_C(13127702400000000); |
| 84 if (cert->valid_expiry() >= base::Time::FromInternalValue(kJanuary2017)) | 77 if (cert->valid_expiry() >= base::Time::FromInternalValue(kJanuary2017)) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 108 | 101 |
| 109 return SecurityStateModel::NO_MIXED_CONTENT; | 102 return SecurityStateModel::NO_MIXED_CONTENT; |
| 110 } | 103 } |
| 111 | 104 |
| 112 SecurityStateModel::SecurityLevel GetSecurityLevelForRequest( | 105 SecurityStateModel::SecurityLevel GetSecurityLevelForRequest( |
| 113 const GURL& url, | 106 const GURL& url, |
| 114 const content::SSLStatus& ssl, | 107 const content::SSLStatus& ssl, |
| 115 Profile* profile, | 108 Profile* profile, |
| 116 scoped_refptr<net::X509Certificate> cert, | 109 scoped_refptr<net::X509Certificate> cert, |
| 117 SecurityStateModel::SHA1DeprecationStatus sha1_status, | 110 SecurityStateModel::SHA1DeprecationStatus sha1_status, |
| 118 SecurityStateModel::MixedContentStatus mixed_content_status) { | 111 SecurityStateModel::MixedContentStatus mixed_content_status, |
| 112 bool used_policy_installed_certificate) { |
| 119 switch (ssl.security_style) { | 113 switch (ssl.security_style) { |
| 120 case content::SECURITY_STYLE_UNKNOWN: | 114 case content::SECURITY_STYLE_UNKNOWN: |
| 121 return SecurityStateModel::NONE; | 115 return SecurityStateModel::NONE; |
| 122 | 116 |
| 123 case content::SECURITY_STYLE_UNAUTHENTICATED: { | 117 case content::SECURITY_STYLE_UNAUTHENTICATED: { |
| 124 if (!content::IsOriginSecure(url) && url.IsStandard()) | 118 if (!content::IsOriginSecure(url) && url.IsStandard()) |
| 125 return GetSecurityLevelForNonSecureFieldTrial(); | 119 return GetSecurityLevelForNonSecureFieldTrial(); |
| 126 return SecurityStateModel::NONE; | 120 return SecurityStateModel::NONE; |
| 127 } | 121 } |
| 128 | 122 |
| 129 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: | 123 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| 130 return SecurityStateModel::SECURITY_ERROR; | 124 return SecurityStateModel::SECURITY_ERROR; |
| 131 | 125 |
| 132 case content::SECURITY_STYLE_WARNING: | 126 case content::SECURITY_STYLE_WARNING: |
| 133 NOTREACHED(); | 127 NOTREACHED(); |
| 134 return SecurityStateModel::SECURITY_WARNING; | 128 return SecurityStateModel::SECURITY_WARNING; |
| 135 | 129 |
| 136 case content::SECURITY_STYLE_AUTHENTICATED: { | 130 case content::SECURITY_STYLE_AUTHENTICATED: { |
| 137 #if defined(OS_CHROMEOS) | |
| 138 // Report if there is a policy cert first, before reporting any other | 131 // Report if there is a policy cert first, before reporting any other |
| 139 // authenticated-but-with-errors cases. A policy cert is a strong | 132 // authenticated-but-with-errors cases. A policy cert is a strong |
| 140 // indicator of a MITM being present (the enterprise), while the | 133 // indicator of a MITM being present (the enterprise), while the |
| 141 // other authenticated-but-with-errors indicate something may | 134 // other authenticated-but-with-errors indicate something may |
| 142 // be wrong, or may be wrong in the future, but is unclear now. | 135 // be wrong, or may be wrong in the future, but is unclear now. |
| 143 policy::PolicyCertService* service = | 136 if (used_policy_installed_certificate) |
| 144 policy::PolicyCertServiceFactory::GetForProfile(profile); | |
| 145 if (service && service->UsedPolicyCertificates()) | |
| 146 return SecurityStateModel::SECURITY_POLICY_WARNING; | 137 return SecurityStateModel::SECURITY_POLICY_WARNING; |
| 147 #endif | |
| 148 | 138 |
| 149 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MAJOR) | 139 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MAJOR) |
| 150 return SecurityStateModel::SECURITY_ERROR; | 140 return SecurityStateModel::SECURITY_ERROR; |
| 151 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MINOR) | 141 if (sha1_status == SecurityStateModel::DEPRECATED_SHA1_MINOR) |
| 152 return SecurityStateModel::NONE; | 142 return SecurityStateModel::NONE; |
| 153 | 143 |
| 154 // Active mixed content is downgraded to the BROKEN style and | 144 // Active mixed content is downgraded to the BROKEN style and |
| 155 // handled above. | 145 // handled above. |
| 156 DCHECK_NE(SecurityStateModel::RAN_MIXED_CONTENT, mixed_content_status); | 146 DCHECK_NE(SecurityStateModel::RAN_MIXED_CONTENT, mixed_content_status); |
| 157 DCHECK_NE(SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, | 147 DCHECK_NE(SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 const { | 200 const { |
| 211 content::NavigationEntry* entry = | 201 content::NavigationEntry* entry = |
| 212 web_contents_->GetController().GetVisibleEntry(); | 202 web_contents_->GetController().GetVisibleEntry(); |
| 213 if (!entry) { | 203 if (!entry) { |
| 214 security_info_ = SecurityInfo(); | 204 security_info_ = SecurityInfo(); |
| 215 visible_url_ = GURL(); | 205 visible_url_ = GURL(); |
| 216 visible_ssl_status_ = content::SSLStatus(); | 206 visible_ssl_status_ = content::SSLStatus(); |
| 217 return security_info_; | 207 return security_info_; |
| 218 } | 208 } |
| 219 | 209 |
| 210 scoped_refptr<net::X509Certificate> cert = nullptr; |
| 211 client_->RetrieveCert(&cert); |
| 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. |
| 225 if (security_info_.security_level == EV_SECURE && | 218 if (security_info_.security_level == EV_SECURE && !cert) { |
| 226 !GetCertForSSLStatus(visible_ssl_status_)) { | |
| 227 security_info_.security_level = SECURE; | 219 security_info_.security_level = SECURE; |
| 228 } | 220 } |
| 229 return security_info_; | 221 return security_info_; |
| 230 } | 222 } |
| 231 | 223 |
| 232 SecurityInfoForRequest( | 224 SecurityInfoForRequest( |
| 233 entry->GetURL(), entry->GetSSL(), | 225 entry->GetURL(), entry->GetSSL(), |
| 234 Profile::FromBrowserContext(web_contents_->GetBrowserContext()), | 226 Profile::FromBrowserContext(web_contents_->GetBrowserContext()), cert, |
| 235 &security_info_); | 227 client_->UsedPolicyInstalledCertificate(), &security_info_); |
| 236 visible_url_ = entry->GetURL(); | 228 visible_url_ = entry->GetURL(); |
| 237 visible_ssl_status_ = entry->GetSSL(); | 229 visible_ssl_status_ = entry->GetSSL(); |
| 238 return security_info_; | 230 return security_info_; |
| 239 } | 231 } |
| 240 | 232 |
| 241 // static | 233 // static |
| 242 void SecurityStateModel::SecurityInfoForRequest(const GURL& url, | 234 void SecurityStateModel::SecurityInfoForRequest( |
| 243 const content::SSLStatus& ssl, | 235 const GURL& url, |
| 244 Profile* profile, | 236 const content::SSLStatus& ssl, |
| 245 SecurityInfo* security_info) { | 237 Profile* profile, |
| 246 scoped_refptr<net::X509Certificate> cert = GetCertForSSLStatus(ssl); | 238 const scoped_refptr<net::X509Certificate>& cert, |
| 239 bool used_policy_installed_certificate, |
| 240 SecurityInfo* security_info) { |
| 247 security_info->cert_id = ssl.cert_id; | 241 security_info->cert_id = ssl.cert_id; |
| 248 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl); | 242 security_info->sha1_deprecation_status = GetSHA1DeprecationStatus(cert, ssl); |
| 249 security_info->mixed_content_status = GetMixedContentStatus(ssl); | 243 security_info->mixed_content_status = GetMixedContentStatus(ssl); |
| 250 security_info->security_bits = ssl.security_bits; | 244 security_info->security_bits = ssl.security_bits; |
| 251 security_info->connection_status = ssl.connection_status; | 245 security_info->connection_status = ssl.connection_status; |
| 252 security_info->cert_status = ssl.cert_status; | 246 security_info->cert_status = ssl.cert_status; |
| 253 security_info->scheme_is_cryptographic = url.SchemeIsCryptographic(); | 247 security_info->scheme_is_cryptographic = url.SchemeIsCryptographic(); |
| 254 security_info->is_secure_protocol_and_ciphersuite = | 248 security_info->is_secure_protocol_and_ciphersuite = |
| 255 (net::SSLConnectionStatusToVersion(ssl.connection_status) >= | 249 (net::SSLConnectionStatusToVersion(ssl.connection_status) >= |
| 256 net::SSL_CONNECTION_VERSION_TLS1_2 && | 250 net::SSL_CONNECTION_VERSION_TLS1_2 && |
| 257 net::IsSecureTLSCipherSuite( | 251 net::IsSecureTLSCipherSuite( |
| 258 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))); | 252 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))); |
| 259 | 253 |
| 260 security_info->sct_verify_statuses.clear(); | 254 security_info->sct_verify_statuses.clear(); |
| 261 for (const auto& sct : ssl.signed_certificate_timestamp_ids) { | 255 for (const auto& sct : ssl.signed_certificate_timestamp_ids) { |
| 262 security_info->sct_verify_statuses.push_back(sct.status); | 256 security_info->sct_verify_statuses.push_back(sct.status); |
| 263 } | 257 } |
| 264 | 258 |
| 265 security_info->security_level = GetSecurityLevelForRequest( | 259 security_info->security_level = GetSecurityLevelForRequest( |
| 266 url, ssl, profile, cert, security_info->sha1_deprecation_status, | 260 url, ssl, profile, cert, security_info->sha1_deprecation_status, |
| 267 security_info->mixed_content_status); | 261 security_info->mixed_content_status, used_policy_installed_certificate); |
| 268 } | 262 } |
| 269 | 263 |
| 270 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents) | 264 SecurityStateModel::SecurityStateModel(content::WebContents* web_contents) |
| 271 : web_contents_(web_contents) {} | 265 : web_contents_(web_contents), |
| 266 client_(new ChromeSecurityStateModelClient(web_contents)) {} |
| OLD | NEW |