OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 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 #include "components/ssl_config/ssl_config_service_manager.h" | 4 #include "components/ssl_config/ssl_config_service_manager.h" |
5 | 5 |
| 6 #include <stdint.h> |
| 7 |
6 #include <algorithm> | 8 #include <algorithm> |
7 #include <string> | 9 #include <string> |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" |
12 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
13 #include "base/prefs/pref_change_registrar.h" | 15 #include "base/prefs/pref_change_registrar.h" |
14 #include "base/prefs/pref_member.h" | 16 #include "base/prefs/pref_member.h" |
15 #include "base/prefs/pref_registry_simple.h" | 17 #include "base/prefs/pref_registry_simple.h" |
16 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "components/content_settings/core/browser/content_settings_utils.h" | 22 #include "components/content_settings/core/browser/content_settings_utils.h" |
21 #include "components/content_settings/core/common/content_settings.h" | 23 #include "components/content_settings/core/common/content_settings.h" |
(...skipping 19 matching lines...) Expand all Loading... |
41 if (!(*it)->GetAsString(&s)) | 43 if (!(*it)->GetAsString(&s)) |
42 continue; | 44 continue; |
43 results.push_back(s); | 45 results.push_back(s); |
44 } | 46 } |
45 return results; | 47 return results; |
46 } | 48 } |
47 | 49 |
48 // Parses a vector of cipher suite strings, returning a sorted vector | 50 // Parses a vector of cipher suite strings, returning a sorted vector |
49 // containing the underlying SSL/TLS cipher suites. Unrecognized/invalid | 51 // containing the underlying SSL/TLS cipher suites. Unrecognized/invalid |
50 // cipher suites will be ignored. | 52 // cipher suites will be ignored. |
51 std::vector<uint16> ParseCipherSuites( | 53 std::vector<uint16_t> ParseCipherSuites( |
52 const std::vector<std::string>& cipher_strings) { | 54 const std::vector<std::string>& cipher_strings) { |
53 std::vector<uint16> cipher_suites; | 55 std::vector<uint16_t> cipher_suites; |
54 cipher_suites.reserve(cipher_strings.size()); | 56 cipher_suites.reserve(cipher_strings.size()); |
55 | 57 |
56 for (std::vector<std::string>::const_iterator it = cipher_strings.begin(); | 58 for (std::vector<std::string>::const_iterator it = cipher_strings.begin(); |
57 it != cipher_strings.end(); ++it) { | 59 it != cipher_strings.end(); ++it) { |
58 uint16 cipher_suite = 0; | 60 uint16_t cipher_suite = 0; |
59 if (!net::ParseSSLCipherString(*it, &cipher_suite)) { | 61 if (!net::ParseSSLCipherString(*it, &cipher_suite)) { |
60 LOG(ERROR) << "Ignoring unrecognized or unparsable cipher suite: " << *it; | 62 LOG(ERROR) << "Ignoring unrecognized or unparsable cipher suite: " << *it; |
61 continue; | 63 continue; |
62 } | 64 } |
63 cipher_suites.push_back(cipher_suite); | 65 cipher_suites.push_back(cipher_suite); |
64 } | 66 } |
65 std::sort(cipher_suites.begin(), cipher_suites.end()); | 67 std::sort(cipher_suites.begin(), cipher_suites.end()); |
66 return cipher_suites; | 68 return cipher_suites; |
67 } | 69 } |
68 | 70 |
69 // Returns the SSL protocol version (as a uint16) represented by a string. | 71 // Returns the SSL protocol version (as a uint16_t) represented by a string. |
70 // Returns 0 if the string is invalid. | 72 // Returns 0 if the string is invalid. |
71 uint16 SSLProtocolVersionFromString(const std::string& version_str) { | 73 uint16_t SSLProtocolVersionFromString(const std::string& version_str) { |
72 uint16 version = 0; // Invalid. | 74 uint16_t version = 0; // Invalid. |
73 if (version_str == switches::kSSLVersionTLSv1) { | 75 if (version_str == switches::kSSLVersionTLSv1) { |
74 version = net::SSL_PROTOCOL_VERSION_TLS1; | 76 version = net::SSL_PROTOCOL_VERSION_TLS1; |
75 } else if (version_str == switches::kSSLVersionTLSv11) { | 77 } else if (version_str == switches::kSSLVersionTLSv11) { |
76 version = net::SSL_PROTOCOL_VERSION_TLS1_1; | 78 version = net::SSL_PROTOCOL_VERSION_TLS1_1; |
77 } else if (version_str == switches::kSSLVersionTLSv12) { | 79 } else if (version_str == switches::kSSLVersionTLSv12) { |
78 version = net::SSL_PROTOCOL_VERSION_TLS1_2; | 80 version = net::SSL_PROTOCOL_VERSION_TLS1_2; |
79 } | 81 } |
80 return version; | 82 return version; |
81 } | 83 } |
82 | 84 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 170 |
169 // The local_state prefs (should only be accessed from UI thread) | 171 // The local_state prefs (should only be accessed from UI thread) |
170 BooleanPrefMember rev_checking_enabled_; | 172 BooleanPrefMember rev_checking_enabled_; |
171 BooleanPrefMember rev_checking_required_local_anchors_; | 173 BooleanPrefMember rev_checking_required_local_anchors_; |
172 StringPrefMember ssl_version_min_; | 174 StringPrefMember ssl_version_min_; |
173 StringPrefMember ssl_version_max_; | 175 StringPrefMember ssl_version_max_; |
174 StringPrefMember ssl_version_fallback_min_; | 176 StringPrefMember ssl_version_fallback_min_; |
175 BooleanPrefMember rc4_enabled_; | 177 BooleanPrefMember rc4_enabled_; |
176 | 178 |
177 // The cached list of disabled SSL cipher suites. | 179 // The cached list of disabled SSL cipher suites. |
178 std::vector<uint16> disabled_cipher_suites_; | 180 std::vector<uint16_t> disabled_cipher_suites_; |
179 | 181 |
180 scoped_refptr<SSLConfigServicePref> ssl_config_service_; | 182 scoped_refptr<SSLConfigServicePref> ssl_config_service_; |
181 | 183 |
182 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 184 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
183 | 185 |
184 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); | 186 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); |
185 }; | 187 }; |
186 | 188 |
187 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( | 189 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( |
188 PrefService* local_state, | 190 PrefService* local_state, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 else | 276 else |
275 config->rev_checking_enabled = false; | 277 config->rev_checking_enabled = false; |
276 config->rev_checking_required_local_anchors = | 278 config->rev_checking_required_local_anchors = |
277 rev_checking_required_local_anchors_.GetValue(); | 279 rev_checking_required_local_anchors_.GetValue(); |
278 std::string version_min_str = ssl_version_min_.GetValue(); | 280 std::string version_min_str = ssl_version_min_.GetValue(); |
279 std::string version_max_str = ssl_version_max_.GetValue(); | 281 std::string version_max_str = ssl_version_max_.GetValue(); |
280 std::string version_fallback_min_str = ssl_version_fallback_min_.GetValue(); | 282 std::string version_fallback_min_str = ssl_version_fallback_min_.GetValue(); |
281 config->version_min = net::kDefaultSSLVersionMin; | 283 config->version_min = net::kDefaultSSLVersionMin; |
282 config->version_max = net::kDefaultSSLVersionMax; | 284 config->version_max = net::kDefaultSSLVersionMax; |
283 config->version_fallback_min = net::kDefaultSSLVersionFallbackMin; | 285 config->version_fallback_min = net::kDefaultSSLVersionFallbackMin; |
284 uint16 version_min = SSLProtocolVersionFromString(version_min_str); | 286 uint16_t version_min = SSLProtocolVersionFromString(version_min_str); |
285 uint16 version_max = SSLProtocolVersionFromString(version_max_str); | 287 uint16_t version_max = SSLProtocolVersionFromString(version_max_str); |
286 uint16 version_fallback_min = | 288 uint16_t version_fallback_min = |
287 SSLProtocolVersionFromString(version_fallback_min_str); | 289 SSLProtocolVersionFromString(version_fallback_min_str); |
288 if (version_min) { | 290 if (version_min) { |
289 config->version_min = version_min; | 291 config->version_min = version_min; |
290 } | 292 } |
291 if (version_max) { | 293 if (version_max) { |
292 uint16 supported_version_max = config->version_max; | 294 uint16_t supported_version_max = config->version_max; |
293 config->version_max = std::min(supported_version_max, version_max); | 295 config->version_max = std::min(supported_version_max, version_max); |
294 } | 296 } |
295 if (version_fallback_min) { | 297 if (version_fallback_min) { |
296 config->version_fallback_min = version_fallback_min; | 298 config->version_fallback_min = version_fallback_min; |
297 } | 299 } |
298 config->disabled_cipher_suites = disabled_cipher_suites_; | 300 config->disabled_cipher_suites = disabled_cipher_suites_; |
299 config->rc4_enabled = rc4_enabled_.GetValue(); | 301 config->rc4_enabled = rc4_enabled_.GetValue(); |
300 } | 302 } |
301 | 303 |
302 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( | 304 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( |
(...skipping 12 matching lines...) Expand all Loading... |
315 PrefService* local_state, | 317 PrefService* local_state, |
316 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { | 318 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { |
317 return new SSLConfigServiceManagerPref(local_state, io_task_runner); | 319 return new SSLConfigServiceManagerPref(local_state, io_task_runner); |
318 } | 320 } |
319 | 321 |
320 // static | 322 // static |
321 void SSLConfigServiceManager::RegisterPrefs(PrefRegistrySimple* registry) { | 323 void SSLConfigServiceManager::RegisterPrefs(PrefRegistrySimple* registry) { |
322 SSLConfigServiceManagerPref::RegisterPrefs(registry); | 324 SSLConfigServiceManagerPref::RegisterPrefs(registry); |
323 } | 325 } |
324 } // namespace ssl_config | 326 } // namespace ssl_config |
OLD | NEW |