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

Side by Side Diff: components/ssl_config/ssl_config_service_manager_pref.cc

Issue 1320533007: Componentize ssl_config_service_manager_pref.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added OWNERS and updated gypi type Created 5 years, 3 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
OLDNEW
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 "chrome/browser/net/ssl_config_service_manager.h" 4 #include "components/ssl_config/ssl_config_service_manager.h"
5 5
6 #include <algorithm> 6 #include <algorithm>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/prefs/pref_change_registrar.h" 13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/prefs/pref_member.h" 14 #include "base/prefs/pref_member.h"
15 #include "base/prefs/pref_registry_simple.h" 15 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "base/single_thread_task_runner.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h"
20 #include "components/content_settings/core/browser/content_settings_utils.h" 18 #include "components/content_settings/core/browser/content_settings_utils.h"
21 #include "components/content_settings/core/common/content_settings.h" 19 #include "components/content_settings/core/common/content_settings.h"
22 #include "content/public/browser/browser_thread.h" 20 #include "components/ssl_config/ssl_config_prefs.h"
21 #include "components/ssl_config/ssl_config_switches.h"
23 #include "net/socket/ssl_client_socket.h" 22 #include "net/socket/ssl_client_socket.h"
24 #include "net/ssl/ssl_cipher_suite_names.h" 23 #include "net/ssl/ssl_cipher_suite_names.h"
25 #include "net/ssl/ssl_config_service.h" 24 #include "net/ssl/ssl_config_service.h"
26 25
27 using content::BrowserThread; 26 namespace base {
27 class SingleThreadTaskRunner;
28 }
28 29
29 namespace { 30 namespace {
30 31
31 // Converts a ListValue of StringValues into a vector of strings. Any Values 32 // Converts a ListValue of StringValues into a vector of strings. Any Values
32 // which cannot be converted will be skipped. 33 // which cannot be converted will be skipped.
33 std::vector<std::string> ListValueToStringVector(const base::ListValue* value) { 34 std::vector<std::string> ListValueToStringVector(const base::ListValue* value) {
34 std::vector<std::string> results; 35 std::vector<std::string> results;
35 results.reserve(value->GetSize()); 36 results.reserve(value->GetSize());
36 std::string s; 37 std::string s;
37 for (base::ListValue::const_iterator it = value->begin(); it != value->end(); 38 for (base::ListValue::const_iterator it = value->begin(); it != value->end();
(...skipping 10 matching lines...) Expand all
48 // cipher suites will be ignored. 49 // cipher suites will be ignored.
49 std::vector<uint16> ParseCipherSuites( 50 std::vector<uint16> ParseCipherSuites(
50 const std::vector<std::string>& cipher_strings) { 51 const std::vector<std::string>& cipher_strings) {
51 std::vector<uint16> cipher_suites; 52 std::vector<uint16> cipher_suites;
52 cipher_suites.reserve(cipher_strings.size()); 53 cipher_suites.reserve(cipher_strings.size());
53 54
54 for (std::vector<std::string>::const_iterator it = cipher_strings.begin(); 55 for (std::vector<std::string>::const_iterator it = cipher_strings.begin();
55 it != cipher_strings.end(); ++it) { 56 it != cipher_strings.end(); ++it) {
56 uint16 cipher_suite = 0; 57 uint16 cipher_suite = 0;
57 if (!net::ParseSSLCipherString(*it, &cipher_suite)) { 58 if (!net::ParseSSLCipherString(*it, &cipher_suite)) {
58 LOG(ERROR) << "Ignoring unrecognized or unparsable cipher suite: " 59 LOG(ERROR) << "Ignoring unrecognized or unparsable cipher suite: " << *it;
59 << *it;
60 continue; 60 continue;
61 } 61 }
62 cipher_suites.push_back(cipher_suite); 62 cipher_suites.push_back(cipher_suite);
63 } 63 }
64 std::sort(cipher_suites.begin(), cipher_suites.end()); 64 std::sort(cipher_suites.begin(), cipher_suites.end());
65 return cipher_suites; 65 return cipher_suites;
66 } 66 }
67 67
68 // Returns the SSL protocol version (as a uint16) represented by a string. 68 // Returns the SSL protocol version (as a uint16) represented by a string.
69 // Returns 0 if the string is invalid. 69 // Returns 0 if the string is invalid.
(...skipping 12 matching lines...) Expand all
82 } // namespace 82 } // namespace
83 83
84 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
85 // SSLConfigServicePref 85 // SSLConfigServicePref
86 86
87 // An SSLConfigService which stores a cached version of the current SSLConfig 87 // An SSLConfigService which stores a cached version of the current SSLConfig
88 // prefs, which are updated by SSLConfigServiceManagerPref when the prefs 88 // prefs, which are updated by SSLConfigServiceManagerPref when the prefs
89 // change. 89 // change.
90 class SSLConfigServicePref : public net::SSLConfigService { 90 class SSLConfigServicePref : public net::SSLConfigService {
91 public: 91 public:
92 SSLConfigServicePref() {} 92 SSLConfigServicePref(
Ryan Sleevi 2015/09/08 21:02:16 STYLE: Add 'explicit' STYLE: Pass by const-ref.
Abhishek 2015/09/10 13:32:54 Done.
93 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
93 94
94 // Store SSL config settings in |config|. Must only be called from IO thread. 95 // Store SSL config settings in |config|. Must only be called from IO thread.
95 void GetSSLConfig(net::SSLConfig* config) override; 96 void GetSSLConfig(net::SSLConfig* config) override;
96 97
97 private: 98 private:
98 // Allow the pref watcher to update our internal state. 99 // Allow the pref watcher to update our internal state.
99 friend class SSLConfigServiceManagerPref; 100 friend class SSLConfigServiceManagerPref;
100 101
101 ~SSLConfigServicePref() override {} 102 ~SSLConfigServicePref() override {}
102 103
103 // This method is posted to the IO thread from the browser thread to carry the 104 // This method is posted to the IO thread from the browser thread to carry the
104 // new config information. 105 // new config information.
105 void SetNewSSLConfig(const net::SSLConfig& new_config); 106 void SetNewSSLConfig(const net::SSLConfig& new_config);
106 107
107 // Cached value of prefs, should only be accessed from IO thread. 108 // Cached value of prefs, should only be accessed from IO thread.
108 net::SSLConfig cached_config_; 109 net::SSLConfig cached_config_;
109 110
111 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
112
110 DISALLOW_COPY_AND_ASSIGN(SSLConfigServicePref); 113 DISALLOW_COPY_AND_ASSIGN(SSLConfigServicePref);
111 }; 114 };
112 115
116 SSLConfigServicePref::SSLConfigServicePref(
117 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
118 : io_task_runner_(io_task_runner) {}
119
113 void SSLConfigServicePref::GetSSLConfig(net::SSLConfig* config) { 120 void SSLConfigServicePref::GetSSLConfig(net::SSLConfig* config) {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO); 121 DCHECK(io_task_runner_->BelongsToCurrentThread());
115 *config = cached_config_; 122 *config = cached_config_;
116 } 123 }
117 124
118 void SSLConfigServicePref::SetNewSSLConfig( 125 void SSLConfigServicePref::SetNewSSLConfig(const net::SSLConfig& new_config) {
119 const net::SSLConfig& new_config) {
120 net::SSLConfig orig_config = cached_config_; 126 net::SSLConfig orig_config = cached_config_;
121 cached_config_ = new_config; 127 cached_config_ = new_config;
122 ProcessConfigUpdate(orig_config, new_config); 128 ProcessConfigUpdate(orig_config, new_config);
123 } 129 }
124 130
125 //////////////////////////////////////////////////////////////////////////////// 131 ////////////////////////////////////////////////////////////////////////////////
126 // SSLConfigServiceManagerPref 132 // SSLConfigServiceManagerPref
127 133
128 // The manager for holding and updating an SSLConfigServicePref instance. 134 // The manager for holding and updating an SSLConfigServicePref instance.
129 class SSLConfigServiceManagerPref 135 class SSLConfigServiceManagerPref : public ssl_config::SSLConfigServiceManager {
130 : public SSLConfigServiceManager {
131 public: 136 public:
132 explicit SSLConfigServiceManagerPref(PrefService* local_state); 137 explicit SSLConfigServiceManagerPref(
Ryan Sleevi 2015/09/08 21:02:16 STYLE: remove explicit, this is now a two-arg ctor
Abhishek 2015/09/10 13:32:54 Done.
138 PrefService* local_state,
139 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
Ryan Sleevi 2015/09/08 21:02:16 const-ref
Abhishek 2015/09/10 13:32:54 Done.
133 ~SSLConfigServiceManagerPref() override {} 140 ~SSLConfigServiceManagerPref() override {}
134 141
135 // Register local_state SSL preferences. 142 // Register local_state SSL preferences.
136 static void RegisterPrefs(PrefRegistrySimple* registry); 143 static void RegisterPrefs(PrefRegistrySimple* registry);
137 144
138 net::SSLConfigService* Get() override; 145 net::SSLConfigService* Get() override;
139 146
140 private: 147 private:
141 // Callback for preference changes. This will post the changes to the IO 148 // Callback for preference changes. This will post the changes to the IO
142 // thread with SetNewSSLConfig. 149 // thread with SetNewSSLConfig.
143 void OnPreferenceChanged(PrefService* prefs, 150 void OnPreferenceChanged(PrefService* prefs, const std::string& pref_name);
144 const std::string& pref_name);
145 151
146 // Store SSL config settings in |config|, directly from the preferences. Must 152 // Store SSL config settings in |config|, directly from the preferences. Must
147 // only be called from UI thread. 153 // only be called from UI thread.
148 void GetSSLConfigFromPrefs(net::SSLConfig* config); 154 void GetSSLConfigFromPrefs(net::SSLConfig* config);
149 155
150 // Processes changes to the disabled cipher suites preference, updating the 156 // Processes changes to the disabled cipher suites preference, updating the
151 // cached list of parsed SSL/TLS cipher suites that are disabled. 157 // cached list of parsed SSL/TLS cipher suites that are disabled.
152 void OnDisabledCipherSuitesChange(PrefService* local_state); 158 void OnDisabledCipherSuitesChange(PrefService* local_state);
153 159
154 PrefChangeRegistrar local_state_change_registrar_; 160 PrefChangeRegistrar local_state_change_registrar_;
155 161
156 // The local_state prefs (should only be accessed from UI thread) 162 // The local_state prefs (should only be accessed from UI thread)
157 BooleanPrefMember rev_checking_enabled_; 163 BooleanPrefMember rev_checking_enabled_;
158 BooleanPrefMember rev_checking_required_local_anchors_; 164 BooleanPrefMember rev_checking_required_local_anchors_;
159 StringPrefMember ssl_version_min_; 165 StringPrefMember ssl_version_min_;
160 StringPrefMember ssl_version_max_; 166 StringPrefMember ssl_version_max_;
161 StringPrefMember ssl_version_fallback_min_; 167 StringPrefMember ssl_version_fallback_min_;
162 BooleanPrefMember ssl_record_splitting_disabled_; 168 BooleanPrefMember ssl_record_splitting_disabled_;
163 169
164 // The cached list of disabled SSL cipher suites. 170 // The cached list of disabled SSL cipher suites.
165 std::vector<uint16> disabled_cipher_suites_; 171 std::vector<uint16> disabled_cipher_suites_;
166 172
167 scoped_refptr<SSLConfigServicePref> ssl_config_service_; 173 scoped_refptr<SSLConfigServicePref> ssl_config_service_;
168 174
175 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
176
169 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); 177 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref);
170 }; 178 };
171 179
172 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( 180 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref(
173 PrefService* local_state) 181 PrefService* local_state,
174 : ssl_config_service_(new SSLConfigServicePref()) { 182 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
183 : ssl_config_service_(new SSLConfigServicePref(io_task_runner)),
184 io_task_runner_(io_task_runner) {
175 DCHECK(local_state); 185 DCHECK(local_state);
176 186
177 PrefChangeRegistrar::NamedChangeCallback local_state_callback = base::Bind( 187 PrefChangeRegistrar::NamedChangeCallback local_state_callback =
178 &SSLConfigServiceManagerPref::OnPreferenceChanged, 188 base::Bind(&SSLConfigServiceManagerPref::OnPreferenceChanged,
179 base::Unretained(this), 189 base::Unretained(this), local_state);
180 local_state);
181 190
182 rev_checking_enabled_.Init( 191 rev_checking_enabled_.Init(ssl_config::prefs::kCertRevocationCheckingEnabled,
183 prefs::kCertRevocationCheckingEnabled, local_state, local_state_callback); 192 local_state, local_state_callback);
184 rev_checking_required_local_anchors_.Init( 193 rev_checking_required_local_anchors_.Init(
185 prefs::kCertRevocationCheckingRequiredLocalAnchors, 194 ssl_config::prefs::kCertRevocationCheckingRequiredLocalAnchors,
186 local_state, 195 local_state, local_state_callback);
196 ssl_version_min_.Init(ssl_config::prefs::kSSLVersionMin, local_state,
197 local_state_callback);
198 ssl_version_max_.Init(ssl_config::prefs::kSSLVersionMax, local_state,
199 local_state_callback);
200 ssl_version_fallback_min_.Init(ssl_config::prefs::kSSLVersionFallbackMin,
201 local_state, local_state_callback);
202 ssl_record_splitting_disabled_.Init(
203 ssl_config::prefs::kDisableSSLRecordSplitting, local_state,
187 local_state_callback); 204 local_state_callback);
188 ssl_version_min_.Init(
189 prefs::kSSLVersionMin, local_state, local_state_callback);
190 ssl_version_max_.Init(
191 prefs::kSSLVersionMax, local_state, local_state_callback);
192 ssl_version_fallback_min_.Init(
193 prefs::kSSLVersionFallbackMin, local_state, local_state_callback);
194 ssl_record_splitting_disabled_.Init(
195 prefs::kDisableSSLRecordSplitting, local_state, local_state_callback);
196 205
197 local_state_change_registrar_.Init(local_state); 206 local_state_change_registrar_.Init(local_state);
198 local_state_change_registrar_.Add( 207 local_state_change_registrar_.Add(ssl_config::prefs::kCipherSuiteBlacklist,
199 prefs::kCipherSuiteBlacklist, local_state_callback); 208 local_state_callback);
200 209
201 OnDisabledCipherSuitesChange(local_state); 210 OnDisabledCipherSuitesChange(local_state);
202 211
203 // Initialize from UI thread. This is okay as there shouldn't be anything on 212 // Initialize from UI thread. This is okay as there shouldn't be anything on
204 // the IO thread trying to access it yet. 213 // the IO thread trying to access it yet.
205 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); 214 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_);
206 } 215 }
207 216
208 // static 217 // static
209 void SSLConfigServiceManagerPref::RegisterPrefs(PrefRegistrySimple* registry) { 218 void SSLConfigServiceManagerPref::RegisterPrefs(PrefRegistrySimple* registry) {
210 net::SSLConfig default_config; 219 net::SSLConfig default_config;
211 registry->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled,
212 default_config.rev_checking_enabled);
213 registry->RegisterBooleanPref( 220 registry->RegisterBooleanPref(
214 prefs::kCertRevocationCheckingRequiredLocalAnchors, 221 ssl_config::prefs::kCertRevocationCheckingEnabled,
222 default_config.rev_checking_enabled);
223 registry->RegisterBooleanPref(
224 ssl_config::prefs::kCertRevocationCheckingRequiredLocalAnchors,
215 default_config.rev_checking_required_local_anchors); 225 default_config.rev_checking_required_local_anchors);
216 registry->RegisterStringPref(prefs::kSSLVersionMin, std::string()); 226 registry->RegisterStringPref(ssl_config::prefs::kSSLVersionMin,
217 registry->RegisterStringPref(prefs::kSSLVersionMax, std::string()); 227 std::string());
218 registry->RegisterStringPref(prefs::kSSLVersionFallbackMin, std::string()); 228 registry->RegisterStringPref(ssl_config::prefs::kSSLVersionMax,
219 registry->RegisterBooleanPref(prefs::kDisableSSLRecordSplitting, 229 std::string());
230 registry->RegisterStringPref(ssl_config::prefs::kSSLVersionFallbackMin,
231 std::string());
232 registry->RegisterBooleanPref(ssl_config::prefs::kDisableSSLRecordSplitting,
220 !default_config.false_start_enabled); 233 !default_config.false_start_enabled);
221 registry->RegisterListPref(prefs::kCipherSuiteBlacklist); 234 registry->RegisterListPref(ssl_config::prefs::kCipherSuiteBlacklist);
222 } 235 }
223 236
224 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { 237 net::SSLConfigService* SSLConfigServiceManagerPref::Get() {
225 return ssl_config_service_.get(); 238 return ssl_config_service_.get();
226 } 239 }
227 240
228 void SSLConfigServiceManagerPref::OnPreferenceChanged( 241 void SSLConfigServiceManagerPref::OnPreferenceChanged(
229 PrefService* prefs, 242 PrefService* prefs,
230 const std::string& pref_name_in) { 243 const std::string& pref_name_in) {
231 DCHECK_CURRENTLY_ON(BrowserThread::UI);
232 DCHECK(prefs); 244 DCHECK(prefs);
233 if (pref_name_in == prefs::kCipherSuiteBlacklist) 245 if (pref_name_in == ssl_config::prefs::kCipherSuiteBlacklist)
234 OnDisabledCipherSuitesChange(prefs); 246 OnDisabledCipherSuitesChange(prefs);
235 247
236 net::SSLConfig new_config; 248 net::SSLConfig new_config;
237 GetSSLConfigFromPrefs(&new_config); 249 GetSSLConfigFromPrefs(&new_config);
238 250
239 // Post a task to |io_loop| with the new configuration, so it can 251 // Post a task to |io_loop| with the new configuration, so it can
240 // update |cached_config_|. 252 // update |cached_config_|.
241 BrowserThread::PostTask( 253 io_task_runner_->PostTask(FROM_HERE,
242 BrowserThread::IO, 254 base::Bind(&SSLConfigServicePref::SetNewSSLConfig,
243 FROM_HERE, 255 ssl_config_service_.get(), new_config));
244 base::Bind(
245 &SSLConfigServicePref::SetNewSSLConfig,
246 ssl_config_service_.get(),
247 new_config));
248 } 256 }
249 257
250 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( 258 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs(
251 net::SSLConfig* config) { 259 net::SSLConfig* config) {
252 // rev_checking_enabled was formerly a user-settable preference, but now 260 // rev_checking_enabled was formerly a user-settable preference, but now
253 // it is managed-only. 261 // it is managed-only.
254 if (rev_checking_enabled_.IsManaged()) 262 if (rev_checking_enabled_.IsManaged())
255 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); 263 config->rev_checking_enabled = rev_checking_enabled_.GetValue();
256 else 264 else
257 config->rev_checking_enabled = false; 265 config->rev_checking_enabled = false;
(...skipping 20 matching lines...) Expand all
278 config->version_fallback_min = version_fallback_min; 286 config->version_fallback_min = version_fallback_min;
279 } 287 }
280 config->disabled_cipher_suites = disabled_cipher_suites_; 288 config->disabled_cipher_suites = disabled_cipher_suites_;
281 // disabling False Start also happens to disable record splitting. 289 // disabling False Start also happens to disable record splitting.
282 config->false_start_enabled = !ssl_record_splitting_disabled_.GetValue(); 290 config->false_start_enabled = !ssl_record_splitting_disabled_.GetValue();
283 } 291 }
284 292
285 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( 293 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange(
286 PrefService* local_state) { 294 PrefService* local_state) {
287 const base::ListValue* value = 295 const base::ListValue* value =
288 local_state->GetList(prefs::kCipherSuiteBlacklist); 296 local_state->GetList(ssl_config::prefs::kCipherSuiteBlacklist);
289 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value)); 297 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value));
290 } 298 }
291 299
292 //////////////////////////////////////////////////////////////////////////////// 300 ////////////////////////////////////////////////////////////////////////////////
293 // SSLConfigServiceManager 301 // SSLConfigServiceManager
294 302
303 namespace ssl_config {
295 // static 304 // static
296 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( 305 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager(
297 PrefService* local_state) { 306 PrefService* local_state,
298 return new SSLConfigServiceManagerPref(local_state); 307 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
Ryan Sleevi 2015/09/08 21:02:16 const-ref
Abhishek 2015/09/10 13:32:54 Done.
308 return new SSLConfigServiceManagerPref(local_state, io_task_runner);
299 } 309 }
300 310
301 // static 311 // static
302 void SSLConfigServiceManager::RegisterPrefs(PrefRegistrySimple* registry) { 312 void SSLConfigServiceManager::RegisterPrefs(PrefRegistrySimple* registry) {
303 SSLConfigServiceManagerPref::RegisterPrefs(registry); 313 SSLConfigServiceManagerPref::RegisterPrefs(registry);
304 } 314 }
315 } // namespace ssl_config
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698