blob: 9993b87b7aa0b1429b21e441d91c85309383e496 [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"
[email protected]03ef4b2a2012-03-06 15:04:2026#include "chrome/browser/profiles/profile.h"
[email protected]71cd5ef2014-08-13 21:22:0427#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
28#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2029#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2630#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3231#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]71cd5ef2014-08-13 21:22:0432#include "chrome/common/chrome_switches.h"
jsbellddb849e2015-08-27 00:12:5633#include "chrome/common/url_constants.h"
thestig884a1602014-08-27 01:29:3934#include "chrome/grit/chromium_strings.h"
35#include "chrome/grit/generated_resources.h"
mukai8eaec822014-10-25 17:53:1636#include "components/content_settings/core/browser/content_settings_utils.h"
37#include "components/content_settings/core/browser/host_content_settings_map.h"
vabr48565592014-10-08 15:06:0238#include "components/content_settings/core/browser/local_shared_objects_counter.h"
palmer0da10b32015-02-11 00:42:1939#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1340#include "components/content_settings/core/common/content_settings_pattern.h"
jialiul02aad2d2015-04-01 18:56:0341#include "components/rappor/rappor_utils.h"
[email protected]0b9fdd72012-04-04 10:00:3342#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4243#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2344#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3445#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2046#include "content/public/common/ssl_status.h"
47#include "content/public/common/url_constants.h"
[email protected]be28b5f42012-07-20 11:31:2548#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1149#include "net/cert/cert_status_flags.h"
50#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5751#include "net/ssl/ssl_cipher_suite_names.h"
52#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2053#include "ui/base/l10n/l10n_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2054
[email protected]24a9f1c92013-11-13 12:33:3755#if defined(OS_CHROMEOS)
56#include "chrome/browser/chromeos/policy/policy_cert_service.h"
57#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
58#endif
59
[email protected]ab6df3b12013-12-24 23:32:2660using base::ASCIIToUTF16;
61using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5662using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3363using content::BrowserThread;
64
65namespace {
66
jww1ed8ea72014-09-02 20:43:2567// Events for UMA. Do not reorder or change!
68enum SSLCertificateDecisionsDidRevoke {
69 USER_CERT_DECISIONS_NOT_REVOKED = 0,
70 USER_CERT_DECISIONS_REVOKED,
71 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
72};
73
palmer0da10b32015-02-11 00:42:1974// The list of content settings types to display on the Website Settings UI. THE
75// ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email
76// [email protected].
[email protected]0b9fdd72012-04-04 10:00:3377ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:2178 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:2179 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
80 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
palmer0da10b32015-02-11 00:42:1981 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
82 CONTENT_SETTINGS_TYPE_IMAGES,
83 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
84 CONTENT_SETTINGS_TYPE_POPUPS,
85 CONTENT_SETTINGS_TYPE_FULLSCREEN,
sashab2b2a314f2015-01-17 06:42:2186 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
palmer0da10b32015-02-11 00:42:1987 CONTENT_SETTINGS_TYPE_PLUGINS,
88 CONTENT_SETTINGS_TYPE_MOUSELOCK,
sashab2b2a314f2015-01-17 06:42:2189 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
benwellsa68ed4b2014-11-13 03:25:3690#if defined(OS_ANDROID)
sashab2b2a314f2015-01-17 06:42:2191 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
benwellsa68ed4b2014-11-13 03:25:3692#endif
[email protected]0b9fdd72012-04-04 10:00:3393};
94
[email protected]94c74b42013-12-02 15:19:4995bool CertificateTransparencyStatusMatch(
96 const content::SignedCertificateTimestampIDStatusList& scts,
97 net::ct::SCTVerifyStatus status) {
98 for (content::SignedCertificateTimestampIDStatusList::const_iterator it =
99 scts.begin();
100 it != scts.end();
101 ++it) {
102 if (it->status == status)
103 return true;
104 }
105
106 return false;
107}
108
109int GetSiteIdentityDetailsMessageByCTInfo(
110 const content::SignedCertificateTimestampIDStatusList& scts,
111 bool is_ev) {
112 // No SCTs - no CT information.
113 if (scts.empty())
114 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT
115 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT);
116
117 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_OK))
118 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED
119 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED);
120
121 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
122 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID
123 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID);
124
125 // status is SCT_STATUS_LOG_UNKNOWN
126 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED
127 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED);
128}
129
130// This function will return SITE_IDENTITY_STATUS_CERT or
131// SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless there are SCTs
132// which failed verification, in which case it will return
133// SITE_IDENTITY_STATUS_ERROR.
134WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo(
135 const content::SignedCertificateTimestampIDStatusList& scts,
136 bool is_ev) {
137 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
138 return WebsiteSettings::SITE_IDENTITY_STATUS_ERROR;
139
140 return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
141 : WebsiteSettings::SITE_IDENTITY_STATUS_CERT;
142}
143
[email protected]0b9fdd72012-04-04 10:00:33144} // namespace
145
146WebsiteSettings::WebsiteSettings(
147 WebsiteSettingsUI* ui,
148 Profile* profile,
[email protected]df818272012-04-20 13:10:50149 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:42150 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:33151 const GURL& url,
152 const content::SSLStatus& ssl,
153 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:50154 : TabSpecificContentSettings::SiteDataObserver(
155 tab_specific_content_settings),
156 ui_(ui),
[email protected]4f822f022012-12-20 19:11:42157 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:26158 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33159 site_url_(url),
160 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:11161 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:20162 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:33163 cert_store_(cert_store),
[email protected]71cd5ef2014-08-13 21:22:04164 content_settings_(profile->GetHostContentSettingsMap()),
165 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25166 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
167 did_revoke_user_ssl_decisions_(false) {
[email protected]03ef4b2a2012-03-06 15:04:20168 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:33169
[email protected]0b9fdd72012-04-04 10:00:33170 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50171 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41172 PresentSiteIdentity();
[email protected]e22d64f2012-09-10 09:03:23173
174 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
175 // created. So this counts how ofter the Website Settings UI is opened.
lgarron04a93502014-11-04 22:25:04176 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20177}
178
[email protected]0b9fdd72012-04-04 10:00:33179WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20180}
181
lgarron04a93502014-11-04 22:25:04182void WebsiteSettings::RecordWebsiteSettingsAction(
183 WebsiteSettingsAction action) {
184 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action",
185 action,
186 WEBSITE_SETTINGS_COUNT);
187
188 // Use a separate histogram to record actions if they are done on a page with
189 // an HTTPS URL. Note that this *disregards* security status.
palmeree0e5af2015-06-05 03:10:40190 //
191
192 // TODO(palmer): Consider adding a new histogram for
193 // GURL::SchemeIsCryptographic. (We don't want to replace this call with a
194 // call to that function because we don't want to change the meanings of
195 // existing metrics.) This would inform the decision to mark non-secure
196 // origins as Dubious or Non-Secure; the overall bug for that is
197 // crbug.com/454579.
lgarron04a93502014-11-04 22:25:04198 if (site_url_.SchemeIs(url::kHttpsScheme)) {
199 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action.HttpsUrl",
200 action,
201 WEBSITE_SETTINGS_COUNT);
202 }
203}
204
jialiul02aad2d2015-04-01 18:56:03205// Get corresponding Rappor Metric.
206const std::string GetRapporMetric(ContentSettingsType permission) {
207 std::string permission_str;
208 switch (permission) {
209 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
210 permission_str = "Geolocation";
211 break;
212 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
213 permission_str = "Notifications";
214 break;
215 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
216 permission_str = "Mic";
217 break;
218 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
219 permission_str = "Camera";
220 break;
221 default:
222 return "";
223 }
224
225 return base::StringPrintf("ContentSettings.PermissionActions_%s.Revoked.Url",
226 permission_str.c_str());
227}
lgarron04a93502014-11-04 22:25:04228
[email protected]df818272012-04-20 13:10:50229void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
230 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23231 // Count how often a permission for a specific content type is changed using
232 // the Website Settings UI.
sashab9debecd2014-12-18 04:15:56233 ContentSettingsTypeHistogram histogram_value =
234 ContentSettingTypeToHistogramValue(type);
235 DCHECK_NE(histogram_value, CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID)
236 << "Invalid content setting type specified.";
237 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.OriginInfo.PermissionChanged",
238 histogram_value,
239 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
240
241 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
242 UMA_HISTOGRAM_ENUMERATION(
243 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
244 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
245 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
246 UMA_HISTOGRAM_ENUMERATION(
247 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
248 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
jialiul02aad2d2015-04-01 18:56:03249 // Trigger Rappor sampling if it is a permission revoke action.
250 const std::string& rappor_metric = GetRapporMetric(type);
251 if (!rappor_metric.empty()) {
252 rappor::SampleDomainAndRegistryFromGURL(
253 g_browser_process->rappor_service(), rappor_metric, this->site_url_);
254 }
sashab9debecd2014-12-18 04:15:56255 }
[email protected]e22d64f2012-09-10 09:03:23256
lgarron04a93502014-11-04 22:25:04257 // This is technically redundant given the histogram above, but putting the
258 // total count of permission changes in another histogram makes it easier to
259 // compare it against other kinds of actions in WebsiteSettings[PopupView].
260 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_CHANGED_PERMISSION);
261
[email protected]df818272012-04-20 13:10:50262 ContentSettingsPattern primary_pattern;
263 ContentSettingsPattern secondary_pattern;
264 switch (type) {
265 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34266 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
mlamouriab1897c2015-02-18 12:09:32267 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
[email protected]df818272012-04-20 13:10:50268 // TODO(markusheintz): The rule we create here should also change the
269 // location permission for iframed content.
270 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
271 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
272 break;
273 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
274 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
275 secondary_pattern = ContentSettingsPattern::Wildcard();
276 break;
[email protected]b1d113d2012-06-27 21:27:34277 case CONTENT_SETTINGS_TYPE_IMAGES:
278 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50279 case CONTENT_SETTINGS_TYPE_PLUGINS:
280 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34281 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27282 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
benwellsa68ed4b2014-11-13 03:25:36283 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
[email protected]df818272012-04-20 13:10:50284 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
285 secondary_pattern = ContentSettingsPattern::Wildcard();
286 break;
sashab2b2a314f2015-01-17 06:42:21287 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
288 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
[email protected]0bacc1912012-12-11 11:05:34289 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
290 secondary_pattern = ContentSettingsPattern::Wildcard();
[email protected]0bacc1912012-12-11 11:05:34291 break;
[email protected]df818272012-04-20 13:10:50292 default:
293 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
294 break;
[email protected]0b9fdd72012-04-04 10:00:33295 }
296
jialiul02aad2d2015-04-01 18:56:03297 // Permission settings are specified via rules. There exists always at least
298 // one rule for the default setting. Get the rule that currently defines
299 // the permission for the given permission |type|. Then test whether the
300 // existing rule is more specific than the rule we are about to create. If
301 // the existing rule is more specific, than change the existing rule instead
302 // of creating a new rule that would be hidden behind the existing rule.
303 content_settings::SettingInfo info;
304 scoped_ptr<base::Value> v =
raymes7dec6d862015-07-27 07:02:08305 content_settings_->GetWebsiteSetting(
jialiul02aad2d2015-04-01 18:56:03306 site_url_, site_url_, type, std::string(), &info);
307 content_settings_->SetNarrowestWebsiteSetting(
308 primary_pattern, secondary_pattern, type, std::string(), setting, info);
[email protected]df818272012-04-20 13:10:50309
[email protected]66f157312012-08-01 13:50:26310 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24311
[email protected]76955932012-12-06 11:01:10312// TODO(markusheintz): This is a temporary hack to fix issue:
313// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25314#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24315 // Refresh the UI to reflect the new setting.
316 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25317#endif
[email protected]df818272012-04-20 13:10:50318}
319
[email protected]df818272012-04-20 13:10:50320void WebsiteSettings::OnSiteDataAccessed() {
321 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33322}
323
[email protected]66f157312012-08-01 13:50:26324void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50325 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36326 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
jww1ed8ea72014-09-02 20:43:25327
328 SSLCertificateDecisionsDidRevoke user_decision =
329 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
330 : USER_CERT_DECISIONS_NOT_REVOKED;
331
332 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions",
333 user_decision,
334 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
335}
336
337void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() {
338 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29339 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
340 site_url().host());
jww1ed8ea72014-09-02 20:43:25341 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26342}
343
[email protected]0b9fdd72012-04-04 10:00:33344void WebsiteSettings::Init(Profile* profile,
345 const GURL& url,
346 const content::SSLStatus& ssl) {
sashab97894ce2014-10-22 10:08:33347 bool isChromeUINativeScheme = false;
348#if defined(OS_ANDROID)
349 isChromeUINativeScheme = url.SchemeIs(chrome::kChromeUINativeScheme);
350#endif
351
352 if (url.SchemeIs(content::kChromeUIScheme) ||
353 url.SchemeIs(url::kAboutScheme) || isChromeUINativeScheme) {
[email protected]03ef4b2a2012-03-06 15:04:20354 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
355 site_identity_details_ =
356 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
357 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
358 return;
359 }
360
361 scoped_refptr<net::X509Certificate> cert;
362
363 // Identity section.
[email protected]a04db822013-12-11 19:14:40364 base::string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20365 if (subject_name.empty()) {
366 subject_name.assign(
367 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20368 }
369
[email protected]f61c1ce2012-05-09 13:55:11370 cert_id_ = ssl.cert_id;
371
[email protected]03ef4b2a2012-03-06 15:04:20372 if (ssl.cert_id &&
373 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
374 (!net::IsCertStatusError(ssl.cert_status) ||
375 net::IsCertStatusMinorError(ssl.cert_status))) {
376 // There are no major errors. Check for minor errors.
[email protected]24a9f1c92013-11-13 12:33:37377#if defined(OS_CHROMEOS)
378 policy::PolicyCertService* service =
379 policy::PolicyCertServiceFactory::GetForProfile(profile);
380 const bool used_policy_certs = service && service->UsedPolicyCertificates();
381#else
382 const bool used_policy_certs = false;
383#endif
384 if (used_policy_certs) {
[email protected]eaf3f322013-04-25 21:53:59385 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37386 site_identity_details_ = l10n_util::GetStringFUTF16(
387 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
[email protected]eaf3f322013-04-25 21:53:59388 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20389 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
[email protected]a04db822013-12-11 19:14:40390 base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20391 if (issuer_name.empty()) {
392 issuer_name.assign(l10n_util::GetStringUTF16(
393 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
394 }
[email protected]94c74b42013-12-02 15:19:49395
[email protected]03ef4b2a2012-03-06 15:04:20396 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49397 GetSiteIdentityDetailsMessageByCTInfo(
398 ssl.signed_certificate_timestamp_ids, false /* not EV */),
399 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20400
401 site_identity_details_ += ASCIIToUTF16("\n\n");
402 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
403 site_identity_details_ += l10n_util::GetStringUTF16(
404 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
405 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
406 site_identity_details_ += l10n_util::GetStringUTF16(
407 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
408 } else {
409 NOTREACHED() << "Need to specify string for this warning";
410 }
[email protected]03ef4b2a2012-03-06 15:04:20411 } else {
rsleevi4f8012722014-09-30 01:28:01412 if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
413 // EV HTTPS page.
414 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
415 ssl.signed_certificate_timestamp_ids, true);
416 DCHECK(!cert->subject().organization_names.empty());
417 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
418 // An EV Cert is required to have a city (localityName) and country but
419 // state is "if any".
420 DCHECK(!cert->subject().locality_name.empty());
421 DCHECK(!cert->subject().country_name.empty());
422 base::string16 locality;
423 if (!cert->subject().state_or_province_name.empty()) {
424 locality = l10n_util::GetStringFUTF16(
425 IDS_PAGEINFO_ADDRESS,
426 UTF8ToUTF16(cert->subject().locality_name),
427 UTF8ToUTF16(cert->subject().state_or_province_name),
428 UTF8ToUTF16(cert->subject().country_name));
429 } else {
430 locality = l10n_util::GetStringFUTF16(
431 IDS_PAGEINFO_PARTIAL_ADDRESS,
432 UTF8ToUTF16(cert->subject().locality_name),
433 UTF8ToUTF16(cert->subject().country_name));
434 }
435 DCHECK(!cert->subject().organization_names.empty());
436 site_identity_details_.assign(l10n_util::GetStringFUTF16(
437 GetSiteIdentityDetailsMessageByCTInfo(
438 ssl.signed_certificate_timestamp_ids, true /* is EV */),
439 UTF8ToUTF16(cert->subject().organization_names[0]),
440 locality,
441 UTF8ToUTF16(cert->issuer().GetDisplayName())));
442 } else {
443 // Non-EV OK HTTPS page.
444 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
445 ssl.signed_certificate_timestamp_ids, false);
446 base::string16 issuer_name(
447 UTF8ToUTF16(cert->issuer().GetDisplayName()));
448 if (issuer_name.empty()) {
449 issuer_name.assign(l10n_util::GetStringUTF16(
450 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
451 }
[email protected]94c74b42013-12-02 15:19:49452
rsleevi4f8012722014-09-30 01:28:01453 site_identity_details_.assign(l10n_util::GetStringFUTF16(
454 GetSiteIdentityDetailsMessageByCTInfo(
455 ssl.signed_certificate_timestamp_ids, false /* not EV */),
456 issuer_name));
457 }
458 // The date after which no new SHA-1 certificates may be issued.
459 // 2016-01-01 00:00:00 UTC
460 static const int64_t kSHA1LastIssuanceDate = INT64_C(13096080000000000);
461 if ((ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT) &&
462 cert->valid_expiry() >
rsleeviad6f5022015-04-24 18:57:50463 base::Time::FromInternalValue(kSHA1LastIssuanceDate)) {
rsleevi4f8012722014-09-30 01:28:01464 site_identity_status_ =
465 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
466 site_identity_details_ +=
467 UTF8ToUTF16("\n\n") +
468 l10n_util::GetStringUTF16(
469 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
470 }
[email protected]03ef4b2a2012-03-06 15:04:20471 }
472 } else {
473 // HTTP or HTTPS with errors (not warnings).
474 site_identity_details_.assign(l10n_util::GetStringUTF16(
475 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
476 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
477 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
478 else
479 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
480
[email protected]a04db822013-12-11 19:14:40481 const base::string16 bullet = UTF8ToUTF16("\n • ");
[email protected]03ef4b2a2012-03-06 15:04:20482 std::vector<SSLErrorInfo> errors;
483 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
484 url, &errors);
485 for (size_t i = 0; i < errors.size(); ++i) {
486 site_identity_details_ += bullet;
487 site_identity_details_ += errors[i].short_description();
488 }
489
490 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
491 site_identity_details_ += ASCIIToUTF16("\n\n");
492 site_identity_details_ += l10n_util::GetStringUTF16(
493 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
494 }
495 }
496
497 // Site Connection
498 // We consider anything less than 80 bits encryption to be weak encryption.
499 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
500 // weakly encrypted connections.
501 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
502
[email protected]1c1051d2014-05-10 11:39:58503 if (ssl.security_style == content::SECURITY_STYLE_UNKNOWN) {
504 // Page is still loading, so SSL status is not yet available. Say nothing.
505 DCHECK_EQ(ssl.security_bits, -1);
506 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
507
508 site_connection_details_.assign(l10n_util::GetStringFUTF16(
509 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
510 subject_name));
511 } else if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) {
512 // HTTPS without a certificate, or not HTTPS.
513 DCHECK(!ssl.cert_id);
514 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
[email protected]03ef4b2a2012-03-06 15:04:20515
516 site_connection_details_.assign(l10n_util::GetStringFUTF16(
517 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
518 subject_name));
519 } else if (ssl.security_bits < 0) {
520 // Security strength is unknown. Say nothing.
521 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
522 } else if (ssl.security_bits == 0) {
523 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
524 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
525 site_connection_details_.assign(l10n_util::GetStringFUTF16(
526 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
527 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20528 } else {
529 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22530
531 if (net::SSLConnectionStatusToVersion(ssl.connection_status) >=
532 net::SSL_CONNECTION_VERSION_TLS1_2 &&
533 net::IsSecureTLSCipherSuite(
534 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))) {
535 site_connection_details_.assign(l10n_util::GetStringFUTF16(
536 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
537 subject_name));
538 } else {
539 site_connection_details_.assign(l10n_util::GetStringFUTF16(
540 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
541 subject_name));
542 }
543
[email protected]03ef4b2a2012-03-06 15:04:20544 if (ssl.content_status) {
545 bool ran_insecure_content =
546 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
547 site_connection_status_ = ran_insecure_content ?
548 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
549 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
550 site_connection_details_.assign(l10n_util::GetStringFUTF16(
551 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
552 site_connection_details_,
553 l10n_util::GetStringUTF16(ran_insecure_content ?
554 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
555 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
556 }
557 }
558
559 uint16 cipher_suite =
560 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
561 if (ssl.security_bits > 0 && cipher_suite) {
562 int ssl_version =
563 net::SSLConnectionStatusToVersion(ssl.connection_status);
564 const char* ssl_version_str;
565 net::SSLVersionToString(&ssl_version_str, ssl_version);
566 site_connection_details_ += ASCIIToUTF16("\n\n");
567 site_connection_details_ += l10n_util::GetStringFUTF16(
568 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
569 ASCIIToUTF16(ssl_version_str));
570
[email protected]03ef4b2a2012-03-06 15:04:20571 bool no_renegotiation =
572 (ssl.connection_status &
573 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
574 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57575 bool is_aead;
576 net::SSLCipherSuiteToStrings(
577 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20578
579 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57580 if (is_aead) {
581 site_connection_details_ += l10n_util::GetStringFUTF16(
582 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
583 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
584 } else {
585 site_connection_details_ += l10n_util::GetStringFUTF16(
586 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
587 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
588 }
[email protected]03ef4b2a2012-03-06 15:04:20589
agl078d2102014-10-20 22:03:22590 if (ssl_version == net::SSL_CONNECTION_VERSION_SSL3 &&
591 site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) {
592 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
593 }
594
595 const bool did_fallback =
596 (ssl.connection_status & net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20597 if (did_fallback) {
[email protected]03ef4b2a2012-03-06 15:04:20598 site_connection_details_ += ASCIIToUTF16("\n\n");
599 site_connection_details_ += l10n_util::GetStringUTF16(
600 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
601 }
agl078d2102014-10-20 22:03:22602
[email protected]03ef4b2a2012-03-06 15:04:20603 if (no_renegotiation) {
604 site_connection_details_ += ASCIIToUTF16("\n\n");
605 site_connection_details_ += l10n_util::GetStringUTF16(
606 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
607 }
608 }
[email protected]e583f752012-08-30 13:26:21609
[email protected]71cd5ef2014-08-13 21:22:04610 // Check if a user decision has been made to allow or deny certificates with
611 // errors on this site.
612 ChromeSSLHostStateDelegate* delegate =
613 ChromeSSLHostStateDelegateFactory::GetForProfile(profile);
614 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40615 // Only show an SSL decision revoke button if the user has chosen to bypass
616 // SSL host errors for this host in the past.
617 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]71cd5ef2014-08-13 21:22:04618
[email protected]e583f752012-08-30 13:26:21619 // By default select the permissions tab that displays all the site
620 // permissions. In case of a connection error or an issue with the
621 // certificate presented by the website, select the connection tab to draw
622 // the user's attention to the issue. If the site does not provide a
623 // certificate because it was loaded over an unencrypted connection, don't
624 // select the connection tab.
625 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
626 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
627 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
628 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59629 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
rsleevi4f8012722014-09-30 01:28:01630 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT ||
631 site_identity_status_ ==
lgarron04a93502014-11-04 22:25:04632 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM) {
[email protected]e583f752012-08-30 13:26:21633 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
lgarron04a93502014-11-04 22:25:04634 RecordWebsiteSettingsAction(
635 WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY);
636 }
[email protected]e583f752012-08-30 13:26:21637 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20638}
[email protected]0b9fdd72012-04-04 10:00:33639
[email protected]df818272012-04-20 13:10:50640void WebsiteSettings::PresentSitePermissions() {
641 PermissionInfoList permission_info_list;
642
643 WebsiteSettingsUI::PermissionInfo permission_info;
644 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
645 permission_info.type = kPermissionType[i];
[email protected]df818272012-04-20 13:10:50646
647 content_settings::SettingInfo info;
sashab2b2a314f2015-01-17 06:42:21648 scoped_ptr<base::Value> value =
raymes7dec6d862015-07-27 07:02:08649 content_settings_->GetWebsiteSetting(
sashab2b2a314f2015-01-17 06:42:21650 site_url_, site_url_, permission_info.type, std::string(), &info);
651 DCHECK(value.get());
652 if (value->GetType() == base::Value::TYPE_INTEGER) {
653 permission_info.setting =
654 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26655 } else {
sashab2b2a314f2015-01-17 06:42:21656 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26657 }
658
[email protected]8bdf45c32012-08-04 00:12:55659 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50660
[email protected]b1d113d2012-06-27 21:27:34661 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21662 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34663 permission_info.default_setting = permission_info.setting;
664 permission_info.setting = CONTENT_SETTING_DEFAULT;
665 } else {
666 permission_info.default_setting =
667 content_settings_->GetDefaultContentSetting(permission_info.type,
668 NULL);
[email protected]df818272012-04-20 13:10:50669 }
palmer0da10b32015-02-11 00:42:19670
671 if (permission_info.setting != CONTENT_SETTING_DEFAULT &&
672 permission_info.setting != permission_info.default_setting) {
673 permission_info_list.push_back(permission_info);
674 }
[email protected]df818272012-04-20 13:10:50675 }
676
677 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33678}
679
[email protected]df818272012-04-20 13:10:50680void WebsiteSettings::PresentSiteData() {
681 CookieInfoList cookie_info_list;
vabrd5e30cd2014-10-02 11:06:03682 const LocalSharedObjectsCounter& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34683 tab_specific_content_settings()->allowed_local_shared_objects();
vabrd5e30cd2014-10-02 11:06:03684 const LocalSharedObjectsCounter& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34685 tab_specific_content_settings()->blocked_local_shared_objects();
686
687 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50688 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34689 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29690 net::registry_controlled_domains::GetDomainAndRegistry(
691 site_url_,
[email protected]aabe1792014-01-30 21:37:46692 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34693 if (cookie_source.empty())
694 cookie_source = site_url_.host();
695 cookie_info.cookie_source = cookie_source;
696 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
697 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
698 cookie_info_list.push_back(cookie_info);
699
700 // Add third party cookie counts.
701 cookie_info.cookie_source = l10n_util::GetStringUTF8(
702 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
703 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
704 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50705 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33706
[email protected]df818272012-04-20 13:10:50707 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33708}
[email protected]16de6de2012-04-04 12:24:14709
[email protected]24c8818c2012-04-25 09:57:41710void WebsiteSettings::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04711 // After initialization the status about the site's connection and its
712 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41713 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
714 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
715 WebsiteSettingsUI::IdentityInfo info;
716 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
717 info.site_identity = UTF16ToUTF8(organization_name());
718 else
719 info.site_identity = site_url_.host();
720
721 info.connection_status = site_connection_status_;
722 info.connection_status_description =
723 UTF16ToUTF8(site_connection_details_);
724 info.identity_status = site_identity_status_;
725 info.identity_status_description =
726 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11727 info.cert_id = cert_id_;
[email protected]71cd5ef2014-08-13 21:22:04728 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
[email protected]24c8818c2012-04-25 09:57:41729 ui_->SetIdentityInfo(info);
730}