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> |
| 8 |
7 #include "base/base64.h" | 9 #include "base/base64.h" |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
14 #include "base/time/default_clock.h" | 16 #include "base/time/default_clock.h" |
15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
19 #include "components/content_settings/core/common/content_settings_types.h" | 22 #include "components/content_settings/core/common/content_settings_types.h" |
20 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
21 #include "net/base/hash_value.h" | 24 #include "net/base/hash_value.h" |
22 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
23 #include "net/http/http_transaction_factory.h" | 26 #include "net/http/http_transaction_factory.h" |
24 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // canonicalizes all hosts into a secure scheme GURL to use with content | 68 // 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 | 69 // settings. The returned GURL will be the passed in host with an empty path and |
67 // https:// as the scheme. | 70 // https:// as the scheme. |
68 GURL GetSecureGURLForHost(const std::string& host) { | 71 GURL GetSecureGURLForHost(const std::string& host) { |
69 std::string url = "https://" + host; | 72 std::string url = "https://" + host; |
70 return GURL(url); | 73 return GURL(url); |
71 } | 74 } |
72 | 75 |
73 // This is a helper function that returns the length of time before a | 76 // This is a helper function that returns the length of time before a |
74 // certificate decision expires based on the command line flags. Returns a | 77 // certificate decision expires based on the command line flags. Returns a |
75 // non-negative value in seconds or a value of -1 indicating that decisions | 78 // non-negative value in seconds or a value of -1 indicating that decisions |
76 // should not be remembered after the current session has ended (but should be | 79 // should not be remembered after the current session has ended (but should be |
77 // remembered indefinitely as long as the session does not end), which is the | 80 // remembered indefinitely as long as the session does not end), which is the |
78 // "old" style of certificate decision memory. Uses the experimental group | 81 // "old" style of certificate decision memory. Uses the experimental group |
79 // unless overridden by a command line flag. | 82 // unless overridden by a command line flag. |
80 int64 GetExpirationDelta() { | 83 int64 GetExpirationDelta() { |
81 // Check command line flags first to give them priority, then check | 84 // Check command line flags first to give them priority, then check |
82 // experimental groups. | 85 // experimental groups. |
83 if (CommandLine::ForCurrentProcess()->HasSwitch( | 86 if (CommandLine::ForCurrentProcess()->HasSwitch( |
84 switches::kRememberCertErrorDecisions)) { | 87 switches::kRememberCertErrorDecisions)) { |
85 std::string switch_value = | 88 std::string switch_value = |
(...skipping 25 matching lines...) Expand all Loading... |
111 kRememberCertificateErrorDecisionsFieldTrialLengthParam); | 114 kRememberCertificateErrorDecisionsFieldTrialLengthParam); |
112 if (!param.empty() && base::StringToInt64(base::StringPiece(param), | 115 if (!param.empty() && base::StringToInt64(base::StringPiece(param), |
113 &field_trial_param_length)) { | 116 &field_trial_param_length)) { |
114 return field_trial_param_length; | 117 return field_trial_param_length; |
115 } | 118 } |
116 } | 119 } |
117 | 120 |
118 return kForgetAtSessionEndSwitchValue; | 121 return kForgetAtSessionEndSwitchValue; |
119 } | 122 } |
120 | 123 |
121 std::string GetKey(net::X509Certificate* cert, net::CertStatus error) { | 124 std::string GetKey(const net::X509Certificate& cert, net::CertStatus error) { |
122 // Since a security decision will be made based on the fingerprint, Chrome | 125 // Since a security decision will be made based on the fingerprint, Chrome |
123 // should use the SHA-256 fingerprint for the certificate. | 126 // should use the SHA-256 fingerprint for the certificate. |
124 net::SHA256HashValue fingerprint = | 127 net::SHA256HashValue fingerprint = |
125 net::X509Certificate::CalculateChainFingerprint256( | 128 net::X509Certificate::CalculateChainFingerprint256( |
126 cert->os_cert_handle(), cert->GetIntermediateCertificates()); | 129 cert.os_cert_handle(), cert.GetIntermediateCertificates()); |
127 std::string base64_fingerprint; | 130 std::string base64_fingerprint; |
128 base::Base64Encode( | 131 base::Base64Encode( |
129 base::StringPiece(reinterpret_cast<const char*>(fingerprint.data), | 132 base::StringPiece(reinterpret_cast<const char*>(fingerprint.data), |
130 sizeof(fingerprint.data)), | 133 sizeof(fingerprint.data)), |
131 &base64_fingerprint); | 134 &base64_fingerprint); |
132 return base::UintToString(error) + base64_fingerprint; | 135 return base::UintToString(error) + base64_fingerprint; |
133 } | 136 } |
134 | 137 |
135 } // namespace | 138 } // namespace |
136 | 139 |
137 // This helper function gets the dictionary of certificate fingerprints to | 140 // This helper function gets the dictionary of certificate fingerprints to |
138 // errors of certificates that have been accepted by the user from the content | 141 // errors of certificates that have been accepted by the user from the content |
139 // dictionary that has been passed in. The returned pointer is owned by the the | 142 // dictionary that has been passed in. The returned pointer is owned by the the |
140 // argument dict that is passed in. | 143 // argument dict that is passed in. |
141 // | 144 // |
142 // If create_entries is set to |DoNotCreateDictionaryEntries|, | 145 // If create_entries is set to |DO_NOT_CREATE_DICTIONARY_ENTRIES|, |
143 // GetValidCertDecisionsDict will return NULL if there is anything invalid about | 146 // GetValidCertDecisionsDict will return NULL if there is anything invalid about |
144 // the setting, such as an invalid version or invalid value types (in addition | 147 // the setting, such as an invalid version or invalid value types (in addition |
145 // to there not be any values in the dictionary). If create_entries is set to | 148 // to there not being any values in the dictionary). If create_entries is set to |
146 // |CreateDictionaryEntries|, if no dictionary is found or the decisions are | 149 // |CREATE_DICTIONARY_ENTRIES|, if no dictionary is found or the decisions are |
147 // expired, a new dictionary will be created | 150 // expired, a new dictionary will be created. |
148 base::DictionaryValue* ChromeSSLHostStateDelegate::GetValidCertDecisionsDict( | 151 base::DictionaryValue* ChromeSSLHostStateDelegate::GetValidCertDecisionsDict( |
149 base::DictionaryValue* dict, | 152 base::DictionaryValue* dict, |
150 CreateDictionaryEntriesDisposition create_entries, | 153 CreateDictionaryEntriesDisposition create_entries, |
151 bool* expired_previous_decision) { | 154 bool* expired_previous_decision) { |
152 // This needs to be done first in case the method is short circuited by an | 155 // This needs to be done first in case the method is short circuited by an |
153 // early failure. | 156 // early failure. |
154 *expired_previous_decision = false; | 157 *expired_previous_decision = false; |
155 | 158 |
156 // Extract the version of the certificate decision structure from the content | 159 // Extract the version of the certificate decision structure from the content |
157 // setting. | 160 // setting. |
158 int version; | 161 int version; |
159 bool success = dict->GetInteger(kSSLCertDecisionVersionKey, &version); | 162 bool success = dict->GetInteger(kSSLCertDecisionVersionKey, &version); |
160 if (!success) { | 163 if (!success) { |
161 if (create_entries == DoNotCreateDictionaryEntries) | 164 if (create_entries == DO_NOT_CREATE_DICTIONARY_ENTRIES) |
162 return NULL; | 165 return NULL; |
163 | 166 |
164 dict->SetInteger(kSSLCertDecisionVersionKey, | 167 dict->SetInteger(kSSLCertDecisionVersionKey, |
165 kDefaultSSLCertDecisionVersion); | 168 kDefaultSSLCertDecisionVersion); |
166 version = kDefaultSSLCertDecisionVersion; | 169 version = kDefaultSSLCertDecisionVersion; |
167 } | 170 } |
168 | 171 |
169 // If the version is somehow a newer version than Chrome can handle, there's | 172 // If the version is somehow a newer version than Chrome can handle, there's |
170 // really nothing to do other than fail silently and pretend it doesn't exist | 173 // really nothing to do other than fail silently and pretend it doesn't exist |
171 // (or is malformed). | 174 // (or is malformed). |
(...skipping 21 matching lines...) Expand all Loading... |
193 LOG(ERROR) << "Failed to parse a certificate error exception that has a " | 196 LOG(ERROR) << "Failed to parse a certificate error exception that has a " |
194 << "bad value for an expiration time: " | 197 << "bad value for an expiration time: " |
195 << decision_expiration_string; | 198 << decision_expiration_string; |
196 return NULL; | 199 return NULL; |
197 } | 200 } |
198 decision_expiration = | 201 decision_expiration = |
199 base::Time::FromInternalValue(decision_expiration_int64); | 202 base::Time::FromInternalValue(decision_expiration_int64); |
200 } | 203 } |
201 | 204 |
202 // Check to see if the user's certificate decision has expired. | 205 // Check to see if the user's certificate decision has expired. |
203 // - Expired and |create_entries| is DoNotCreateDictionaryEntries, return | 206 // - Expired and |create_entries| is DO_NOT_CREATE_DICTIONARY_ENTRIES, return |
204 // NULL. | 207 // NULL. |
205 // - Expired and |create_entries| is CreateDictionaryEntries, update the | 208 // - Expired and |create_entries| is CREATE_DICTIONARY_ENTRIES, update the |
206 // expiration time. | 209 // expiration time. |
207 if (should_remember_ssl_decisions_ != | 210 if (should_remember_ssl_decisions_ != |
208 ForgetSSLExceptionDecisionsAtSessionEnd && | 211 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END && |
209 decision_expiration.ToInternalValue() <= now.ToInternalValue()) { | 212 decision_expiration.ToInternalValue() <= now.ToInternalValue()) { |
210 *expired_previous_decision = true; | 213 *expired_previous_decision = true; |
211 | 214 |
212 if (create_entries == DoNotCreateDictionaryEntries) | 215 if (create_entries == DO_NOT_CREATE_DICTIONARY_ENTRIES) |
213 return NULL; | 216 return NULL; |
214 | 217 |
215 expired = true; | 218 expired = true; |
216 base::Time expiration_time = | 219 base::Time expiration_time = |
217 now + default_ssl_cert_decision_expiration_delta_; | 220 now + default_ssl_cert_decision_expiration_delta_; |
218 // Unfortunately, JSON (and thus content settings) doesn't support int64 | 221 // Unfortunately, JSON (and thus content settings) doesn't support int64 |
219 // values, only doubles. Since this mildly depends on precision, it is | 222 // values, only doubles. Since this mildly depends on precision, it is |
220 // better to store the value as a string. | 223 // better to store the value as a string. |
221 dict->SetString(kSSLCertDecisionExpirationTimeKey, | 224 dict->SetString(kSSLCertDecisionExpirationTimeKey, |
222 base::Int64ToString(expiration_time.ToInternalValue())); | 225 base::Int64ToString(expiration_time.ToInternalValue())); |
223 } | 226 } |
224 | 227 |
225 // Extract the map of certificate fingerprints to errors from the setting. | 228 // Extract the map of certificate fingerprints to errors from the setting. |
226 base::DictionaryValue* cert_error_dict = NULL; // Will be owned by dict | 229 base::DictionaryValue* cert_error_dict = NULL; // Will be owned by dict |
227 if (expired || | 230 if (expired || |
228 !dict->GetDictionary(kSSLCertDecisionCertErrorMapKey, &cert_error_dict)) { | 231 !dict->GetDictionary(kSSLCertDecisionCertErrorMapKey, &cert_error_dict)) { |
229 if (create_entries == DoNotCreateDictionaryEntries) | 232 if (create_entries == DO_NOT_CREATE_DICTIONARY_ENTRIES) |
230 return NULL; | 233 return NULL; |
231 | 234 |
232 cert_error_dict = new base::DictionaryValue(); | 235 cert_error_dict = new base::DictionaryValue(); |
233 // dict takes ownership of cert_error_dict | 236 // dict takes ownership of cert_error_dict |
234 dict->Set(kSSLCertDecisionCertErrorMapKey, cert_error_dict); | 237 dict->Set(kSSLCertDecisionCertErrorMapKey, cert_error_dict); |
235 } | 238 } |
236 | 239 |
237 return cert_error_dict; | 240 return cert_error_dict; |
238 } | 241 } |
239 | 242 |
240 // If |should_remember_ssl_decisions_| is | 243 // If |should_remember_ssl_decisions_| is |
241 // ForgetSSLExceptionDecisionsAtSessionEnd, that means that all invalid | 244 // FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END, that means that all invalid |
242 // certificate proceed decisions should be forgotten when the session ends. At | 245 // certificate proceed decisions should be forgotten when the session ends. At |
243 // attempt is made in the destructor to remove the entries, but in the case that | 246 // attempt is made in the destructor to remove the entries, but in the case that |
244 // things didn't shut down cleanly, on start, Clear is called to guarantee a | 247 // things didn't shut down cleanly, on start, Clear is called to guarantee a |
245 // clean state. | 248 // clean state. |
246 ChromeSSLHostStateDelegate::ChromeSSLHostStateDelegate(Profile* profile) | 249 ChromeSSLHostStateDelegate::ChromeSSLHostStateDelegate(Profile* profile) |
247 : clock_(new base::DefaultClock()), profile_(profile) { | 250 : clock_(new base::DefaultClock()), profile_(profile) { |
248 int64 expiration_delta = GetExpirationDelta(); | 251 int64 expiration_delta = GetExpirationDelta(); |
249 if (expiration_delta == kForgetAtSessionEndSwitchValue) { | 252 if (expiration_delta == kForgetAtSessionEndSwitchValue) { |
250 should_remember_ssl_decisions_ = ForgetSSLExceptionDecisionsAtSessionEnd; | 253 should_remember_ssl_decisions_ = |
| 254 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END; |
251 expiration_delta = 0; | 255 expiration_delta = 0; |
252 Clear(); | 256 Clear(); |
253 } else { | 257 } else { |
254 should_remember_ssl_decisions_ = RememberSSLExceptionDecisionsForDelta; | 258 should_remember_ssl_decisions_ = REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA; |
255 } | 259 } |
256 default_ssl_cert_decision_expiration_delta_ = | 260 default_ssl_cert_decision_expiration_delta_ = |
257 base::TimeDelta::FromSeconds(expiration_delta); | 261 base::TimeDelta::FromSeconds(expiration_delta); |
258 } | 262 } |
259 | 263 |
260 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() { | 264 ChromeSSLHostStateDelegate::~ChromeSSLHostStateDelegate() { |
261 if (should_remember_ssl_decisions_ == ForgetSSLExceptionDecisionsAtSessionEnd) | 265 if (should_remember_ssl_decisions_ == |
| 266 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END) |
262 Clear(); | 267 Clear(); |
263 } | 268 } |
264 | 269 |
265 void ChromeSSLHostStateDelegate::DenyCert(const std::string& host, | 270 void ChromeSSLHostStateDelegate::DenyCert(const std::string& host, |
266 net::X509Certificate* cert, | 271 const net::X509Certificate& cert, |
267 net::CertStatus error) { | 272 net::CertStatus error) { |
268 ChangeCertPolicy(host, cert, error, net::CertPolicy::DENIED); | 273 ChangeCertPolicy(host, cert, error, net::CertPolicy::DENIED); |
269 } | 274 } |
270 | 275 |
271 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host, | 276 void ChromeSSLHostStateDelegate::AllowCert(const std::string& host, |
272 net::X509Certificate* cert, | 277 const net::X509Certificate& cert, |
273 net::CertStatus error) { | 278 net::CertStatus error) { |
274 ChangeCertPolicy(host, cert, error, net::CertPolicy::ALLOWED); | 279 ChangeCertPolicy(host, cert, error, net::CertPolicy::ALLOWED); |
275 } | 280 } |
276 | 281 |
277 void ChromeSSLHostStateDelegate::Clear() { | 282 void ChromeSSLHostStateDelegate::Clear() { |
278 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( | 283 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( |
279 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS); | 284 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS); |
280 } | 285 } |
281 | 286 |
282 net::CertPolicy::Judgment ChromeSSLHostStateDelegate::QueryPolicy( | 287 net::CertPolicy::Judgment ChromeSSLHostStateDelegate::QueryPolicy( |
283 const std::string& host, | 288 const std::string& host, |
284 net::X509Certificate* cert, | 289 const net::X509Certificate& cert, |
285 net::CertStatus error, | 290 net::CertStatus error, |
286 bool* expired_previous_decision) { | 291 bool* expired_previous_decision) { |
287 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); | 292 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); |
288 GURL url = GetSecureGURLForHost(host); | 293 GURL url = GetSecureGURLForHost(host); |
289 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | 294 scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
290 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); | 295 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); |
291 | 296 |
292 // Set a default value in case this method is short circuited and doesn't do a | 297 // Set a default value in case this method is short circuited and doesn't do a |
293 // full query. | 298 // full query. |
294 *expired_previous_decision = false; | 299 *expired_previous_decision = false; |
295 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) | 300 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) |
296 return net::CertPolicy::UNKNOWN; | 301 return net::CertPolicy::UNKNOWN; |
297 | 302 |
298 base::DictionaryValue* dict; // Owned by value | 303 base::DictionaryValue* dict; // Owned by value |
299 int policy_decision; | 304 int policy_decision; |
300 bool success = value->GetAsDictionary(&dict); | 305 bool success = value->GetAsDictionary(&dict); |
301 DCHECK(success); | 306 DCHECK(success); |
302 | 307 |
303 base::DictionaryValue* cert_error_dict; // Owned by value | 308 base::DictionaryValue* cert_error_dict; // Owned by value |
304 cert_error_dict = GetValidCertDecisionsDict( | 309 cert_error_dict = GetValidCertDecisionsDict( |
305 dict, DoNotCreateDictionaryEntries, expired_previous_decision); | 310 dict, DO_NOT_CREATE_DICTIONARY_ENTRIES, expired_previous_decision); |
306 if (!cert_error_dict) { | 311 if (!cert_error_dict) { |
307 // This revoke is necessary to clear any old expired setting that may | 312 // This revoke is necessary to clear any old expired setting that may be |
308 // lingering in the case that an old decision expried. | 313 // lingering in the case that an old decision expried. |
309 RevokeUserDecisions(host); | 314 RevokeUserDecisions(host); |
310 return net::CertPolicy::UNKNOWN; | 315 return net::CertPolicy::UNKNOWN; |
311 } | 316 } |
312 | 317 |
313 success = cert_error_dict->GetIntegerWithoutPathExpansion(GetKey(cert, error), | 318 success = cert_error_dict->GetIntegerWithoutPathExpansion(GetKey(cert, error), |
314 &policy_decision); | 319 &policy_decision); |
315 | 320 |
316 // If a policy decision was successfully retrieved and it's a valid value of | 321 // If a policy decision was successfully retrieved and it's a valid value of |
317 // ALLOWED or DENIED, return the valid value. Otherwise, return UNKNOWN. | 322 // ALLOWED or DENIED, return the valid value. Otherwise, return UNKNOWN. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // stack a way revoke SSLConfig's allowed_bad_certs lists per socket. | 354 // stack a way revoke SSLConfig's allowed_bad_certs lists per socket. |
350 // | 355 // |
351 // For now, RevokeUserDecisionsHard is our solution for the rare case where it | 356 // For now, RevokeUserDecisionsHard is our solution for the rare case where it |
352 // is necessary to revoke the preferences immediately. It does so by flushing | 357 // is necessary to revoke the preferences immediately. It does so by flushing |
353 // idle sockets. | 358 // idle sockets. |
354 void ChromeSSLHostStateDelegate::RevokeUserDecisionsHard( | 359 void ChromeSSLHostStateDelegate::RevokeUserDecisionsHard( |
355 const std::string& host) { | 360 const std::string& host) { |
356 RevokeUserDecisions(host); | 361 RevokeUserDecisions(host); |
357 scoped_refptr<net::URLRequestContextGetter> getter( | 362 scoped_refptr<net::URLRequestContextGetter> getter( |
358 profile_->GetRequestContext()); | 363 profile_->GetRequestContext()); |
359 profile_->GetRequestContext()->GetNetworkTaskRunner()->PostTask( | 364 getter->GetNetworkTaskRunner()->PostTask( |
360 FROM_HERE, base::Bind(&CloseIdleConnections, getter)); | 365 FROM_HERE, base::Bind(&CloseIdleConnections, getter)); |
361 } | 366 } |
362 | 367 |
363 bool ChromeSSLHostStateDelegate::HasUserDecision(const std::string& host) { | 368 bool ChromeSSLHostStateDelegate::HasUserDecision( |
| 369 const std::string& host) const { |
364 GURL url = GetSecureGURLForHost(host); | 370 GURL url = GetSecureGURLForHost(host); |
365 const ContentSettingsPattern pattern = | 371 const ContentSettingsPattern pattern = |
366 ContentSettingsPattern::FromURLNoWildcard(url); | 372 ContentSettingsPattern::FromURLNoWildcard(url); |
367 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); | 373 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); |
368 | 374 |
369 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | 375 scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
370 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); | 376 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); |
371 | 377 |
372 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) | 378 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) |
373 return false; | 379 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
396 const std::string& host, | 402 const std::string& host, |
397 int pid) const { | 403 int pid) const { |
398 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); | 404 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); |
399 } | 405 } |
400 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { | 406 void ChromeSSLHostStateDelegate::SetClock(scoped_ptr<base::Clock> clock) { |
401 clock_.reset(clock.release()); | 407 clock_.reset(clock.release()); |
402 } | 408 } |
403 | 409 |
404 void ChromeSSLHostStateDelegate::ChangeCertPolicy( | 410 void ChromeSSLHostStateDelegate::ChangeCertPolicy( |
405 const std::string& host, | 411 const std::string& host, |
406 net::X509Certificate* cert, | 412 const net::X509Certificate& cert, |
407 net::CertStatus error, | 413 net::CertStatus error, |
408 net::CertPolicy::Judgment judgment) { | 414 const net::CertPolicy::Judgment judgment) { |
409 GURL url = GetSecureGURLForHost(host); | 415 GURL url = GetSecureGURLForHost(host); |
410 const ContentSettingsPattern pattern = | 416 const ContentSettingsPattern pattern = |
411 ContentSettingsPattern::FromURLNoWildcard(url); | 417 ContentSettingsPattern::FromURLNoWildcard(url); |
412 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); | 418 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); |
413 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | 419 scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
414 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); | 420 url, url, CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, std::string(), NULL)); |
415 | 421 |
416 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) | 422 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) |
417 value.reset(new base::DictionaryValue()); | 423 value.reset(new base::DictionaryValue()); |
418 | 424 |
419 base::DictionaryValue* dict; | 425 base::DictionaryValue* dict; |
420 bool success = value->GetAsDictionary(&dict); | 426 bool success = value->GetAsDictionary(&dict); |
421 DCHECK(success); | 427 DCHECK(success); |
422 | 428 |
423 bool expired_previous_decision; // unused value in this function | 429 bool expired_previous_decision; // unused value in this function |
424 base::DictionaryValue* cert_dict = GetValidCertDecisionsDict( | 430 base::DictionaryValue* cert_dict = GetValidCertDecisionsDict( |
425 dict, CreateDictionaryEntries, &expired_previous_decision); | 431 dict, CREATE_DICTIONARY_ENTRIES, &expired_previous_decision); |
426 // If a a valid certificate dictionary cannot be extracted from the content | 432 // If a a valid certificate dictionary cannot be extracted from the content |
427 // setting, that means it's in an unknown format. Unfortunately, there's | 433 // setting, that means it's in an unknown format. Unfortunately, there's |
428 // nothing to be done in that case, so a silent fail is the only option. | 434 // nothing to be done in that case, so a silent fail is the only option. |
429 if (!cert_dict) | 435 if (!cert_dict) |
430 return; | 436 return; |
431 | 437 |
432 dict->SetIntegerWithoutPathExpansion(kSSLCertDecisionVersionKey, | 438 dict->SetIntegerWithoutPathExpansion(kSSLCertDecisionVersionKey, |
433 kDefaultSSLCertDecisionVersion); | 439 kDefaultSSLCertDecisionVersion); |
434 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment); | 440 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), judgment); |
435 | 441 |
436 // The map takes ownership of the value, so it is released in the call to | 442 // The map takes ownership of the value, so it is released in the call to |
437 // SetWebsiteSetting. | 443 // SetWebsiteSetting. |
438 map->SetWebsiteSetting(pattern, | 444 map->SetWebsiteSetting(pattern, |
439 pattern, | 445 pattern, |
440 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, | 446 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, |
441 std::string(), | 447 std::string(), |
442 value.release()); | 448 value.release()); |
443 } | 449 } |
OLD | NEW |