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

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

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: Remove SecurityStateModel. 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 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents(
162 entry->GetURL(), false, entry, web_contents, false)) {
163 state->fails_malware_check = true;
164 }
165 }
166
167 } // namespace 138 } // namespace
168 139
169 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( 140 std::unique_ptr<security_state::VisibleSecurityState> GetVisibleSecurityState(
170 content::WebContents* web_contents) 141 content::WebContents* web_contents) {
171 : content::WebContentsObserver(web_contents), 142 auto state = base::MakeUnique<security_state::VisibleSecurityState>();
172 web_contents_(web_contents), 143
173 security_state_model_(new SecurityStateModel()), 144 content::NavigationEntry* entry =
174 logged_http_warning_on_current_navigation_(false) { 145 web_contents->GetController().GetVisibleEntry();
175 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;
176 } 179 }
177 180
178 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} 181 blink::WebSecurityStyle GetSecurityStyle(
179 182 const security_state::SecurityInfo& security_info,
180 // static
181 blink::WebSecurityStyle ChromeSecurityStateModelClient::GetSecurityStyle(
182 const security_state::SecurityStateModel::SecurityInfo& security_info,
183 content::SecurityStyleExplanations* security_style_explanations) { 183 content::SecurityStyleExplanations* security_style_explanations) {
184 const blink::WebSecurityStyle security_style = 184 const blink::WebSecurityStyle security_style =
185 SecurityLevelToSecurityStyle(security_info.security_level); 185 SecurityLevelToSecurityStyle(security_info.security_level);
186 186
187 if (security_info.security_level == 187 if (security_info.security_level == security_state::HTTP_SHOW_WARNING) {
188 security_state::SecurityStateModel::HTTP_SHOW_WARNING) {
189 // 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
190 // unauthenticated explanation explaining why the omnibox warning is 189 // unauthenticated explanation explaining why the omnibox warning is
191 // present. 190 // present.
192 security_style_explanations->unauthenticated_explanations.push_back( 191 security_style_explanations->unauthenticated_explanations.push_back(
193 content::SecurityStyleExplanation( 192 content::SecurityStyleExplanation(
194 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), 193 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT),
195 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT_DESCRIPTION))); 194 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT_DESCRIPTION)));
196 } else if (security_info.security_level == 195 } else if (security_info.security_level == security_state::NONE &&
197 security_state::SecurityStateModel::NONE &&
198 security_info.displayed_private_user_data_input_on_http) { 196 security_info.displayed_private_user_data_input_on_http) {
199 // If the HTTP_SHOW_WARNING field trial isn't in use yet, display an 197 // If the HTTP_SHOW_WARNING field trial isn't in use yet, display an
200 // informational note that the omnibox will contain a warning for 198 // informational note that the omnibox will contain a warning for
201 // this site in a future version of Chrome. 199 // this site in a future version of Chrome.
202 security_style_explanations->info_explanations.push_back( 200 security_style_explanations->info_explanations.push_back(
203 content::SecurityStyleExplanation( 201 content::SecurityStyleExplanation(
204 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), 202 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT),
205 l10n_util::GetStringUTF8( 203 l10n_util::GetStringUTF8(
206 IDS_PRIVATE_USER_DATA_INPUT_FUTURE_DESCRIPTION))); 204 IDS_PRIVATE_USER_DATA_INPUT_FUTURE_DESCRIPTION)));
207 } 205 }
208 206
209 security_style_explanations->ran_insecure_content_style = 207 security_style_explanations->ran_insecure_content_style =
210 SecurityLevelToSecurityStyle( 208 SecurityLevelToSecurityStyle(security_state::kRanInsecureContentLevel);
211 SecurityStateModel::kRanInsecureContentLevel);
212 security_style_explanations->displayed_insecure_content_style = 209 security_style_explanations->displayed_insecure_content_style =
213 SecurityLevelToSecurityStyle( 210 SecurityLevelToSecurityStyle(
214 SecurityStateModel::kDisplayedInsecureContentLevel); 211 security_state::kDisplayedInsecureContentLevel);
215 212
216 // Check if the page is HTTP; if so, no more explanations are needed. Note 213 // Check if the page is HTTP; if so, no more explanations are needed. Note
217 // that SecurityStyleUnauthenticated does not necessarily mean that 214 // that SecurityStyleUnauthenticated does not necessarily mean that
218 // the page is loaded over HTTP, because the security style merely 215 // the page is loaded over HTTP, because the security style merely
219 // represents how the embedder wishes to display the security state of 216 // represents how the embedder wishes to display the security state of
220 // the page, and the embedder can choose to display HTTPS page as HTTP 217 // the page, and the embedder can choose to display HTTPS page as HTTP
221 // if it wants to (for example, displaying deprecated crypto 218 // if it wants to (for example, displaying deprecated crypto
222 // algorithms with the same UI treatment as HTTP pages). 219 // algorithms with the same UI treatment as HTTP pages).
223 security_style_explanations->scheme_is_cryptographic = 220 security_style_explanations->scheme_is_cryptographic =
224 security_info.scheme_is_cryptographic; 221 security_info.scheme_is_cryptographic;
225 if (!security_info.scheme_is_cryptographic) { 222 if (!security_info.scheme_is_cryptographic) {
226 return security_style; 223 return security_style;
227 } 224 }
228 225
229 if (security_info.sha1_deprecation_status == 226 if (security_info.sha1_deprecation_status ==
230 SecurityStateModel::DEPRECATED_SHA1_MAJOR) { 227 security_state::DEPRECATED_SHA1_MAJOR) {
231 security_style_explanations->broken_explanations.push_back( 228 security_style_explanations->broken_explanations.push_back(
232 content::SecurityStyleExplanation( 229 content::SecurityStyleExplanation(
233 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1), 230 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1),
234 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION), 231 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION),
235 !!security_info.certificate)); 232 !!security_info.certificate));
236 } else if (security_info.sha1_deprecation_status == 233 } else if (security_info.sha1_deprecation_status ==
237 SecurityStateModel::DEPRECATED_SHA1_MINOR) { 234 security_state::DEPRECATED_SHA1_MINOR) {
238 security_style_explanations->unauthenticated_explanations.push_back( 235 security_style_explanations->unauthenticated_explanations.push_back(
239 content::SecurityStyleExplanation( 236 content::SecurityStyleExplanation(
240 l10n_util::GetStringUTF8(IDS_MINOR_SHA1), 237 l10n_util::GetStringUTF8(IDS_MINOR_SHA1),
241 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION), 238 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION),
242 !!security_info.certificate)); 239 !!security_info.certificate));
243 } 240 }
244 241
245 // Record the presence of mixed content (HTTP subresources on an HTTPS 242 // Record the presence of mixed content (HTTP subresources on an HTTPS
246 // page). 243 // page).
247 security_style_explanations->ran_mixed_content = 244 security_style_explanations->ran_mixed_content =
248 security_info.mixed_content_status == 245 security_info.mixed_content_status ==
249 SecurityStateModel::CONTENT_STATUS_RAN || 246 security_state::CONTENT_STATUS_RAN ||
250 security_info.mixed_content_status == 247 security_info.mixed_content_status ==
251 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 248 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
252 security_style_explanations->displayed_mixed_content = 249 security_style_explanations->displayed_mixed_content =
253 security_info.mixed_content_status == 250 security_info.mixed_content_status ==
254 SecurityStateModel::CONTENT_STATUS_DISPLAYED || 251 security_state::CONTENT_STATUS_DISPLAYED ||
255 security_info.mixed_content_status == 252 security_info.mixed_content_status ==
256 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 253 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
257 254
258 bool is_cert_status_error = net::IsCertStatusError(security_info.cert_status); 255 bool is_cert_status_error = net::IsCertStatusError(security_info.cert_status);
259 bool is_cert_status_minor_error = 256 bool is_cert_status_minor_error =
260 net::IsCertStatusMinorError(security_info.cert_status); 257 net::IsCertStatusMinorError(security_info.cert_status);
261 258
262 // If the main resource was loaded no certificate errors or only minor 259 // If the main resource was loaded no certificate errors or only minor
263 // certificate errors, then record the presence of subresources with 260 // certificate errors, then record the presence of subresources with
264 // certificate errors. Subresource certificate errors aren't recorded 261 // certificate errors. Subresource certificate errors aren't recorded
265 // when the main resource was loaded with major certificate errors 262 // when the main resource was loaded with major certificate errors
266 // because, in the common case, these subresource certificate errors 263 // because, in the common case, these subresource certificate errors
267 // would be duplicative with the main resource's error. 264 // would be duplicative with the main resource's error.
268 if (!is_cert_status_error || is_cert_status_minor_error) { 265 if (!is_cert_status_error || is_cert_status_minor_error) {
269 security_style_explanations->ran_content_with_cert_errors = 266 security_style_explanations->ran_content_with_cert_errors =
270 security_info.content_with_cert_errors_status == 267 security_info.content_with_cert_errors_status ==
271 SecurityStateModel::CONTENT_STATUS_RAN || 268 security_state::CONTENT_STATUS_RAN ||
272 security_info.content_with_cert_errors_status == 269 security_info.content_with_cert_errors_status ==
273 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 270 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
274 security_style_explanations->displayed_content_with_cert_errors = 271 security_style_explanations->displayed_content_with_cert_errors =
275 security_info.content_with_cert_errors_status == 272 security_info.content_with_cert_errors_status ==
276 SecurityStateModel::CONTENT_STATUS_DISPLAYED || 273 security_state::CONTENT_STATUS_DISPLAYED ||
277 security_info.content_with_cert_errors_status == 274 security_info.content_with_cert_errors_status ==
278 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; 275 security_state::CONTENT_STATUS_DISPLAYED_AND_RAN;
279 } 276 }
280 277
281 if (is_cert_status_error) { 278 if (is_cert_status_error) {
282 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString( 279 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(
283 net::MapCertStatusToNetError(security_info.cert_status))); 280 net::MapCertStatusToNetError(security_info.cert_status)));
284 281
285 content::SecurityStyleExplanation explanation( 282 content::SecurityStyleExplanation explanation(
286 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), 283 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
287 l10n_util::GetStringFUTF8( 284 l10n_util::GetStringFUTF8(
288 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), 285 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
289 !!security_info.certificate); 286 !!security_info.certificate);
290 287
291 if (is_cert_status_minor_error) { 288 if (is_cert_status_minor_error) {
292 security_style_explanations->unauthenticated_explanations.push_back( 289 security_style_explanations->unauthenticated_explanations.push_back(
293 explanation); 290 explanation);
294 } else { 291 } else {
295 security_style_explanations->broken_explanations.push_back(explanation); 292 security_style_explanations->broken_explanations.push_back(explanation);
296 } 293 }
297 } else { 294 } else {
298 // If the certificate does not have errors and is not using 295 // If the certificate does not have errors and is not using
299 // deprecated SHA1, then add an explanation that the certificate is 296 // deprecated SHA1, then add an explanation that the certificate is
300 // valid. 297 // valid.
301 if (security_info.sha1_deprecation_status == 298 if (security_info.sha1_deprecation_status ==
302 SecurityStateModel::NO_DEPRECATED_SHA1) { 299 security_state::NO_DEPRECATED_SHA1) {
303 security_style_explanations->secure_explanations.push_back( 300 security_style_explanations->secure_explanations.push_back(
304 content::SecurityStyleExplanation( 301 content::SecurityStyleExplanation(
305 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), 302 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE),
306 l10n_util::GetStringUTF8( 303 l10n_util::GetStringUTF8(
307 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), 304 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION),
308 !!security_info.certificate)); 305 !!security_info.certificate));
309 } 306 }
310 } 307 }
311 308
312 AddConnectionExplanation(security_info, security_style_explanations); 309 AddConnectionExplanation(security_info, security_style_explanations);
313 310
314 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed; 311 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed;
315 if (security_info.pkp_bypassed) { 312 if (security_info.pkp_bypassed) {
316 security_style_explanations->info_explanations.push_back( 313 security_style_explanations->info_explanations.push_back(
317 content::SecurityStyleExplanation( 314 content::SecurityStyleExplanation(
318 "Public-Key Pinning Bypassed", 315 "Public-Key Pinning Bypassed",
319 "Public-key pinning was bypassed by a local root certificate.")); 316 "Public-key pinning was bypassed by a local root certificate."));
320 } 317 }
321 318
322 return security_style; 319 return security_style;
323 } 320 }
324 321
325 void ChromeSecurityStateModelClient::GetSecurityInfo( 322 } // namespace security_state
326 SecurityStateModel::SecurityInfo* result) const {
327 security_state_model_->GetSecurityInfo(result);
328 }
329
330 void ChromeSecurityStateModelClient::VisibleSecurityStateChanged() {
331 if (logged_http_warning_on_current_navigation_)
332 return;
333
334 security_state::SecurityStateModel::SecurityInfo security_info;
335 GetSecurityInfo(&security_info);
336 if (!security_info.displayed_private_user_data_input_on_http)
337 return;
338
339 std::string warning;
340 bool warning_is_user_visible = false;
341 switch (security_info.security_level) {
342 case security_state::SecurityStateModel::HTTP_SHOW_WARNING:
343 warning =
344 "This page includes a password or credit card input in a non-secure "
345 "context. A warning has been added to the URL bar. For more "
346 "information, see https://goo.gl/zmWq3m.";
347 warning_is_user_visible = true;
348 break;
349 case security_state::SecurityStateModel::NONE:
350 case security_state::SecurityStateModel::DANGEROUS:
351 warning =
352 "This page includes a password or credit card input in a non-secure "
353 "context. A warning will be added to the URL bar in Chrome 56 (Jan "
354 "2017). For more information, see https://goo.gl/zmWq3m.";
355 break;
356 default:
357 return;
358 }
359
360 logged_http_warning_on_current_navigation_ = true;
361 web_contents_->GetMainFrame()->AddMessageToConsole(
362 content::CONSOLE_MESSAGE_LEVEL_WARNING, warning);
363 UMA_HISTOGRAM_BOOLEAN("Security.HTTPBad.UserWarnedAboutSensitiveInput",
364 warning_is_user_visible);
365 }
366
367 void ChromeSecurityStateModelClient::DidFinishNavigation(
368 content::NavigationHandle* navigation_handle) {
369 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) {
370 // Only reset the console message flag for main-frame navigations,
371 // and not for same-page navigations like reference fragments and pushState.
372 logged_http_warning_on_current_navigation_ = false;
373 }
374 }
375
376 bool ChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() {
377 #if defined(OS_CHROMEOS)
378 policy::PolicyCertService* service =
379 policy::PolicyCertServiceFactory::GetForProfile(
380 Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
381 if (service && service->UsedPolicyCertificates())
382 return true;
383 #endif
384 return false;
385 }
386
387 bool ChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) {
388 return content::IsOriginSecure(url);
389 }
390
391 void ChromeSecurityStateModelClient::GetVisibleSecurityState(
392 SecurityStateModel::VisibleSecurityState* state) {
393 content::NavigationEntry* entry =
394 web_contents_->GetController().GetVisibleEntry();
395 if (!entry) {
396 *state = SecurityStateModel::VisibleSecurityState();
397 return;
398 }
399
400 if (!entry->GetSSL().initialized) {
401 *state = SecurityStateModel::VisibleSecurityState();
402 // Connection security information is still being initialized, but malware
403 // status might already be known.
404 CheckSafeBrowsingStatus(entry, web_contents_, state);
405 return;
406 }
407
408 state->connection_info_initialized = true;
409 state->url = entry->GetURL();
410 const content::SSLStatus& ssl = entry->GetSSL();
411 state->certificate = ssl.certificate;
412 state->cert_status = ssl.cert_status;
413 state->connection_status = ssl.connection_status;
414 state->key_exchange_group = ssl.key_exchange_group;
415 state->security_bits = ssl.security_bits;
416 state->pkp_bypassed = ssl.pkp_bypassed;
417 state->sct_verify_statuses.clear();
418 state->sct_verify_statuses.insert(state->sct_verify_statuses.begin(),
419 ssl.sct_statuses.begin(),
420 ssl.sct_statuses.end());
421 state->displayed_mixed_content =
422 !!(ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT);
423 state->ran_mixed_content =
424 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
425 state->displayed_content_with_cert_errors =
426 !!(ssl.content_status &
427 content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS);
428 state->ran_content_with_cert_errors =
429 !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS);
430 state->displayed_password_field_on_http =
431 !!(ssl.content_status &
432 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
433 state->displayed_credit_card_field_on_http =
434 !!(ssl.content_status &
435 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
436
437 CheckSafeBrowsingStatus(entry, web_contents_, state);
438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698