blob: d18e1f7cc6a3e930f6f8af9cc0a0fbb72342d534 [file] [log] [blame]
[email protected]03ef4b2a2012-03-06 15:04:201// Copyright (c) 2012 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
[email protected]4237dd52012-06-05 00:00:325#include "chrome/browser/ui/website_settings/website_settings.h"
[email protected]03ef4b2a2012-03-06 15:04:206
7#include <string>
8#include <vector>
9
[email protected]eb2140c2013-07-29 12:37:3410#include "base/command_line.h"
[email protected]15b092542012-05-16 13:08:1411#include "base/i18n/time_formatting.h"
[email protected]71cd5ef2014-08-13 21:22:0412#include "base/metrics/field_trial.h"
[email protected]3ea1b182013-02-08 22:38:4113#include "base/metrics/histogram.h"
14#include "base/strings/string_number_conversions.h"
jialiul02aad2d2015-04-01 18:56:0315#include "base/strings/stringprintf.h"
[email protected]774cc3c2013-06-07 20:26:4516#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3317#include "base/values.h"
jialiul02aad2d2015-04-01 18:56:0318#include "chrome/browser/browser_process.h"
[email protected]6b8a3c742014-07-25 00:25:3519#include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
[email protected]b0cb5e82012-07-19 19:22:4720#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
24#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
[email protected]77a91c72012-08-13 16:19:3425#include "chrome/browser/history/history_service_factory.h"
palmerf2cba0d2015-08-27 23:15:0626#include "chrome/browser/infobars/infobar_service.h"
[email protected]03ef4b2a2012-03-06 15:04:2027#include "chrome/browser/profiles/profile.h"
[email protected]71cd5ef2014-08-13 21:22:0428#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
29#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2030#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2631#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3232#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]71cd5ef2014-08-13 21:22:0433#include "chrome/common/chrome_switches.h"
jsbellddb849e2015-08-27 00:12:5634#include "chrome/common/url_constants.h"
thestig884a1602014-08-27 01:29:3935#include "chrome/grit/chromium_strings.h"
36#include "chrome/grit/generated_resources.h"
mukai8eaec822014-10-25 17:53:1637#include "components/content_settings/core/browser/content_settings_utils.h"
38#include "components/content_settings/core/browser/host_content_settings_map.h"
vabr48565592014-10-08 15:06:0239#include "components/content_settings/core/browser/local_shared_objects_counter.h"
palmer0da10b32015-02-11 00:42:1940#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1341#include "components/content_settings/core/common/content_settings_pattern.h"
jialiul02aad2d2015-04-01 18:56:0342#include "components/rappor/rappor_utils.h"
[email protected]0b9fdd72012-04-04 10:00:3343#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4244#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2345#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3446#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2047#include "content/public/common/ssl_status.h"
48#include "content/public/common/url_constants.h"
[email protected]be28b5f42012-07-20 11:31:2549#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1150#include "net/cert/cert_status_flags.h"
51#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5752#include "net/ssl/ssl_cipher_suite_names.h"
53#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2054#include "ui/base/l10n/l10n_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2055
[email protected]24a9f1c92013-11-13 12:33:3756#if defined(OS_CHROMEOS)
57#include "chrome/browser/chromeos/policy/policy_cert_service.h"
58#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
59#endif
60
[email protected]ab6df3b12013-12-24 23:32:2661using base::ASCIIToUTF16;
62using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5663using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3364using content::BrowserThread;
65
66namespace {
67
jww1ed8ea72014-09-02 20:43:2568// Events for UMA. Do not reorder or change!
69enum SSLCertificateDecisionsDidRevoke {
70 USER_CERT_DECISIONS_NOT_REVOKED = 0,
71 USER_CERT_DECISIONS_REVOKED,
72 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
73};
74
palmer0da10b32015-02-11 00:42:1975// The list of content settings types to display on the Website Settings UI. THE
76// ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email
77// [email protected].
[email protected]0b9fdd72012-04-04 10:00:3378ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:2179 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:2180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
81 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
palmer0da10b32015-02-11 00:42:1982 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
83 CONTENT_SETTINGS_TYPE_IMAGES,
84 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
85 CONTENT_SETTINGS_TYPE_POPUPS,
86 CONTENT_SETTINGS_TYPE_FULLSCREEN,
sashab2b2a314f2015-01-17 06:42:2187 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
palmer0da10b32015-02-11 00:42:1988 CONTENT_SETTINGS_TYPE_PLUGINS,
89 CONTENT_SETTINGS_TYPE_MOUSELOCK,
sashab2b2a314f2015-01-17 06:42:2190 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
benwellsa68ed4b2014-11-13 03:25:3691#if defined(OS_ANDROID)
sashab2b2a314f2015-01-17 06:42:2192 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
benwellsa68ed4b2014-11-13 03:25:3693#endif
[email protected]0b9fdd72012-04-04 10:00:3394};
95
[email protected]94c74b42013-12-02 15:19:4996bool CertificateTransparencyStatusMatch(
97 const content::SignedCertificateTimestampIDStatusList& scts,
98 net::ct::SCTVerifyStatus status) {
99 for (content::SignedCertificateTimestampIDStatusList::const_iterator it =
100 scts.begin();
101 it != scts.end();
102 ++it) {
103 if (it->status == status)
104 return true;
105 }
106
107 return false;
108}
109
110int GetSiteIdentityDetailsMessageByCTInfo(
111 const content::SignedCertificateTimestampIDStatusList& scts,
112 bool is_ev) {
113 // No SCTs - no CT information.
114 if (scts.empty())
115 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT
116 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT);
117
118 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_OK))
119 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED
120 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED);
121
122 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
123 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID
124 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID);
125
126 // status is SCT_STATUS_LOG_UNKNOWN
127 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED
128 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED);
129}
130
131// This function will return SITE_IDENTITY_STATUS_CERT or
132// SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless there are SCTs
133// which failed verification, in which case it will return
134// SITE_IDENTITY_STATUS_ERROR.
135WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo(
136 const content::SignedCertificateTimestampIDStatusList& scts,
137 bool is_ev) {
138 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
139 return WebsiteSettings::SITE_IDENTITY_STATUS_ERROR;
140
141 return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
142 : WebsiteSettings::SITE_IDENTITY_STATUS_CERT;
143}
144
[email protected]0b9fdd72012-04-04 10:00:33145} // namespace
146
147WebsiteSettings::WebsiteSettings(
148 WebsiteSettingsUI* ui,
149 Profile* profile,
[email protected]df818272012-04-20 13:10:50150 TabSpecificContentSettings* tab_specific_content_settings,
palmerf2cba0d2015-08-27 23:15:06151 content::WebContents* web_contents,
[email protected]0b9fdd72012-04-04 10:00:33152 const GURL& url,
153 const content::SSLStatus& ssl,
154 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:50155 : TabSpecificContentSettings::SiteDataObserver(
156 tab_specific_content_settings),
157 ui_(ui),
palmerf2cba0d2015-08-27 23:15:06158 web_contents_(web_contents),
[email protected]66f157312012-08-01 13:50:26159 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33160 site_url_(url),
161 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:11162 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:20163 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:33164 cert_store_(cert_store),
[email protected]71cd5ef2014-08-13 21:22:04165 content_settings_(profile->GetHostContentSettingsMap()),
166 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25167 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
168 did_revoke_user_ssl_decisions_(false) {
[email protected]03ef4b2a2012-03-06 15:04:20169 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:33170
171 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50172 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41173 PresentSiteIdentity();
[email protected]e22d64f2012-09-10 09:03:23174
175 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
176 // created. So this counts how ofter the Website Settings UI is opened.
lgarron04a93502014-11-04 22:25:04177 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20178}
179
[email protected]0b9fdd72012-04-04 10:00:33180WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20181}
182
lgarron04a93502014-11-04 22:25:04183void WebsiteSettings::RecordWebsiteSettingsAction(
184 WebsiteSettingsAction action) {
185 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action",
186 action,
187 WEBSITE_SETTINGS_COUNT);
188
189 // Use a separate histogram to record actions if they are done on a page with
190 // an HTTPS URL. Note that this *disregards* security status.
palmeree0e5af2015-06-05 03:10:40191 //
192
193 // TODO(palmer): Consider adding a new histogram for
194 // GURL::SchemeIsCryptographic. (We don't want to replace this call with a
195 // call to that function because we don't want to change the meanings of
196 // existing metrics.) This would inform the decision to mark non-secure
197 // origins as Dubious or Non-Secure; the overall bug for that is
198 // crbug.com/454579.
lgarron04a93502014-11-04 22:25:04199 if (site_url_.SchemeIs(url::kHttpsScheme)) {
200 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action.HttpsUrl",
201 action,
202 WEBSITE_SETTINGS_COUNT);
203 }
204}
205
jialiul02aad2d2015-04-01 18:56:03206// Get corresponding Rappor Metric.
207const std::string GetRapporMetric(ContentSettingsType permission) {
208 std::string permission_str;
209 switch (permission) {
210 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
211 permission_str = "Geolocation";
212 break;
213 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
214 permission_str = "Notifications";
215 break;
216 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
217 permission_str = "Mic";
218 break;
219 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
220 permission_str = "Camera";
221 break;
222 default:
223 return "";
224 }
225
226 return base::StringPrintf("ContentSettings.PermissionActions_%s.Revoked.Url",
227 permission_str.c_str());
228}
lgarron04a93502014-11-04 22:25:04229
[email protected]df818272012-04-20 13:10:50230void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
231 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23232 // Count how often a permission for a specific content type is changed using
233 // the Website Settings UI.
sashab9debecd2014-12-18 04:15:56234 ContentSettingsTypeHistogram histogram_value =
235 ContentSettingTypeToHistogramValue(type);
236 DCHECK_NE(histogram_value, CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID)
237 << "Invalid content setting type specified.";
238 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.OriginInfo.PermissionChanged",
239 histogram_value,
240 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
241
242 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
243 UMA_HISTOGRAM_ENUMERATION(
244 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
245 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
246 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
247 UMA_HISTOGRAM_ENUMERATION(
248 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
249 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
jialiul02aad2d2015-04-01 18:56:03250 // Trigger Rappor sampling if it is a permission revoke action.
251 const std::string& rappor_metric = GetRapporMetric(type);
252 if (!rappor_metric.empty()) {
253 rappor::SampleDomainAndRegistryFromGURL(
254 g_browser_process->rappor_service(), rappor_metric, this->site_url_);
255 }
sashab9debecd2014-12-18 04:15:56256 }
[email protected]e22d64f2012-09-10 09:03:23257
lgarron04a93502014-11-04 22:25:04258 // This is technically redundant given the histogram above, but putting the
259 // total count of permission changes in another histogram makes it easier to
260 // compare it against other kinds of actions in WebsiteSettings[PopupView].
261 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_CHANGED_PERMISSION);
262
[email protected]df818272012-04-20 13:10:50263 ContentSettingsPattern primary_pattern;
264 ContentSettingsPattern secondary_pattern;
265 switch (type) {
266 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34267 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
mlamouriab1897c2015-02-18 12:09:32268 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
[email protected]df818272012-04-20 13:10:50269 // TODO(markusheintz): The rule we create here should also change the
270 // location permission for iframed content.
271 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
272 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
273 break;
274 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
275 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
276 secondary_pattern = ContentSettingsPattern::Wildcard();
277 break;
[email protected]b1d113d2012-06-27 21:27:34278 case CONTENT_SETTINGS_TYPE_IMAGES:
279 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50280 case CONTENT_SETTINGS_TYPE_PLUGINS:
281 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34282 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27283 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
benwellsa68ed4b2014-11-13 03:25:36284 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
[email protected]df818272012-04-20 13:10:50285 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
286 secondary_pattern = ContentSettingsPattern::Wildcard();
287 break;
sashab2b2a314f2015-01-17 06:42:21288 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
289 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
[email protected]0bacc1912012-12-11 11:05:34290 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
291 secondary_pattern = ContentSettingsPattern::Wildcard();
[email protected]0bacc1912012-12-11 11:05:34292 break;
[email protected]df818272012-04-20 13:10:50293 default:
294 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
295 break;
[email protected]0b9fdd72012-04-04 10:00:33296 }
297
jialiul02aad2d2015-04-01 18:56:03298 // Permission settings are specified via rules. There exists always at least
299 // one rule for the default setting. Get the rule that currently defines
300 // the permission for the given permission |type|. Then test whether the
301 // existing rule is more specific than the rule we are about to create. If
302 // the existing rule is more specific, than change the existing rule instead
303 // of creating a new rule that would be hidden behind the existing rule.
304 content_settings::SettingInfo info;
305 scoped_ptr<base::Value> v =
raymes7dec6d862015-07-27 07:02:08306 content_settings_->GetWebsiteSetting(
jialiul02aad2d2015-04-01 18:56:03307 site_url_, site_url_, type, std::string(), &info);
308 content_settings_->SetNarrowestWebsiteSetting(
309 primary_pattern, secondary_pattern, type, std::string(), setting, info);
[email protected]df818272012-04-20 13:10:50310
[email protected]66f157312012-08-01 13:50:26311 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24312
[email protected]76955932012-12-06 11:01:10313// TODO(markusheintz): This is a temporary hack to fix issue:
314// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25315#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24316 // Refresh the UI to reflect the new setting.
317 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25318#endif
[email protected]df818272012-04-20 13:10:50319}
320
321void WebsiteSettings::OnSiteDataAccessed() {
322 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33323}
324
[email protected]66f157312012-08-01 13:50:26325void WebsiteSettings::OnUIClosing() {
palmerf2cba0d2015-08-27 23:15:06326 if (show_info_bar_ && web_contents_) {
327 InfoBarService* infobar_service =
328 InfoBarService::FromWebContents(web_contents_);
329 if (infobar_service)
330 WebsiteSettingsInfoBarDelegate::Create(infobar_service);
331 }
jww1ed8ea72014-09-02 20:43:25332
333 SSLCertificateDecisionsDidRevoke user_decision =
334 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
335 : USER_CERT_DECISIONS_NOT_REVOKED;
336
337 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions",
338 user_decision,
339 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
340}
341
342void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() {
343 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29344 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
345 site_url().host());
jww1ed8ea72014-09-02 20:43:25346 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26347}
348
[email protected]0b9fdd72012-04-04 10:00:33349void WebsiteSettings::Init(Profile* profile,
350 const GURL& url,
351 const content::SSLStatus& ssl) {
sashab97894ce2014-10-22 10:08:33352 bool isChromeUINativeScheme = false;
353#if defined(OS_ANDROID)
354 isChromeUINativeScheme = url.SchemeIs(chrome::kChromeUINativeScheme);
355#endif
356
357 if (url.SchemeIs(content::kChromeUIScheme) ||
358 url.SchemeIs(url::kAboutScheme) || isChromeUINativeScheme) {
[email protected]03ef4b2a2012-03-06 15:04:20359 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
360 site_identity_details_ =
361 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
362 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
363 return;
364 }
365
366 scoped_refptr<net::X509Certificate> cert;
367
368 // Identity section.
[email protected]a04db822013-12-11 19:14:40369 base::string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20370 if (subject_name.empty()) {
371 subject_name.assign(
372 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20373 }
374
[email protected]f61c1ce2012-05-09 13:55:11375 cert_id_ = ssl.cert_id;
376
[email protected]03ef4b2a2012-03-06 15:04:20377 if (ssl.cert_id &&
378 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
379 (!net::IsCertStatusError(ssl.cert_status) ||
380 net::IsCertStatusMinorError(ssl.cert_status))) {
381 // There are no major errors. Check for minor errors.
[email protected]24a9f1c92013-11-13 12:33:37382#if defined(OS_CHROMEOS)
383 policy::PolicyCertService* service =
384 policy::PolicyCertServiceFactory::GetForProfile(profile);
385 const bool used_policy_certs = service && service->UsedPolicyCertificates();
386#else
387 const bool used_policy_certs = false;
388#endif
389 if (used_policy_certs) {
[email protected]eaf3f322013-04-25 21:53:59390 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37391 site_identity_details_ = l10n_util::GetStringFUTF16(
392 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
[email protected]eaf3f322013-04-25 21:53:59393 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20394 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
[email protected]a04db822013-12-11 19:14:40395 base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20396 if (issuer_name.empty()) {
397 issuer_name.assign(l10n_util::GetStringUTF16(
398 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
399 }
[email protected]94c74b42013-12-02 15:19:49400
[email protected]03ef4b2a2012-03-06 15:04:20401 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49402 GetSiteIdentityDetailsMessageByCTInfo(
403 ssl.signed_certificate_timestamp_ids, false /* not EV */),
404 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20405
406 site_identity_details_ += ASCIIToUTF16("\n\n");
407 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
408 site_identity_details_ += l10n_util::GetStringUTF16(
409 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
410 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
411 site_identity_details_ += l10n_util::GetStringUTF16(
412 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
413 } else {
414 NOTREACHED() << "Need to specify string for this warning";
415 }
[email protected]03ef4b2a2012-03-06 15:04:20416 } else {
rsleevi4f8012722014-09-30 01:28:01417 if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
418 // EV HTTPS page.
419 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
420 ssl.signed_certificate_timestamp_ids, true);
421 DCHECK(!cert->subject().organization_names.empty());
422 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
423 // An EV Cert is required to have a city (localityName) and country but
424 // state is "if any".
425 DCHECK(!cert->subject().locality_name.empty());
426 DCHECK(!cert->subject().country_name.empty());
427 base::string16 locality;
428 if (!cert->subject().state_or_province_name.empty()) {
429 locality = l10n_util::GetStringFUTF16(
430 IDS_PAGEINFO_ADDRESS,
431 UTF8ToUTF16(cert->subject().locality_name),
432 UTF8ToUTF16(cert->subject().state_or_province_name),
433 UTF8ToUTF16(cert->subject().country_name));
434 } else {
435 locality = l10n_util::GetStringFUTF16(
436 IDS_PAGEINFO_PARTIAL_ADDRESS,
437 UTF8ToUTF16(cert->subject().locality_name),
438 UTF8ToUTF16(cert->subject().country_name));
439 }
440 DCHECK(!cert->subject().organization_names.empty());
441 site_identity_details_.assign(l10n_util::GetStringFUTF16(
442 GetSiteIdentityDetailsMessageByCTInfo(
443 ssl.signed_certificate_timestamp_ids, true /* is EV */),
444 UTF8ToUTF16(cert->subject().organization_names[0]),
445 locality,
446 UTF8ToUTF16(cert->issuer().GetDisplayName())));
447 } else {
448 // Non-EV OK HTTPS page.
449 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
450 ssl.signed_certificate_timestamp_ids, false);
451 base::string16 issuer_name(
452 UTF8ToUTF16(cert->issuer().GetDisplayName()));
453 if (issuer_name.empty()) {
454 issuer_name.assign(l10n_util::GetStringUTF16(
455 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
456 }
[email protected]94c74b42013-12-02 15:19:49457
rsleevi4f8012722014-09-30 01:28:01458 site_identity_details_.assign(l10n_util::GetStringFUTF16(
459 GetSiteIdentityDetailsMessageByCTInfo(
460 ssl.signed_certificate_timestamp_ids, false /* not EV */),
461 issuer_name));
462 }
463 // The date after which no new SHA-1 certificates may be issued.
464 // 2016-01-01 00:00:00 UTC
465 static const int64_t kSHA1LastIssuanceDate = INT64_C(13096080000000000);
466 if ((ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT) &&
467 cert->valid_expiry() >
rsleeviad6f5022015-04-24 18:57:50468 base::Time::FromInternalValue(kSHA1LastIssuanceDate)) {
rsleevi4f8012722014-09-30 01:28:01469 site_identity_status_ =
470 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
471 site_identity_details_ +=
472 UTF8ToUTF16("\n\n") +
473 l10n_util::GetStringUTF16(
474 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
475 }
[email protected]03ef4b2a2012-03-06 15:04:20476 }
477 } else {
478 // HTTP or HTTPS with errors (not warnings).
479 site_identity_details_.assign(l10n_util::GetStringUTF16(
480 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
481 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
482 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
483 else
484 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
485
[email protected]a04db822013-12-11 19:14:40486 const base::string16 bullet = UTF8ToUTF16("\n • ");
[email protected]03ef4b2a2012-03-06 15:04:20487 std::vector<SSLErrorInfo> errors;
488 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
489 url, &errors);
490 for (size_t i = 0; i < errors.size(); ++i) {
491 site_identity_details_ += bullet;
492 site_identity_details_ += errors[i].short_description();
493 }
494
495 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
496 site_identity_details_ += ASCIIToUTF16("\n\n");
497 site_identity_details_ += l10n_util::GetStringUTF16(
498 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
499 }
500 }
501
502 // Site Connection
503 // We consider anything less than 80 bits encryption to be weak encryption.
504 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
505 // weakly encrypted connections.
506 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
507
[email protected]1c1051d2014-05-10 11:39:58508 if (ssl.security_style == content::SECURITY_STYLE_UNKNOWN) {
509 // Page is still loading, so SSL status is not yet available. Say nothing.
510 DCHECK_EQ(ssl.security_bits, -1);
511 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
512
513 site_connection_details_.assign(l10n_util::GetStringFUTF16(
514 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
515 subject_name));
516 } else if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) {
517 // HTTPS without a certificate, or not HTTPS.
518 DCHECK(!ssl.cert_id);
519 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
[email protected]03ef4b2a2012-03-06 15:04:20520
521 site_connection_details_.assign(l10n_util::GetStringFUTF16(
522 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
523 subject_name));
524 } else if (ssl.security_bits < 0) {
525 // Security strength is unknown. Say nothing.
526 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
527 } else if (ssl.security_bits == 0) {
528 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
529 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
530 site_connection_details_.assign(l10n_util::GetStringFUTF16(
531 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
532 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20533 } else {
534 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22535
536 if (net::SSLConnectionStatusToVersion(ssl.connection_status) >=
537 net::SSL_CONNECTION_VERSION_TLS1_2 &&
538 net::IsSecureTLSCipherSuite(
539 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))) {
540 site_connection_details_.assign(l10n_util::GetStringFUTF16(
541 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
542 subject_name));
543 } else {
544 site_connection_details_.assign(l10n_util::GetStringFUTF16(
545 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
546 subject_name));
547 }
548
[email protected]03ef4b2a2012-03-06 15:04:20549 if (ssl.content_status) {
550 bool ran_insecure_content =
551 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
552 site_connection_status_ = ran_insecure_content ?
553 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
554 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
555 site_connection_details_.assign(l10n_util::GetStringFUTF16(
556 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
557 site_connection_details_,
558 l10n_util::GetStringUTF16(ran_insecure_content ?
559 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
560 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
561 }
562 }
563
564 uint16 cipher_suite =
565 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
566 if (ssl.security_bits > 0 && cipher_suite) {
567 int ssl_version =
568 net::SSLConnectionStatusToVersion(ssl.connection_status);
569 const char* ssl_version_str;
570 net::SSLVersionToString(&ssl_version_str, ssl_version);
571 site_connection_details_ += ASCIIToUTF16("\n\n");
572 site_connection_details_ += l10n_util::GetStringFUTF16(
573 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
574 ASCIIToUTF16(ssl_version_str));
575
[email protected]03ef4b2a2012-03-06 15:04:20576 bool no_renegotiation =
577 (ssl.connection_status &
578 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
579 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57580 bool is_aead;
581 net::SSLCipherSuiteToStrings(
582 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20583
584 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57585 if (is_aead) {
586 site_connection_details_ += l10n_util::GetStringFUTF16(
587 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
588 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
589 } else {
590 site_connection_details_ += l10n_util::GetStringFUTF16(
591 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
592 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
593 }
[email protected]03ef4b2a2012-03-06 15:04:20594
agl078d2102014-10-20 22:03:22595 if (ssl_version == net::SSL_CONNECTION_VERSION_SSL3 &&
596 site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) {
597 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
598 }
599
600 const bool did_fallback =
601 (ssl.connection_status & net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20602 if (did_fallback) {
[email protected]03ef4b2a2012-03-06 15:04:20603 site_connection_details_ += ASCIIToUTF16("\n\n");
604 site_connection_details_ += l10n_util::GetStringUTF16(
605 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
606 }
agl078d2102014-10-20 22:03:22607
[email protected]03ef4b2a2012-03-06 15:04:20608 if (no_renegotiation) {
609 site_connection_details_ += ASCIIToUTF16("\n\n");
610 site_connection_details_ += l10n_util::GetStringUTF16(
611 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
612 }
613 }
[email protected]e583f752012-08-30 13:26:21614
[email protected]71cd5ef2014-08-13 21:22:04615 // Check if a user decision has been made to allow or deny certificates with
616 // errors on this site.
617 ChromeSSLHostStateDelegate* delegate =
618 ChromeSSLHostStateDelegateFactory::GetForProfile(profile);
619 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40620 // Only show an SSL decision revoke button if the user has chosen to bypass
621 // SSL host errors for this host in the past.
622 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]71cd5ef2014-08-13 21:22:04623
[email protected]e583f752012-08-30 13:26:21624 // By default select the permissions tab that displays all the site
625 // permissions. In case of a connection error or an issue with the
626 // certificate presented by the website, select the connection tab to draw
627 // the user's attention to the issue. If the site does not provide a
628 // certificate because it was loaded over an unencrypted connection, don't
629 // select the connection tab.
630 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
631 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
632 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
633 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59634 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
rsleevi4f8012722014-09-30 01:28:01635 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT ||
636 site_identity_status_ ==
lgarron04a93502014-11-04 22:25:04637 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM) {
[email protected]e583f752012-08-30 13:26:21638 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
lgarron04a93502014-11-04 22:25:04639 RecordWebsiteSettingsAction(
640 WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY);
641 }
[email protected]e583f752012-08-30 13:26:21642 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20643}
[email protected]0b9fdd72012-04-04 10:00:33644
[email protected]df818272012-04-20 13:10:50645void WebsiteSettings::PresentSitePermissions() {
646 PermissionInfoList permission_info_list;
647
648 WebsiteSettingsUI::PermissionInfo permission_info;
649 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
650 permission_info.type = kPermissionType[i];
651
652 content_settings::SettingInfo info;
sashab2b2a314f2015-01-17 06:42:21653 scoped_ptr<base::Value> value =
raymes7dec6d862015-07-27 07:02:08654 content_settings_->GetWebsiteSetting(
sashab2b2a314f2015-01-17 06:42:21655 site_url_, site_url_, permission_info.type, std::string(), &info);
656 DCHECK(value.get());
657 if (value->GetType() == base::Value::TYPE_INTEGER) {
658 permission_info.setting =
659 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26660 } else {
sashab2b2a314f2015-01-17 06:42:21661 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26662 }
663
[email protected]8bdf45c32012-08-04 00:12:55664 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50665
[email protected]b1d113d2012-06-27 21:27:34666 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21667 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34668 permission_info.default_setting = permission_info.setting;
669 permission_info.setting = CONTENT_SETTING_DEFAULT;
670 } else {
671 permission_info.default_setting =
672 content_settings_->GetDefaultContentSetting(permission_info.type,
673 NULL);
[email protected]df818272012-04-20 13:10:50674 }
palmer0da10b32015-02-11 00:42:19675
676 if (permission_info.setting != CONTENT_SETTING_DEFAULT &&
677 permission_info.setting != permission_info.default_setting) {
678 permission_info_list.push_back(permission_info);
679 }
[email protected]df818272012-04-20 13:10:50680 }
681
682 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33683}
684
[email protected]df818272012-04-20 13:10:50685void WebsiteSettings::PresentSiteData() {
686 CookieInfoList cookie_info_list;
vabrd5e30cd2014-10-02 11:06:03687 const LocalSharedObjectsCounter& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34688 tab_specific_content_settings()->allowed_local_shared_objects();
vabrd5e30cd2014-10-02 11:06:03689 const LocalSharedObjectsCounter& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34690 tab_specific_content_settings()->blocked_local_shared_objects();
691
692 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50693 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34694 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29695 net::registry_controlled_domains::GetDomainAndRegistry(
696 site_url_,
[email protected]aabe1792014-01-30 21:37:46697 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34698 if (cookie_source.empty())
699 cookie_source = site_url_.host();
700 cookie_info.cookie_source = cookie_source;
701 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
702 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
703 cookie_info_list.push_back(cookie_info);
704
705 // Add third party cookie counts.
706 cookie_info.cookie_source = l10n_util::GetStringUTF8(
707 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
708 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
709 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50710 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33711
[email protected]df818272012-04-20 13:10:50712 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33713}
[email protected]16de6de2012-04-04 12:24:14714
[email protected]24c8818c2012-04-25 09:57:41715void WebsiteSettings::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04716 // After initialization the status about the site's connection and its
717 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41718 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
719 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
720 WebsiteSettingsUI::IdentityInfo info;
721 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
722 info.site_identity = UTF16ToUTF8(organization_name());
723 else
724 info.site_identity = site_url_.host();
725
726 info.connection_status = site_connection_status_;
727 info.connection_status_description =
728 UTF16ToUTF8(site_connection_details_);
729 info.identity_status = site_identity_status_;
730 info.identity_status_description =
731 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11732 info.cert_id = cert_id_;
[email protected]71cd5ef2014-08-13 21:22:04733 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
[email protected]24c8818c2012-04-25 09:57:41734 ui_->SetIdentityInfo(info);
735}