OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/metrics/field_trial.h" | |
11 #include "base/metrics/histogram_macros.h" | |
12 #include "base/strings/string16.h" | |
13 #include "base/strings/utf_string_conversions.h" | |
14 #include "build/build_config.h" | |
15 #include "chrome/browser/browser_process.h" | |
16 #include "chrome/browser/chromeos/policy/policy_cert_service.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" | |
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" | |
27 #include "content/public/browser/security_style_explanations.h" | |
28 #include "content/public/browser/ssl_status.h" | |
29 #include "content/public/browser/web_contents.h" | |
30 #include "content/public/common/origin_util.h" | |
31 #include "net/base/net_errors.h" | |
32 #include "net/cert/x509_certificate.h" | |
33 #include "net/ssl/ssl_cipher_suite_names.h" | |
34 #include "net/ssl/ssl_connection_status_flags.h" | |
35 #include "third_party/boringssl/src/include/openssl/ssl.h" | |
36 #include "ui/base/l10n/l10n_util.h" | |
37 | |
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModelClient); | |
39 | |
40 using safe_browsing::SafeBrowsingUIManager; | |
41 using security_state::SecurityStateModel; | |
42 | |
43 namespace { | |
44 | |
45 // 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 | |
47 // a blink::WebSecurityStyle. | |
48 blink::WebSecurityStyle SecurityLevelToSecurityStyle( | |
49 SecurityStateModel::SecurityLevel security_level) { | |
50 switch (security_level) { | |
51 case SecurityStateModel::NONE: | |
52 case SecurityStateModel::HTTP_SHOW_WARNING: | |
53 return blink::WebSecurityStyleUnauthenticated; | |
54 case SecurityStateModel::SECURITY_WARNING: | |
55 case SecurityStateModel::SECURE_WITH_POLICY_INSTALLED_CERT: | |
56 return blink::WebSecurityStyleWarning; | |
57 case SecurityStateModel::EV_SECURE: | |
58 case SecurityStateModel::SECURE: | |
59 return blink::WebSecurityStyleAuthenticated; | |
60 case SecurityStateModel::DANGEROUS: | |
61 return blink::WebSecurityStyleAuthenticationBroken; | |
62 } | |
63 | |
64 NOTREACHED(); | |
65 return blink::WebSecurityStyleUnknown; | |
66 } | |
67 | |
68 void AddConnectionExplanation( | |
69 const security_state::SecurityStateModel::SecurityInfo& security_info, | |
70 content::SecurityStyleExplanations* security_style_explanations) { | |
71 | |
72 // 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 | |
74 // check the |connection_status| to see if there was a connection. | |
75 if (security_info.connection_status == 0) { | |
76 return; | |
77 } | |
78 | |
79 int ssl_version = | |
80 net::SSLConnectionStatusToVersion(security_info.connection_status); | |
81 const char* protocol; | |
82 net::SSLVersionToString(&protocol, ssl_version); | |
83 const char* key_exchange; | |
84 const char* cipher; | |
85 const char* mac; | |
86 bool is_aead; | |
87 bool is_tls13; | |
88 uint16_t cipher_suite = | |
89 net::SSLConnectionStatusToCipherSuite(security_info.connection_status); | |
90 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, | |
91 &is_tls13, cipher_suite); | |
92 base::string16 protocol_name = base::ASCIIToUTF16(protocol); | |
93 const base::string16 cipher_name = | |
94 (mac == NULL) ? base::ASCIIToUTF16(cipher) | |
95 : l10n_util::GetStringFUTF16(IDS_CIPHER_WITH_MAC, | |
96 base::ASCIIToUTF16(cipher), | |
97 base::ASCIIToUTF16(mac)); | |
98 | |
99 // Include the key exchange group (previously known as curve) if specified. | |
100 base::string16 key_exchange_name; | |
101 if (is_tls13) { | |
102 key_exchange_name = base::ASCIIToUTF16( | |
103 SSL_get_curve_name(security_info.key_exchange_group)); | |
104 } else if (security_info.key_exchange_group != 0) { | |
105 key_exchange_name = l10n_util::GetStringFUTF16( | |
106 IDS_SSL_KEY_EXCHANGE_WITH_GROUP, base::ASCIIToUTF16(key_exchange), | |
107 base::ASCIIToUTF16( | |
108 SSL_get_curve_name(security_info.key_exchange_group))); | |
109 } else { | |
110 key_exchange_name = base::ASCIIToUTF16(key_exchange); | |
111 } | |
112 | |
113 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) { | |
114 security_style_explanations->secure_explanations.push_back( | |
115 content::SecurityStyleExplanation( | |
116 l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), | |
117 l10n_util::GetStringFUTF8(IDS_STRONG_SSL_DESCRIPTION, protocol_name, | |
118 key_exchange_name, cipher_name))); | |
119 return; | |
120 } | |
121 | |
122 std::vector<base::string16> description_replacements; | |
123 int status = security_info.obsolete_ssl_status; | |
124 int str_id; | |
125 | |
126 str_id = (status & net::OBSOLETE_SSL_MASK_PROTOCOL) | |
127 ? IDS_SSL_AN_OBSOLETE_PROTOCOL | |
128 : IDS_SSL_A_STRONG_PROTOCOL; | |
129 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); | |
130 description_replacements.push_back(protocol_name); | |
131 | |
132 str_id = (status & net::OBSOLETE_SSL_MASK_KEY_EXCHANGE) | |
133 ? IDS_SSL_AN_OBSOLETE_KEY_EXCHANGE | |
134 : IDS_SSL_A_STRONG_KEY_EXCHANGE; | |
135 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); | |
136 description_replacements.push_back(key_exchange_name); | |
137 | |
138 str_id = (status & net::OBSOLETE_SSL_MASK_CIPHER) ? IDS_SSL_AN_OBSOLETE_CIPHER | |
139 : IDS_SSL_A_STRONG_CIPHER; | |
140 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); | |
141 description_replacements.push_back(cipher_name); | |
142 | |
143 security_style_explanations->info_explanations.push_back( | |
144 content::SecurityStyleExplanation( | |
145 l10n_util::GetStringUTF8(IDS_OBSOLETE_SSL_SUMMARY), | |
146 base::UTF16ToUTF8( | |
147 l10n_util::GetStringFUTF16(IDS_OBSOLETE_SSL_DESCRIPTION, | |
148 description_replacements, nullptr)))); | |
149 } | |
150 | |
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 | |
168 | |
169 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( | |
170 content::WebContents* web_contents) | |
171 : content::WebContentsObserver(web_contents), | |
172 web_contents_(web_contents), | |
173 security_state_model_(new SecurityStateModel()), | |
174 logged_http_warning_on_current_navigation_(false) { | |
175 security_state_model_->SetClient(this); | |
176 } | |
177 | |
178 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} | |
179 | |
180 // static | |
181 blink::WebSecurityStyle ChromeSecurityStateModelClient::GetSecurityStyle( | |
182 const security_state::SecurityStateModel::SecurityInfo& security_info, | |
183 content::SecurityStyleExplanations* security_style_explanations) { | |
184 const blink::WebSecurityStyle security_style = | |
185 SecurityLevelToSecurityStyle(security_info.security_level); | |
186 | |
187 if (security_info.security_level == | |
188 security_state::SecurityStateModel::HTTP_SHOW_WARNING) { | |
189 // If the HTTP_SHOW_WARNING field trial is in use, display an | |
190 // unauthenticated explanation explaining why the omnibox warning is | |
191 // present. | |
192 security_style_explanations->unauthenticated_explanations.push_back( | |
193 content::SecurityStyleExplanation( | |
194 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), | |
195 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT_DESCRIPTION))); | |
196 } else if (security_info.security_level == | |
197 security_state::SecurityStateModel::NONE && | |
198 security_info.displayed_private_user_data_input_on_http) { | |
199 // 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 | |
201 // this site in a future version of Chrome. | |
202 security_style_explanations->info_explanations.push_back( | |
203 content::SecurityStyleExplanation( | |
204 l10n_util::GetStringUTF8(IDS_PRIVATE_USER_DATA_INPUT), | |
205 l10n_util::GetStringUTF8( | |
206 IDS_PRIVATE_USER_DATA_INPUT_FUTURE_DESCRIPTION))); | |
207 } | |
208 | |
209 security_style_explanations->ran_insecure_content_style = | |
210 SecurityLevelToSecurityStyle( | |
211 SecurityStateModel::kRanInsecureContentLevel); | |
212 security_style_explanations->displayed_insecure_content_style = | |
213 SecurityLevelToSecurityStyle( | |
214 SecurityStateModel::kDisplayedInsecureContentLevel); | |
215 | |
216 // Check if the page is HTTP; if so, no more explanations are needed. Note | |
217 // that SecurityStyleUnauthenticated does not necessarily mean that | |
218 // the page is loaded over HTTP, because the security style merely | |
219 // 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 | |
221 // if it wants to (for example, displaying deprecated crypto | |
222 // algorithms with the same UI treatment as HTTP pages). | |
223 security_style_explanations->scheme_is_cryptographic = | |
224 security_info.scheme_is_cryptographic; | |
225 if (!security_info.scheme_is_cryptographic) { | |
226 return security_style; | |
227 } | |
228 | |
229 if (security_info.sha1_deprecation_status == | |
230 SecurityStateModel::DEPRECATED_SHA1_MAJOR) { | |
231 security_style_explanations->broken_explanations.push_back( | |
232 content::SecurityStyleExplanation( | |
233 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1), | |
234 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION), | |
235 !!security_info.certificate)); | |
236 } else if (security_info.sha1_deprecation_status == | |
237 SecurityStateModel::DEPRECATED_SHA1_MINOR) { | |
238 security_style_explanations->unauthenticated_explanations.push_back( | |
239 content::SecurityStyleExplanation( | |
240 l10n_util::GetStringUTF8(IDS_MINOR_SHA1), | |
241 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION), | |
242 !!security_info.certificate)); | |
243 } | |
244 | |
245 // Record the presence of mixed content (HTTP subresources on an HTTPS | |
246 // page). | |
247 security_style_explanations->ran_mixed_content = | |
248 security_info.mixed_content_status == | |
249 SecurityStateModel::CONTENT_STATUS_RAN || | |
250 security_info.mixed_content_status == | |
251 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
252 security_style_explanations->displayed_mixed_content = | |
253 security_info.mixed_content_status == | |
254 SecurityStateModel::CONTENT_STATUS_DISPLAYED || | |
255 security_info.mixed_content_status == | |
256 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
257 | |
258 bool is_cert_status_error = net::IsCertStatusError(security_info.cert_status); | |
259 bool is_cert_status_minor_error = | |
260 net::IsCertStatusMinorError(security_info.cert_status); | |
261 | |
262 // If the main resource was loaded no certificate errors or only minor | |
263 // certificate errors, then record the presence of subresources with | |
264 // certificate errors. Subresource certificate errors aren't recorded | |
265 // when the main resource was loaded with major certificate errors | |
266 // because, in the common case, these subresource certificate errors | |
267 // would be duplicative with the main resource's error. | |
268 if (!is_cert_status_error || is_cert_status_minor_error) { | |
269 security_style_explanations->ran_content_with_cert_errors = | |
270 security_info.content_with_cert_errors_status == | |
271 SecurityStateModel::CONTENT_STATUS_RAN || | |
272 security_info.content_with_cert_errors_status == | |
273 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
274 security_style_explanations->displayed_content_with_cert_errors = | |
275 security_info.content_with_cert_errors_status == | |
276 SecurityStateModel::CONTENT_STATUS_DISPLAYED || | |
277 security_info.content_with_cert_errors_status == | |
278 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
279 } | |
280 | |
281 if (is_cert_status_error) { | |
282 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString( | |
283 net::MapCertStatusToNetError(security_info.cert_status))); | |
284 | |
285 content::SecurityStyleExplanation explanation( | |
286 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), | |
287 l10n_util::GetStringFUTF8( | |
288 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), | |
289 !!security_info.certificate); | |
290 | |
291 if (is_cert_status_minor_error) { | |
292 security_style_explanations->unauthenticated_explanations.push_back( | |
293 explanation); | |
294 } else { | |
295 security_style_explanations->broken_explanations.push_back(explanation); | |
296 } | |
297 } else { | |
298 // If the certificate does not have errors and is not using | |
299 // deprecated SHA1, then add an explanation that the certificate is | |
300 // valid. | |
301 if (security_info.sha1_deprecation_status == | |
302 SecurityStateModel::NO_DEPRECATED_SHA1) { | |
303 security_style_explanations->secure_explanations.push_back( | |
304 content::SecurityStyleExplanation( | |
305 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), | |
306 l10n_util::GetStringUTF8( | |
307 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), | |
308 !!security_info.certificate)); | |
309 } | |
310 } | |
311 | |
312 AddConnectionExplanation(security_info, security_style_explanations); | |
313 | |
314 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed; | |
315 if (security_info.pkp_bypassed) { | |
316 security_style_explanations->info_explanations.push_back( | |
317 content::SecurityStyleExplanation( | |
318 "Public-Key Pinning Bypassed", | |
319 "Public-key pinning was bypassed by a local root certificate.")); | |
320 } | |
321 | |
322 return security_style; | |
323 } | |
324 | |
325 void ChromeSecurityStateModelClient::GetSecurityInfo( | |
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 } | |
OLD | NEW |