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

Side by Side Diff: chrome/browser/ssl/chrome_ssl_host_state_delegate.cc

Issue 418133012: Add button to page info to revoke user certificate decisions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address pkasting comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 5 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/threading/non_thread_safe.h"
12 #include "base/time/clock.h" 13 #include "base/time/clock.h"
13 #include "base/time/default_clock.h" 14 #include "base/time/default_clock.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "chrome/browser/content_settings/host_content_settings_map.h" 16 #include "chrome/browser/content_settings/host_content_settings_map.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "components/content_settings/core/common/content_settings_types.h" 19 #include "components/content_settings/core/common/content_settings_types.h"
19 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
20 #include "net/base/hash_value.h" 21 #include "net/base/hash_value.h"
21 #include "net/cert/x509_certificate.h" 22 #include "net/cert/x509_certificate.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 234 }
234 235
235 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() { 236 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() {
236 if (should_remember_ssl_decisions_ == ForgetSSLExceptionDecisionsAtSessionEnd) 237 if (should_remember_ssl_decisions_ == ForgetSSLExceptionDecisionsAtSessionEnd)
237 Clear(); 238 Clear();
238 } 239 }
239 240
240 void ChromeSSLHostStateDelegate::DenyCert(const std::string& host, 241 void ChromeSSLHostStateDelegate::DenyCert(const std::string& host,
241 net::X509Certificate* cert, 242 net::X509Certificate* cert,
242 net::CertStatus error) { 243 net::CertStatus error) {
244 DCHECK(CalledOnValidThread());
243 ChangeCertPolicy(host, cert, error, net::CertPolicy::DENIED); 245 ChangeCertPolicy(host, cert, error, net::CertPolicy::DENIED);
244 } 246 }
245 247
246 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host, 248 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host,
247 net::X509Certificate* cert, 249 net::X509Certificate* cert,
248 net::CertStatus error) { 250 net::CertStatus error) {
251 DCHECK(CalledOnValidThread());
249 ChangeCertPolicy(host, cert, error, net::CertPolicy::ALLOWED); 252 ChangeCertPolicy(host, cert, error, net::CertPolicy::ALLOWED);
250 } 253 }
251 254
252 void ChromeSSLHostStateDelegate::Clear() { 255 void ChromeSSLHostStateDelegate::Clear() {
256 DCHECK(CalledOnValidThread());
253 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( 257 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType(
254 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS); 258 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS);
255 } 259 }
256 260
257 net::CertPolicy::Judgment ChromeSSLHostStateDelegate::QueryPolicy( 261 net::CertPolicy::Judgment ChromeSSLHostStateDelegate::QueryPolicy(
258 const std::string& host, 262 const std::string& host,
259 net::X509Certificate* cert, 263 net::X509Certificate* cert,
260 net::CertStatus error) { 264 net::CertStatus error) {
265 DCHECK(CalledOnValidThread());
261 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 266 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
262 GURL url = GetSecureGURLForHost(host); 267 GURL url = GetSecureGURLForHost(host);
263 scoped_ptr<base::Value> value(map->GetWebsiteSetting( 268 scoped_ptr<base::Value> value(map->GetWebsiteSetting(
264 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); 269 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL));
265 270
266 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) 271 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY))
267 return net::CertPolicy::UNKNOWN; 272 return net::CertPolicy::UNKNOWN;
268 273
269 base::DictionaryValue* dict; // Owned by value 274 base::DictionaryValue* dict; // Owned by value
270 int policy_decision; 275 int policy_decision;
(...skipping 14 matching lines...) Expand all
285 if (success && policy_decision == net::CertPolicy::Judgment::ALLOWED) 290 if (success && policy_decision == net::CertPolicy::Judgment::ALLOWED)
286 return net::CertPolicy::Judgment::ALLOWED; 291 return net::CertPolicy::Judgment::ALLOWED;
287 else if (success && policy_decision == net::CertPolicy::Judgment::DENIED) 292 else if (success && policy_decision == net::CertPolicy::Judgment::DENIED)
288 return net::CertPolicy::Judgment::DENIED; 293 return net::CertPolicy::Judgment::DENIED;
289 294
290 return net::CertPolicy::Judgment::UNKNOWN; 295 return net::CertPolicy::Judgment::UNKNOWN;
291 } 296 }
292 297
293 void ChromeSSLHostStateDelegate::RevokeAllowAndDenyPreferences( 298 void ChromeSSLHostStateDelegate::RevokeAllowAndDenyPreferences(
294 const std::string& host) { 299 const std::string& host) {
300 DCHECK(CalledOnValidThread());
295 GURL url = GetSecureGURLForHost(host); 301 GURL url = GetSecureGURLForHost(host);
296 const ContentSettingsPattern pattern = 302 const ContentSettingsPattern pattern =
297 ContentSettingsPattern::FromURLNoWildcard(url); 303 ContentSettingsPattern::FromURLNoWildcard(url);
298 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 304 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
299 305
300 map->SetWebsiteSetting(pattern, 306 map->SetWebsiteSetting(pattern,
301 pattern, 307 pattern,
302 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, 308 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
303 std::string(), 309 std::string(),
304 NULL); 310 NULL);
305 } 311 }
306 312
307 bool ChromeSSLHostStateDelegate::HasAllowedOrDeniedCert( 313 bool ChromeSSLHostStateDelegate::HasAllowedOrDeniedCert(
308 const std::string& host) { 314 const std::string& host) {
315 DCHECK(CalledOnValidThread());
309 GURL url = GetSecureGURLForHost(host); 316 GURL url = GetSecureGURLForHost(host);
310 const ContentSettingsPattern pattern = 317 const ContentSettingsPattern pattern =
311 ContentSettingsPattern::FromURLNoWildcard(url); 318 ContentSettingsPattern::FromURLNoWildcard(url);
312 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 319 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
313 320
314 scoped_ptr<base::Value> value(map->GetWebsiteSetting( 321 scoped_ptr<base::Value> value(map->GetWebsiteSetting(
315 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); 322 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL));
316 323
317 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) 324 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY))
318 return false; 325 return false;
319 326
320 base::DictionaryValue* dict; // Owned by value 327 base::DictionaryValue* dict; // Owned by value
321 bool success = value->GetAsDictionary(&dict); 328 bool success = value->GetAsDictionary(&dict);
322 DCHECK(success); 329 DCHECK(success);
323 330
324 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 331 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
325 int policy_decision; // Owned by dict 332 int policy_decision; // Owned by dict
326 success = it.value().GetAsInteger(&policy_decision); 333 success = it.value().GetAsInteger(&policy_decision);
327 if (success && (static_cast<net::CertPolicy::Judgment>(policy_decision) != 334 if (success && (static_cast<net::CertPolicy::Judgment>(policy_decision) !=
328 net::CertPolicy::UNKNOWN)) 335 net::CertPolicy::UNKNOWN))
329 return true; 336 return true;
330 } 337 }
331 338
332 return false; 339 return false;
333 } 340 }
334 341
342 void ChromeSSLHostStateDelegate::HostRanInsecureContent(const std::string& host,
343 int pid) {
344 DCHECK(CalledOnValidThread());
345 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid));
346 }
347
348 bool ChromeSSLHostStateDelegate::DidHostRunInsecureContent(
349 const std::string& host,
350 int pid) const {
351 DCHECK(CalledOnValidThread());
352 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid));
353 }
335 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { 354 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) {
355 DCHECK(CalledOnValidThread());
336 clock_.reset(clock.release()); 356 clock_.reset(clock.release());
337 } 357 }
338 358
339 void ChromeSSLHostStateDelegate::ChangeCertPolicy( 359 void ChromeSSLHostStateDelegate::ChangeCertPolicy(
340 const std::string& host, 360 const std::string& host,
341 net::X509Certificate* cert, 361 net::X509Certificate* cert,
342 net::CertStatus error, 362 net::CertStatus error,
343 net::CertPolicy::Judgment judgment) { 363 net::CertPolicy::Judgment judgment) {
344 GURL url = GetSecureGURLForHost(host); 364 GURL url = GetSecureGURLForHost(host);
345 const ContentSettingsPattern pattern = 365 const ContentSettingsPattern pattern =
(...skipping 22 matching lines...) Expand all
368 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment); 388 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment);
369 389
370 // The map takes ownership of the value, so it is released in the call to 390 // The map takes ownership of the value, so it is released in the call to
371 // SetWebsiteSetting. 391 // SetWebsiteSetting.
372 map->SetWebsiteSetting(pattern, 392 map->SetWebsiteSetting(pattern,
373 pattern, 393 pattern,
374 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, 394 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
375 std::string(), 395 std::string(),
376 value.release()); 396 value.release());
377 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698