| OLD | NEW |
| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/guid.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/clock.h" | 16 #include "base/time/clock.h" |
| 16 #include "base/time/default_clock.h" | 17 #include "base/time/default_clock.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 20 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 "RememberCertificateErrorDecisions"; | 40 "RememberCertificateErrorDecisions"; |
| 40 const char kRememberCertificateErrorDecisionsFieldTrialDefaultGroup[] = | 41 const char kRememberCertificateErrorDecisionsFieldTrialDefaultGroup[] = |
| 41 "Default"; | 42 "Default"; |
| 42 const char kRememberCertificateErrorDecisionsFieldTrialLengthParam[] = "length"; | 43 const char kRememberCertificateErrorDecisionsFieldTrialLengthParam[] = "length"; |
| 43 | 44 |
| 44 // Keys for the per-site error + certificate finger to judgment content | 45 // Keys for the per-site error + certificate finger to judgment content |
| 45 // settings map. | 46 // settings map. |
| 46 const char kSSLCertDecisionCertErrorMapKey[] = "cert_exceptions_map"; | 47 const char kSSLCertDecisionCertErrorMapKey[] = "cert_exceptions_map"; |
| 47 const char kSSLCertDecisionExpirationTimeKey[] = "decision_expiration_time"; | 48 const char kSSLCertDecisionExpirationTimeKey[] = "decision_expiration_time"; |
| 48 const char kSSLCertDecisionVersionKey[] = "version"; | 49 const char kSSLCertDecisionVersionKey[] = "version"; |
| 50 const char kSSLCertDecisionGUIDKey[] = "guid"; |
| 49 | 51 |
| 50 const int kDefaultSSLCertDecisionVersion = 1; | 52 const int kDefaultSSLCertDecisionVersion = 1; |
| 51 | 53 |
| 52 void CloseIdleConnections( | 54 void CloseIdleConnections( |
| 53 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { | 55 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { |
| 54 url_request_context_getter-> | 56 url_request_context_getter-> |
| 55 GetURLRequestContext()-> | 57 GetURLRequestContext()-> |
| 56 http_transaction_factory()-> | 58 http_transaction_factory()-> |
| 57 GetSession()-> | 59 GetSession()-> |
| 58 CloseIdleConnections(); | 60 CloseIdleConnections(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return NULL; | 212 return NULL; |
| 211 | 213 |
| 212 expired = true; | 214 expired = true; |
| 213 base::Time expiration_time = | 215 base::Time expiration_time = |
| 214 now + default_ssl_cert_decision_expiration_delta_; | 216 now + default_ssl_cert_decision_expiration_delta_; |
| 215 // Unfortunately, JSON (and thus content settings) doesn't support int64 | 217 // Unfortunately, JSON (and thus content settings) doesn't support int64 |
| 216 // values, only doubles. Since this mildly depends on precision, it is | 218 // values, only doubles. Since this mildly depends on precision, it is |
| 217 // better to store the value as a string. | 219 // better to store the value as a string. |
| 218 dict->SetString(kSSLCertDecisionExpirationTimeKey, | 220 dict->SetString(kSSLCertDecisionExpirationTimeKey, |
| 219 base::Int64ToString(expiration_time.ToInternalValue())); | 221 base::Int64ToString(expiration_time.ToInternalValue())); |
| 222 } else if (should_remember_ssl_decisions_ == |
| 223 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END) { |
| 224 if (dict->HasKey(kSSLCertDecisionGUIDKey)) { |
| 225 std::string old_expiration_guid; |
| 226 success = dict->GetString(kSSLCertDecisionGUIDKey, &old_expiration_guid); |
| 227 if (old_expiration_guid.compare(current_expiration_guid_) != 0) { |
| 228 *expired_previous_decision = true; |
| 229 expired = true; |
| 230 } |
| 231 } |
| 220 } | 232 } |
| 221 | 233 |
| 234 dict->SetString(kSSLCertDecisionGUIDKey, current_expiration_guid_); |
| 235 |
| 222 // Extract the map of certificate fingerprints to errors from the setting. | 236 // Extract the map of certificate fingerprints to errors from the setting. |
| 223 base::DictionaryValue* cert_error_dict = NULL; // Will be owned by dict | 237 base::DictionaryValue* cert_error_dict = NULL; // Will be owned by dict |
| 224 if (expired || | 238 if (expired || |
| 225 !dict->GetDictionary(kSSLCertDecisionCertErrorMapKey, &cert_error_dict)) { | 239 !dict->GetDictionary(kSSLCertDecisionCertErrorMapKey, &cert_error_dict)) { |
| 226 if (create_entries == DO_NOT_CREATE_DICTIONARY_ENTRIES) | 240 if (create_entries == DO_NOT_CREATE_DICTIONARY_ENTRIES) |
| 227 return NULL; | 241 return NULL; |
| 228 | 242 |
| 229 cert_error_dict = new base::DictionaryValue(); | 243 cert_error_dict = new base::DictionaryValue(); |
| 230 // dict takes ownership of cert_error_dict | 244 // dict takes ownership of cert_error_dict |
| 231 dict->Set(kSSLCertDecisionCertErrorMapKey, cert_error_dict); | 245 dict->Set(kSSLCertDecisionCertErrorMapKey, cert_error_dict); |
| 232 } | 246 } |
| 233 | 247 |
| 234 return cert_error_dict; | 248 return cert_error_dict; |
| 235 } | 249 } |
| 236 | 250 |
| 237 // If |should_remember_ssl_decisions_| is | 251 // If |should_remember_ssl_decisions_| is |
| 238 // FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END, that means that all invalid | 252 // FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END, that means that all invalid |
| 239 // certificate proceed decisions should be forgotten when the session ends. At | 253 // certificate proceed decisions should be forgotten when the session ends. To |
| 240 // attempt is made in the destructor to remove the entries, but in the case that | 254 // simulate that, Chrome keeps track of a guid to represent the current browser |
| 241 // things didn't shut down cleanly, on start, Clear is called to guarantee a | 255 // session and stores it in decision entries. See the comment for |
| 242 // clean state. | 256 // |current_expiration_guid_| for more information. |
| 243 ChromeSSLHostStateDelegate::ChromeSSLHostStateDelegate(Profile* profile) | 257 ChromeSSLHostStateDelegate::ChromeSSLHostStateDelegate(Profile* profile) |
| 244 : clock_(new base::DefaultClock()), profile_(profile) { | 258 : clock_(new base::DefaultClock()), |
| 259 profile_(profile), |
| 260 current_expiration_guid_(base::GenerateGUID()) { |
| 245 int64 expiration_delta = GetExpirationDelta(); | 261 int64 expiration_delta = GetExpirationDelta(); |
| 246 if (expiration_delta == kForgetAtSessionEndSwitchValue) { | 262 if (expiration_delta == kForgetAtSessionEndSwitchValue) { |
| 247 should_remember_ssl_decisions_ = | 263 should_remember_ssl_decisions_ = |
| 248 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END; | 264 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END; |
| 249 expiration_delta = 0; | 265 expiration_delta = 0; |
| 250 Clear(); | |
| 251 } else { | 266 } else { |
| 252 should_remember_ssl_decisions_ = REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA; | 267 should_remember_ssl_decisions_ = REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA; |
| 253 } | 268 } |
| 254 default_ssl_cert_decision_expiration_delta_ = | 269 default_ssl_cert_decision_expiration_delta_ = |
| 255 base::TimeDelta::FromSeconds(expiration_delta); | 270 base::TimeDelta::FromSeconds(expiration_delta); |
| 256 } | 271 } |
| 257 | 272 |
| 258 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() { | 273 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() { |
| 259 if (should_remember_ssl_decisions_ == | |
| 260 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END) | |
| 261 Clear(); | |
| 262 } | 274 } |
| 263 | 275 |
| 264 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host, | 276 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host, |
| 265 const net::X509Certificate& cert, | 277 const net::X509Certificate& cert, |
| 266 net::CertStatus error) { | 278 net::CertStatus error) { |
| 267 GURL url = GetSecureGURLForHost(host); | 279 GURL url = GetSecureGURLForHost(host); |
| 268 const ContentSettingsPattern pattern = | 280 const ContentSettingsPattern pattern = |
| 269 ContentSettingsPattern::FromURLNoWildcard(url); | 281 ContentSettingsPattern::FromURLNoWildcard(url); |
| 270 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); | 282 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); |
| 271 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | 283 scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 431 } |
| 420 | 432 |
| 421 bool ChromeSSLHostStateDelegate::DidHostRunInsecureContent( | 433 bool ChromeSSLHostStateDelegate::DidHostRunInsecureContent( |
| 422 const std::string& host, | 434 const std::string& host, |
| 423 int pid) const { | 435 int pid) const { |
| 424 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); | 436 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); |
| 425 } | 437 } |
| 426 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { | 438 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { |
| 427 clock_.reset(clock.release()); | 439 clock_.reset(clock.release()); |
| 428 } | 440 } |
| OLD | NEW |