blob: caeab798cf18acb559e1c792a80a264e78b82999 [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"
thestig884a1602014-08-27 01:29:3933#include "chrome/grit/chromium_strings.h"
34#include "chrome/grit/generated_resources.h"
mukai8eaec822014-10-25 17:53:1635#include "components/content_settings/core/browser/content_settings_utils.h"
36#include "components/content_settings/core/browser/host_content_settings_map.h"
vabr48565592014-10-08 15:06:0237#include "components/content_settings/core/browser/local_shared_objects_counter.h"
palmer0da10b32015-02-11 00:42:1938#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1339#include "components/content_settings/core/common/content_settings_pattern.h"
jialiul02aad2d2015-04-01 18:56:0340#include "components/rappor/rappor_utils.h"
[email protected]0b9fdd72012-04-04 10:00:3341#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4242#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2343#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3444#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2045#include "content/public/common/ssl_status.h"
46#include "content/public/common/url_constants.h"
[email protected]be28b5f42012-07-20 11:31:2547#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1148#include "net/cert/cert_status_flags.h"
49#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5750#include "net/ssl/ssl_cipher_suite_names.h"
51#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2052#include "ui/base/l10n/l10n_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2053
[email protected]24a9f1c92013-11-13 12:33:3754#if defined(OS_CHROMEOS)
55#include "chrome/browser/chromeos/policy/policy_cert_service.h"
56#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
57#endif
58
[email protected]ab6df3b12013-12-24 23:32:2659using base::ASCIIToUTF16;
60using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5661using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3362using content::BrowserThread;
63
64namespace {
65
jww1ed8ea72014-09-02 20:43:2566// Events for UMA. Do not reorder or change!
67enum SSLCertificateDecisionsDidRevoke {
68 USER_CERT_DECISIONS_NOT_REVOKED = 0,
69 USER_CERT_DECISIONS_REVOKED,
70 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
71};
72
palmer0da10b32015-02-11 00:42:1973// The list of content settings types to display on the Website Settings UI. THE
74// ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email
75// [email protected].
[email protected]0b9fdd72012-04-04 10:00:3376ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:2177 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:2178 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
79 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
palmer0da10b32015-02-11 00:42:1980 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
81 CONTENT_SETTINGS_TYPE_IMAGES,
82 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
83 CONTENT_SETTINGS_TYPE_POPUPS,
84 CONTENT_SETTINGS_TYPE_FULLSCREEN,
sashab2b2a314f2015-01-17 06:42:2185 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
palmer0da10b32015-02-11 00:42:1986 CONTENT_SETTINGS_TYPE_PLUGINS,
87 CONTENT_SETTINGS_TYPE_MOUSELOCK,
sashab2b2a314f2015-01-17 06:42:2188 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
benwellsa68ed4b2014-11-13 03:25:3689#if defined(OS_ANDROID)
sashab2b2a314f2015-01-17 06:42:2190 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
benwellsa68ed4b2014-11-13 03:25:3691#endif
[email protected]0b9fdd72012-04-04 10:00:3392};
93
[email protected]94c74b42013-12-02 15:19:4994bool CertificateTransparencyStatusMatch(
95 const content::SignedCertificateTimestampIDStatusList& scts,
96 net::ct::SCTVerifyStatus status) {
97 for (content::SignedCertificateTimestampIDStatusList::const_iterator it =
98 scts.begin();
99 it != scts.end();
100 ++it) {
101 if (it->status == status)
102 return true;
103 }
104
105 return false;
106}
107
108int GetSiteIdentityDetailsMessageByCTInfo(
109 const content::SignedCertificateTimestampIDStatusList& scts,
110 bool is_ev) {
111 // No SCTs - no CT information.
112 if (scts.empty())
113 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT
114 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT);
115
116 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_OK))
117 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED
118 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED);
119
120 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
121 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID
122 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID);
123
124 // status is SCT_STATUS_LOG_UNKNOWN
125 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED
126 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED);
127}
128
129// This function will return SITE_IDENTITY_STATUS_CERT or
130// SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless there are SCTs
131// which failed verification, in which case it will return
132// SITE_IDENTITY_STATUS_ERROR.
133WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo(
134 const content::SignedCertificateTimestampIDStatusList& scts,
135 bool is_ev) {
136 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
137 return WebsiteSettings::SITE_IDENTITY_STATUS_ERROR;
138
139 return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
140 : WebsiteSettings::SITE_IDENTITY_STATUS_CERT;
141}
142
[email protected]0b9fdd72012-04-04 10:00:33143} // namespace
144
145WebsiteSettings::WebsiteSettings(
146 WebsiteSettingsUI* ui,
147 Profile* profile,
[email protected]df818272012-04-20 13:10:50148 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:42149 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:33150 const GURL& url,
151 const content::SSLStatus& ssl,
152 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:50153 : TabSpecificContentSettings::SiteDataObserver(
154 tab_specific_content_settings),
155 ui_(ui),
[email protected]4f822f022012-12-20 19:11:42156 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:26157 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33158 site_url_(url),
159 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:11160 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:20161 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:33162 cert_store_(cert_store),
[email protected]71cd5ef2014-08-13 21:22:04163 content_settings_(profile->GetHostContentSettingsMap()),
164 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25165 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
166 did_revoke_user_ssl_decisions_(false) {
[email protected]03ef4b2a2012-03-06 15:04:20167 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:33168
[email protected]0b9fdd72012-04-04 10:00:33169 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50170 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41171 PresentSiteIdentity();
[email protected]e22d64f2012-09-10 09:03:23172
173 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
174 // created. So this counts how ofter the Website Settings UI is opened.
lgarron04a93502014-11-04 22:25:04175 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20176}
177
[email protected]0b9fdd72012-04-04 10:00:33178WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20179}
180
lgarron04a93502014-11-04 22:25:04181void WebsiteSettings::RecordWebsiteSettingsAction(
182 WebsiteSettingsAction action) {
183 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action",
184 action,
185 WEBSITE_SETTINGS_COUNT);
186
187 // Use a separate histogram to record actions if they are done on a page with
188 // an HTTPS URL. Note that this *disregards* security status.
palmeree0e5af2015-06-05 03:10:40189 //
190
191 // TODO(palmer): Consider adding a new histogram for
192 // GURL::SchemeIsCryptographic. (We don't want to replace this call with a
193 // call to that function because we don't want to change the meanings of
194 // existing metrics.) This would inform the decision to mark non-secure
195 // origins as Dubious or Non-Secure; the overall bug for that is
196 // crbug.com/454579.
lgarron04a93502014-11-04 22:25:04197 if (site_url_.SchemeIs(url::kHttpsScheme)) {
198 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action.HttpsUrl",
199 action,
200 WEBSITE_SETTINGS_COUNT);
201 }
202}
203
jialiul02aad2d2015-04-01 18:56:03204// Get corresponding Rappor Metric.
205const std::string GetRapporMetric(ContentSettingsType permission) {
206 std::string permission_str;
207 switch (permission) {
208 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
209 permission_str = "Geolocation";
210 break;
211 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
212 permission_str = "Notifications";
213 break;
214 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
215 permission_str = "Mic";
216 break;
217 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
218 permission_str = "Camera";
219 break;
220 default:
221 return "";
222 }
223
224 return base::StringPrintf("ContentSettings.PermissionActions_%s.Revoked.Url",
225 permission_str.c_str());
226}
lgarron04a93502014-11-04 22:25:04227
[email protected]df818272012-04-20 13:10:50228void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
229 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23230 // Count how often a permission for a specific content type is changed using
231 // the Website Settings UI.
sashab9debecd2014-12-18 04:15:56232 ContentSettingsTypeHistogram histogram_value =
233 ContentSettingTypeToHistogramValue(type);
234 DCHECK_NE(histogram_value, CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID)
235 << "Invalid content setting type specified.";
236 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.OriginInfo.PermissionChanged",
237 histogram_value,
238 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
239
240 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
241 UMA_HISTOGRAM_ENUMERATION(
242 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
243 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
244 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
245 UMA_HISTOGRAM_ENUMERATION(
246 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
247 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
jialiul02aad2d2015-04-01 18:56:03248 // Trigger Rappor sampling if it is a permission revoke action.
249 const std::string& rappor_metric = GetRapporMetric(type);
250 if (!rappor_metric.empty()) {
251 rappor::SampleDomainAndRegistryFromGURL(
252 g_browser_process->rappor_service(), rappor_metric, this->site_url_);
253 }
sashab9debecd2014-12-18 04:15:56254 }
[email protected]e22d64f2012-09-10 09:03:23255
lgarron04a93502014-11-04 22:25:04256 // This is technically redundant given the histogram above, but putting the
257 // total count of permission changes in another histogram makes it easier to
258 // compare it against other kinds of actions in WebsiteSettings[PopupView].
259 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_CHANGED_PERMISSION);
260
[email protected]df818272012-04-20 13:10:50261 ContentSettingsPattern primary_pattern;
262 ContentSettingsPattern secondary_pattern;
263 switch (type) {
264 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34265 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
mlamouriab1897c2015-02-18 12:09:32266 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
[email protected]df818272012-04-20 13:10:50267 // TODO(markusheintz): The rule we create here should also change the
268 // location permission for iframed content.
269 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
270 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
271 break;
272 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
273 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
274 secondary_pattern = ContentSettingsPattern::Wildcard();
275 break;
[email protected]b1d113d2012-06-27 21:27:34276 case CONTENT_SETTINGS_TYPE_IMAGES:
277 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50278 case CONTENT_SETTINGS_TYPE_PLUGINS:
279 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34280 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27281 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
benwellsa68ed4b2014-11-13 03:25:36282 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
[email protected]df818272012-04-20 13:10:50283 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
284 secondary_pattern = ContentSettingsPattern::Wildcard();
285 break;
sashab2b2a314f2015-01-17 06:42:21286 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
287 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
[email protected]0bacc1912012-12-11 11:05:34288 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
289 secondary_pattern = ContentSettingsPattern::Wildcard();
[email protected]0bacc1912012-12-11 11:05:34290 break;
[email protected]df818272012-04-20 13:10:50291 default:
292 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
293 break;
[email protected]0b9fdd72012-04-04 10:00:33294 }
295
jialiul02aad2d2015-04-01 18:56:03296 // Permission settings are specified via rules. There exists always at least
297 // one rule for the default setting. Get the rule that currently defines
298 // the permission for the given permission |type|. Then test whether the
299 // existing rule is more specific than the rule we are about to create. If
300 // the existing rule is more specific, than change the existing rule instead
301 // of creating a new rule that would be hidden behind the existing rule.
302 content_settings::SettingInfo info;
303 scoped_ptr<base::Value> v =
raymes7dec6d862015-07-27 07:02:08304 content_settings_->GetWebsiteSetting(
jialiul02aad2d2015-04-01 18:56:03305 site_url_, site_url_, type, std::string(), &info);
306 content_settings_->SetNarrowestWebsiteSetting(
307 primary_pattern, secondary_pattern, type, std::string(), setting, info);
[email protected]df818272012-04-20 13:10:50308
[email protected]66f157312012-08-01 13:50:26309 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24310
[email protected]76955932012-12-06 11:01:10311// TODO(markusheintz): This is a temporary hack to fix issue:
312// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25313#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24314 // Refresh the UI to reflect the new setting.
315 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25316#endif
[email protected]df818272012-04-20 13:10:50317}
318
[email protected]df818272012-04-20 13:10:50319void WebsiteSettings::OnSiteDataAccessed() {
320 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33321}
322
[email protected]66f157312012-08-01 13:50:26323void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50324 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36325 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
jww1ed8ea72014-09-02 20:43:25326
327 SSLCertificateDecisionsDidRevoke user_decision =
328 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
329 : USER_CERT_DECISIONS_NOT_REVOKED;
330
331 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions",
332 user_decision,
333 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
334}
335
336void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() {
337 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29338 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
339 site_url().host());
jww1ed8ea72014-09-02 20:43:25340 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26341}
342
[email protected]0b9fdd72012-04-04 10:00:33343void WebsiteSettings::Init(Profile* profile,
344 const GURL& url,
345 const content::SSLStatus& ssl) {
sashab97894ce2014-10-22 10:08:33346 bool isChromeUINativeScheme = false;
347#if defined(OS_ANDROID)
348 isChromeUINativeScheme = url.SchemeIs(chrome::kChromeUINativeScheme);
349#endif
350
351 if (url.SchemeIs(content::kChromeUIScheme) ||
352 url.SchemeIs(url::kAboutScheme) || isChromeUINativeScheme) {
[email protected]03ef4b2a2012-03-06 15:04:20353 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
354 site_identity_details_ =
355 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
356 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
357 return;
358 }
359
360 scoped_refptr<net::X509Certificate> cert;
361
362 // Identity section.
[email protected]a04db822013-12-11 19:14:40363 base::string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20364 if (subject_name.empty()) {
365 subject_name.assign(
366 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20367 }
368
[email protected]f61c1ce2012-05-09 13:55:11369 cert_id_ = ssl.cert_id;
370
[email protected]03ef4b2a2012-03-06 15:04:20371 if (ssl.cert_id &&
372 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
373 (!net::IsCertStatusError(ssl.cert_status) ||
374 net::IsCertStatusMinorError(ssl.cert_status))) {
375 // There are no major errors. Check for minor errors.
[email protected]24a9f1c92013-11-13 12:33:37376#if defined(OS_CHROMEOS)
377 policy::PolicyCertService* service =
378 policy::PolicyCertServiceFactory::GetForProfile(profile);
379 const bool used_policy_certs = service && service->UsedPolicyCertificates();
380#else
381 const bool used_policy_certs = false;
382#endif
383 if (used_policy_certs) {
[email protected]eaf3f322013-04-25 21:53:59384 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37385 site_identity_details_ = l10n_util::GetStringFUTF16(
386 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
[email protected]eaf3f322013-04-25 21:53:59387 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20388 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
[email protected]a04db822013-12-11 19:14:40389 base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20390 if (issuer_name.empty()) {
391 issuer_name.assign(l10n_util::GetStringUTF16(
392 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
393 }
[email protected]94c74b42013-12-02 15:19:49394
[email protected]03ef4b2a2012-03-06 15:04:20395 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49396 GetSiteIdentityDetailsMessageByCTInfo(
397 ssl.signed_certificate_timestamp_ids, false /* not EV */),
398 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20399
400 site_identity_details_ += ASCIIToUTF16("\n\n");
401 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
402 site_identity_details_ += l10n_util::GetStringUTF16(
403 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
404 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
405 site_identity_details_ += l10n_util::GetStringUTF16(
406 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
407 } else {
408 NOTREACHED() << "Need to specify string for this warning";
409 }
[email protected]03ef4b2a2012-03-06 15:04:20410 } else {
rsleevi4f8012722014-09-30 01:28:01411 if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
412 // EV HTTPS page.
413 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
414 ssl.signed_certificate_timestamp_ids, true);
415 DCHECK(!cert->subject().organization_names.empty());
416 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
417 // An EV Cert is required to have a city (localityName) and country but
418 // state is "if any".
419 DCHECK(!cert->subject().locality_name.empty());
420 DCHECK(!cert->subject().country_name.empty());
421 base::string16 locality;
422 if (!cert->subject().state_or_province_name.empty()) {
423 locality = l10n_util::GetStringFUTF16(
424 IDS_PAGEINFO_ADDRESS,
425 UTF8ToUTF16(cert->subject().locality_name),
426 UTF8ToUTF16(cert->subject().state_or_province_name),
427 UTF8ToUTF16(cert->subject().country_name));
428 } else {
429 locality = l10n_util::GetStringFUTF16(
430 IDS_PAGEINFO_PARTIAL_ADDRESS,
431 UTF8ToUTF16(cert->subject().locality_name),
432 UTF8ToUTF16(cert->subject().country_name));
433 }
434 DCHECK(!cert->subject().organization_names.empty());
435 site_identity_details_.assign(l10n_util::GetStringFUTF16(
436 GetSiteIdentityDetailsMessageByCTInfo(
437 ssl.signed_certificate_timestamp_ids, true /* is EV */),
438 UTF8ToUTF16(cert->subject().organization_names[0]),
439 locality,
440 UTF8ToUTF16(cert->issuer().GetDisplayName())));
441 } else {
442 // Non-EV OK HTTPS page.
443 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
444 ssl.signed_certificate_timestamp_ids, false);
445 base::string16 issuer_name(
446 UTF8ToUTF16(cert->issuer().GetDisplayName()));
447 if (issuer_name.empty()) {
448 issuer_name.assign(l10n_util::GetStringUTF16(
449 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
450 }
[email protected]94c74b42013-12-02 15:19:49451
rsleevi4f8012722014-09-30 01:28:01452 site_identity_details_.assign(l10n_util::GetStringFUTF16(
453 GetSiteIdentityDetailsMessageByCTInfo(
454 ssl.signed_certificate_timestamp_ids, false /* not EV */),
455 issuer_name));
456 }
457 // The date after which no new SHA-1 certificates may be issued.
458 // 2016-01-01 00:00:00 UTC
459 static const int64_t kSHA1LastIssuanceDate = INT64_C(13096080000000000);
460 if ((ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT) &&
461 cert->valid_expiry() >
rsleeviad6f5022015-04-24 18:57:50462 base::Time::FromInternalValue(kSHA1LastIssuanceDate)) {
rsleevi4f8012722014-09-30 01:28:01463 site_identity_status_ =
464 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
465 site_identity_details_ +=
466 UTF8ToUTF16("\n\n") +
467 l10n_util::GetStringUTF16(
468 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
469 }
[email protected]03ef4b2a2012-03-06 15:04:20470 }
471 } else {
472 // HTTP or HTTPS with errors (not warnings).
473 site_identity_details_.assign(l10n_util::GetStringUTF16(
474 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
475 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
476 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
477 else
478 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
479
[email protected]a04db822013-12-11 19:14:40480 const base::string16 bullet = UTF8ToUTF16("\n • ");
[email protected]03ef4b2a2012-03-06 15:04:20481 std::vector<SSLErrorInfo> errors;
482 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
483 url, &errors);
484 for (size_t i = 0; i < errors.size(); ++i) {
485 site_identity_details_ += bullet;
486 site_identity_details_ += errors[i].short_description();
487 }
488
489 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
490 site_identity_details_ += ASCIIToUTF16("\n\n");
491 site_identity_details_ += l10n_util::GetStringUTF16(
492 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
493 }
494 }
495
496 // Site Connection
497 // We consider anything less than 80 bits encryption to be weak encryption.
498 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
499 // weakly encrypted connections.
500 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
501
[email protected]1c1051d2014-05-10 11:39:58502 if (ssl.security_style == content::SECURITY_STYLE_UNKNOWN) {
503 // Page is still loading, so SSL status is not yet available. Say nothing.
504 DCHECK_EQ(ssl.security_bits, -1);
505 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
506
507 site_connection_details_.assign(l10n_util::GetStringFUTF16(
508 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
509 subject_name));
510 } else if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) {
511 // HTTPS without a certificate, or not HTTPS.
512 DCHECK(!ssl.cert_id);
513 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
[email protected]03ef4b2a2012-03-06 15:04:20514
515 site_connection_details_.assign(l10n_util::GetStringFUTF16(
516 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
517 subject_name));
518 } else if (ssl.security_bits < 0) {
519 // Security strength is unknown. Say nothing.
520 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
521 } else if (ssl.security_bits == 0) {
522 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
523 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
524 site_connection_details_.assign(l10n_util::GetStringFUTF16(
525 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
526 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20527 } else {
528 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22529
530 if (net::SSLConnectionStatusToVersion(ssl.connection_status) >=
531 net::SSL_CONNECTION_VERSION_TLS1_2 &&
532 net::IsSecureTLSCipherSuite(
533 net::SSLConnectionStatusToCipherSuite(ssl.connection_status))) {
534 site_connection_details_.assign(l10n_util::GetStringFUTF16(
535 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
536 subject_name));
537 } else {
538 site_connection_details_.assign(l10n_util::GetStringFUTF16(
539 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
540 subject_name));
541 }
542
[email protected]03ef4b2a2012-03-06 15:04:20543 if (ssl.content_status) {
544 bool ran_insecure_content =
545 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
546 site_connection_status_ = ran_insecure_content ?
547 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
548 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
549 site_connection_details_.assign(l10n_util::GetStringFUTF16(
550 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
551 site_connection_details_,
552 l10n_util::GetStringUTF16(ran_insecure_content ?
553 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
554 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
555 }
556 }
557
558 uint16 cipher_suite =
559 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
560 if (ssl.security_bits > 0 && cipher_suite) {
561 int ssl_version =
562 net::SSLConnectionStatusToVersion(ssl.connection_status);
563 const char* ssl_version_str;
564 net::SSLVersionToString(&ssl_version_str, ssl_version);
565 site_connection_details_ += ASCIIToUTF16("\n\n");
566 site_connection_details_ += l10n_util::GetStringFUTF16(
567 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
568 ASCIIToUTF16(ssl_version_str));
569
[email protected]03ef4b2a2012-03-06 15:04:20570 bool no_renegotiation =
571 (ssl.connection_status &
572 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
573 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57574 bool is_aead;
575 net::SSLCipherSuiteToStrings(
576 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20577
578 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57579 if (is_aead) {
580 site_connection_details_ += l10n_util::GetStringFUTF16(
581 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
582 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
583 } else {
584 site_connection_details_ += l10n_util::GetStringFUTF16(
585 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
586 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
587 }
[email protected]03ef4b2a2012-03-06 15:04:20588
agl078d2102014-10-20 22:03:22589 if (ssl_version == net::SSL_CONNECTION_VERSION_SSL3 &&
590 site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) {
591 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
592 }
593
594 const bool did_fallback =
595 (ssl.connection_status & net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20596 if (did_fallback) {
[email protected]03ef4b2a2012-03-06 15:04:20597 site_connection_details_ += ASCIIToUTF16("\n\n");
598 site_connection_details_ += l10n_util::GetStringUTF16(
599 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
600 }
agl078d2102014-10-20 22:03:22601
[email protected]03ef4b2a2012-03-06 15:04:20602 if (no_renegotiation) {
603 site_connection_details_ += ASCIIToUTF16("\n\n");
604 site_connection_details_ += l10n_util::GetStringUTF16(
605 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
606 }
607 }
[email protected]e583f752012-08-30 13:26:21608
[email protected]71cd5ef2014-08-13 21:22:04609 // Check if a user decision has been made to allow or deny certificates with
610 // errors on this site.
611 ChromeSSLHostStateDelegate* delegate =
612 ChromeSSLHostStateDelegateFactory::GetForProfile(profile);
613 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40614 // Only show an SSL decision revoke button if the user has chosen to bypass
615 // SSL host errors for this host in the past.
616 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]71cd5ef2014-08-13 21:22:04617
[email protected]e583f752012-08-30 13:26:21618 // By default select the permissions tab that displays all the site
619 // permissions. In case of a connection error or an issue with the
620 // certificate presented by the website, select the connection tab to draw
621 // the user's attention to the issue. If the site does not provide a
622 // certificate because it was loaded over an unencrypted connection, don't
623 // select the connection tab.
624 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
625 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
626 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
627 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59628 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
rsleevi4f8012722014-09-30 01:28:01629 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT ||
630 site_identity_status_ ==
lgarron04a93502014-11-04 22:25:04631 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM) {
[email protected]e583f752012-08-30 13:26:21632 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
lgarron04a93502014-11-04 22:25:04633 RecordWebsiteSettingsAction(
634 WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY);
635 }
[email protected]e583f752012-08-30 13:26:21636 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20637}
[email protected]0b9fdd72012-04-04 10:00:33638
[email protected]df818272012-04-20 13:10:50639void WebsiteSettings::PresentSitePermissions() {
640 PermissionInfoList permission_info_list;
641
642 WebsiteSettingsUI::PermissionInfo permission_info;
643 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
644 permission_info.type = kPermissionType[i];
[email protected]df818272012-04-20 13:10:50645
646 content_settings::SettingInfo info;
sashab2b2a314f2015-01-17 06:42:21647 scoped_ptr<base::Value> value =
raymes7dec6d862015-07-27 07:02:08648 content_settings_->GetWebsiteSetting(
sashab2b2a314f2015-01-17 06:42:21649 site_url_, site_url_, permission_info.type, std::string(), &info);
650 DCHECK(value.get());
651 if (value->GetType() == base::Value::TYPE_INTEGER) {
652 permission_info.setting =
653 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26654 } else {
sashab2b2a314f2015-01-17 06:42:21655 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26656 }
657
[email protected]8bdf45c32012-08-04 00:12:55658 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50659
[email protected]b1d113d2012-06-27 21:27:34660 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21661 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34662 permission_info.default_setting = permission_info.setting;
663 permission_info.setting = CONTENT_SETTING_DEFAULT;
664 } else {
665 permission_info.default_setting =
666 content_settings_->GetDefaultContentSetting(permission_info.type,
667 NULL);
[email protected]df818272012-04-20 13:10:50668 }
palmer0da10b32015-02-11 00:42:19669
670 if (permission_info.setting != CONTENT_SETTING_DEFAULT &&
671 permission_info.setting != permission_info.default_setting) {
672 permission_info_list.push_back(permission_info);
673 }
[email protected]df818272012-04-20 13:10:50674 }
675
676 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33677}
678
[email protected]df818272012-04-20 13:10:50679void WebsiteSettings::PresentSiteData() {
680 CookieInfoList cookie_info_list;
vabrd5e30cd2014-10-02 11:06:03681 const LocalSharedObjectsCounter& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34682 tab_specific_content_settings()->allowed_local_shared_objects();
vabrd5e30cd2014-10-02 11:06:03683 const LocalSharedObjectsCounter& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34684 tab_specific_content_settings()->blocked_local_shared_objects();
685
686 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50687 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34688 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29689 net::registry_controlled_domains::GetDomainAndRegistry(
690 site_url_,
[email protected]aabe1792014-01-30 21:37:46691 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34692 if (cookie_source.empty())
693 cookie_source = site_url_.host();
694 cookie_info.cookie_source = cookie_source;
695 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
696 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
697 cookie_info_list.push_back(cookie_info);
698
699 // Add third party cookie counts.
700 cookie_info.cookie_source = l10n_util::GetStringUTF8(
701 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
702 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
703 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50704 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33705
[email protected]df818272012-04-20 13:10:50706 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33707}
[email protected]16de6de2012-04-04 12:24:14708
[email protected]24c8818c2012-04-25 09:57:41709void WebsiteSettings::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04710 // After initialization the status about the site's connection and its
711 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41712 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
713 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
714 WebsiteSettingsUI::IdentityInfo info;
715 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
716 info.site_identity = UTF16ToUTF8(organization_name());
717 else
718 info.site_identity = site_url_.host();
719
720 info.connection_status = site_connection_status_;
721 info.connection_status_description =
722 UTF16ToUTF8(site_connection_details_);
723 info.identity_status = site_identity_status_;
724 info.identity_status_description =
725 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11726 info.cert_id = cert_id_;
[email protected]71cd5ef2014-08-13 21:22:04727 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
[email protected]24c8818c2012-04-25 09:57:41728 ui_->SetIdentityInfo(info);
729}