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

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

Issue 469003004: Revert "Add button to page info to revoke user certificate decisions." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/bind.h"
9 #include "base/command_line.h" 8 #include "base/command_line.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/time/clock.h" 12 #include "base/time/clock.h"
14 #include "base/time/default_clock.h" 13 #include "base/time/default_clock.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "chrome/browser/content_settings/host_content_settings_map.h" 15 #include "chrome/browser/content_settings/host_content_settings_map.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
19 #include "components/content_settings/core/common/content_settings_types.h" 18 #include "components/content_settings/core/common/content_settings_types.h"
20 #include "components/variations/variations_associated_data.h" 19 #include "components/variations/variations_associated_data.h"
21 #include "net/base/hash_value.h" 20 #include "net/base/hash_value.h"
22 #include "net/cert/x509_certificate.h" 21 #include "net/cert/x509_certificate.h"
23 #include "net/http/http_transaction_factory.h"
24 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_getter.h"
26 #include "url/gurl.h" 22 #include "url/gurl.h"
27 23
28 namespace { 24 namespace {
29 25
30 // Switch value that specifies that certificate decisions should be forgotten at 26 // Switch value that specifies that certificate decisions should be forgotten at
31 // the end of the current session. 27 // the end of the current session.
32 const int64 kForgetAtSessionEndSwitchValue = -1; 28 const int64 kForgetAtSessionEndSwitchValue = -1;
33 29
34 // Experiment information 30 // Experiment information
35 const char kRememberCertificateErrorDecisionsFieldTrialName[] = 31 const char kRememberCertificateErrorDecisionsFieldTrialName[] =
36 "RememberCertificateErrorDecisions"; 32 "RememberCertificateErrorDecisions";
37 const char kRememberCertificateErrorDecisionsFieldTrialDefaultGroup[] = 33 const char kRememberCertificateErrorDecisionsFieldTrialDefaultGroup[] =
38 "Default"; 34 "Default";
39 const char kRememberCertificateErrorDecisionsFieldTrialLengthParam[] = "length"; 35 const char kRememberCertificateErrorDecisionsFieldTrialLengthParam[] = "length";
40 36
41 // Keys for the per-site error + certificate finger to judgement content 37 // Keys for the per-site error + certificate finger to judgement content
42 // settings map. 38 // settings map.
43 const char kSSLCertDecisionCertErrorMapKey[] = "cert_exceptions_map"; 39 const char kSSLCertDecisionCertErrorMapKey[] = "cert_exceptions_map";
44 const char kSSLCertDecisionExpirationTimeKey[] = "decision_expiration_time"; 40 const char kSSLCertDecisionExpirationTimeKey[] = "decision_expiration_time";
45 const char kSSLCertDecisionVersionKey[] = "version"; 41 const char kSSLCertDecisionVersionKey[] = "version";
46 42
47 const int kDefaultSSLCertDecisionVersion = 1; 43 const int kDefaultSSLCertDecisionVersion = 1;
48 44
49 // Closes all idle network connections for the given URLRequestContext. This is
50 // a big hammer and should be wielded with extreme caution as it can have a big,
51 // negative impact on network performance. In this case, it is used by
52 // RevokeUserDecisionsHard, which should only be called by rare, user initiated
53 // events. See the comment before RevokeUserDecisionsHard implementation for
54 // more information.
55 void CloseIdleConnections(
56 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
57 url_request_context_getter->
58 GetURLRequestContext()->
59 http_transaction_factory()->
60 GetSession()->
61 CloseIdleConnections();
62 }
63
64 // All SSL decisions are per host (and are shared arcoss schemes), so this 45 // All SSL decisions are per host (and are shared arcoss schemes), so this
65 // canonicalizes all hosts into a secure scheme GURL to use with content 46 // canonicalizes all hosts into a secure scheme GURL to use with content
66 // settings. The returned GURL will be the passed in host with an empty path and 47 // settings. The returned GURL will be the passed in host with an empty path and
67 // https:// as the scheme. 48 // https:// as the scheme.
68 GURL GetSecureGURLForHost(const std::string& host) { 49 GURL GetSecureGURLForHost(const std::string& host) {
69 std::string url = "https://" + host; 50 std::string url = "https://" + host;
70 return GURL(url); 51 return GURL(url);
71 } 52 }
72 53
73 // This is a helper function that returns the length of time before a 54 // This is a helper function that returns the length of time before a
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // If a policy decision was successfully retrieved and it's a valid value of 283 // If a policy decision was successfully retrieved and it's a valid value of
303 // ALLOWED or DENIED, return the valid value. Otherwise, return UNKNOWN. 284 // ALLOWED or DENIED, return the valid value. Otherwise, return UNKNOWN.
304 if (success && policy_decision == net::CertPolicy::Judgment::ALLOWED) 285 if (success && policy_decision == net::CertPolicy::Judgment::ALLOWED)
305 return net::CertPolicy::Judgment::ALLOWED; 286 return net::CertPolicy::Judgment::ALLOWED;
306 else if (success && policy_decision == net::CertPolicy::Judgment::DENIED) 287 else if (success && policy_decision == net::CertPolicy::Judgment::DENIED)
307 return net::CertPolicy::Judgment::DENIED; 288 return net::CertPolicy::Judgment::DENIED;
308 289
309 return net::CertPolicy::Judgment::UNKNOWN; 290 return net::CertPolicy::Judgment::UNKNOWN;
310 } 291 }
311 292
312 void ChromeSSLHostStateDelegate::RevokeUserDecisions(const std::string& host) { 293 void ChromeSSLHostStateDelegate::RevokeAllowAndDenyPreferences(
294 const std::string& host) {
313 GURL url = GetSecureGURLForHost(host); 295 GURL url = GetSecureGURLForHost(host);
314 const ContentSettingsPattern pattern = 296 const ContentSettingsPattern pattern =
315 ContentSettingsPattern::FromURLNoWildcard(url); 297 ContentSettingsPattern::FromURLNoWildcard(url);
316 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 298 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
317 299
318 map->SetWebsiteSetting(pattern, 300 map->SetWebsiteSetting(pattern,
319 pattern, 301 pattern,
320 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, 302 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
321 std::string(), 303 std::string(),
322 NULL); 304 NULL);
323 } 305 }
324 306
325 // TODO(jww): This will revoke all of the decisions in the browser context. 307 bool ChromeSSLHostStateDelegate::HasAllowedOrDeniedCert(
326 // However, the networking stack actually keeps track of its own list of
327 // exceptions per-HttpNetworkTransaction in the SSLConfig structure (see the
328 // allowed_bad_certs Vector in net/ssl/ssl_config.h). This dual-tracking of
329 // exceptions introduces a problem where the browser context can revoke a
330 // certificate, but if a transaction reuses a cached version of the SSLConfig
331 // (probably from a pooled socket), it may bypass the intestitial layer.
332 //
333 // Over time, the cached versions should expire and it should converge on
334 // showing the interstitial. We probably need to introduce into the networking
335 // stack a way revoke SSLConfig's allowed_bad_certs lists per socket.
336 //
337 // For now, RevokeUserDecisionsHard is our solution for the rare case where it
338 // is necessary to revoke the preferences immediately. It does so by flushing
339 // idle sockets.
340 void ChromeSSLHostStateDelegate::RevokeUserDecisionsHard(
341 const std::string& host) { 308 const std::string& host) {
342 RevokeUserDecisions(host);
343 scoped_refptr<net::URLRequestContextGetter> getter(
344 profile_->GetRequestContext());
345 profile_->GetRequestContext()->GetNetworkTaskRunner()->PostTask(
346 FROM_HERE, base::Bind(&CloseIdleConnections, getter));
347 }
348
349 bool ChromeSSLHostStateDelegate::HasUserDecision(const std::string& host) {
350 GURL url = GetSecureGURLForHost(host); 309 GURL url = GetSecureGURLForHost(host);
351 const ContentSettingsPattern pattern = 310 const ContentSettingsPattern pattern =
352 ContentSettingsPattern::FromURLNoWildcard(url); 311 ContentSettingsPattern::FromURLNoWildcard(url);
353 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 312 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
354 313
355 scoped_ptr<base::Value> value(map->GetWebsiteSetting( 314 scoped_ptr<base::Value> value(map->GetWebsiteSetting(
356 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); 315 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL));
357 316
358 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) 317 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY))
359 return false; 318 return false;
360 319
361 base::DictionaryValue* dict; // Owned by value 320 base::DictionaryValue* dict; // Owned by value
362 bool success = value->GetAsDictionary(&dict); 321 bool success = value->GetAsDictionary(&dict);
363 DCHECK(success); 322 DCHECK(success);
364 323
365 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 324 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
366 int policy_decision; // Owned by dict 325 int policy_decision; // Owned by dict
367 success = it.value().GetAsInteger(&policy_decision); 326 success = it.value().GetAsInteger(&policy_decision);
368 if (success && (static_cast<net::CertPolicy::Judgment>(policy_decision) != 327 if (success && (static_cast<net::CertPolicy::Judgment>(policy_decision) !=
369 net::CertPolicy::UNKNOWN)) 328 net::CertPolicy::UNKNOWN))
370 return true; 329 return true;
371 } 330 }
372 331
373 return false; 332 return false;
374 } 333 }
375 334
376 void ChromeSSLHostStateDelegate::HostRanInsecureContent(const std::string& host,
377 int pid) {
378 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid));
379 }
380
381 bool ChromeSSLHostStateDelegate::DidHostRunInsecureContent(
382 const std::string& host,
383 int pid) const {
384 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid));
385 }
386 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { 335 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) {
387 clock_.reset(clock.release()); 336 clock_.reset(clock.release());
388 } 337 }
389 338
390 void ChromeSSLHostStateDelegate::ChangeCertPolicy( 339 void ChromeSSLHostStateDelegate::ChangeCertPolicy(
391 const std::string& host, 340 const std::string& host,
392 net::X509Certificate* cert, 341 net::X509Certificate* cert,
393 net::CertStatus error, 342 net::CertStatus error,
394 net::CertPolicy::Judgment judgment) { 343 net::CertPolicy::Judgment judgment) {
395 GURL url = GetSecureGURLForHost(host); 344 GURL url = GetSecureGURLForHost(host);
(...skipping 23 matching lines...) Expand all
419 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment); 368 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment);
420 369
421 // The map takes ownership of the value, so it is released in the call to 370 // The map takes ownership of the value, so it is released in the call to
422 // SetWebsiteSetting. 371 // SetWebsiteSetting.
423 map->SetWebsiteSetting(pattern, 372 map->SetWebsiteSetting(pattern,
424 pattern, 373 pattern,
425 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, 374 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
426 std::string(), 375 std::string(),
427 value.release()); 376 value.release());
428 } 377 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/chrome_ssl_host_state_delegate.h ('k') | chrome/browser/ssl/chrome_ssl_host_state_delegate_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698