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

Side by Side Diff: chrome/browser/net/ssl_config_service_manager_pref.cc

Issue 10917182: Disable TLS channel id if cookies are disabled or third-party cookies are blocked. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes for comment #3 Created 8 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 | Annotate | Revision Log
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 "chrome/browser/net/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 "chrome/browser/api/prefs/pref_change_registrar.h" 12 #include "chrome/browser/api/prefs/pref_change_registrar.h"
13 #include "chrome/browser/api/prefs/pref_member.h" 13 #include "chrome/browser/api/prefs/pref_member.h"
14 #include "chrome/browser/content_settings/content_settings_utils.h"
14 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/content_settings.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
20 #include "net/base/ssl_cipher_suite_names.h" 22 #include "net/base/ssl_cipher_suite_names.h"
21 #include "net/base/ssl_config_service.h" 23 #include "net/base/ssl_config_service.h"
22 24
23 using content::BrowserThread; 25 using content::BrowserThread;
24 26
25 namespace { 27 namespace {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 140 }
139 141
140 //////////////////////////////////////////////////////////////////////////////// 142 ////////////////////////////////////////////////////////////////////////////////
141 // SSLConfigServiceManagerPref 143 // SSLConfigServiceManagerPref
142 144
143 // The manager for holding and updating an SSLConfigServicePref instance. 145 // The manager for holding and updating an SSLConfigServicePref instance.
144 class SSLConfigServiceManagerPref 146 class SSLConfigServiceManagerPref
145 : public SSLConfigServiceManager, 147 : public SSLConfigServiceManager,
146 public content::NotificationObserver { 148 public content::NotificationObserver {
147 public: 149 public:
148 explicit SSLConfigServiceManagerPref(PrefService* local_state); 150 SSLConfigServiceManagerPref(PrefService* local_state,
151 PrefService* user_prefs);
149 virtual ~SSLConfigServiceManagerPref() {} 152 virtual ~SSLConfigServiceManagerPref() {}
150 153
151 // Register local_state SSL preferences. 154 // Register local_state SSL preferences.
152 static void RegisterPrefs(PrefService* prefs); 155 static void RegisterPrefs(PrefService* local_state);
153 156
154 virtual net::SSLConfigService* Get(); 157 virtual net::SSLConfigService* Get();
155 158
156 private: 159 private:
157 // Callback for preference changes. This will post the changes to the IO 160 // Callback for preference changes. This will post the changes to the IO
158 // thread with SetNewSSLConfig. 161 // thread with SetNewSSLConfig.
159 virtual void Observe(int type, 162 virtual void Observe(int type,
160 const content::NotificationSource& source, 163 const content::NotificationSource& source,
161 const content::NotificationDetails& details); 164 const content::NotificationDetails& details);
162 165
163 // Store SSL config settings in |config|, directly from the preferences. Must 166 // Store SSL config settings in |config|, directly from the preferences. Must
164 // only be called from UI thread. 167 // only be called from UI thread.
165 void GetSSLConfigFromPrefs(net::SSLConfig* config); 168 void GetSSLConfigFromPrefs(net::SSLConfig* config);
166 169
167 // Processes changes to the disabled cipher suites preference, updating the 170 // Processes changes to the disabled cipher suites preference, updating the
168 // cached list of parsed SSL/TLS cipher suites that are disabled. 171 // cached list of parsed SSL/TLS cipher suites that are disabled.
169 void OnDisabledCipherSuitesChange(PrefService* prefs); 172 void OnDisabledCipherSuitesChange(PrefService* local_state);
170 173
171 PrefChangeRegistrar pref_change_registrar_; 174 // Processes changes to the default cookie settings.
175 void OnDefaultContentSettingsChange(PrefService* user_prefs);
172 176
173 // The prefs (should only be accessed from UI thread) 177 PrefChangeRegistrar local_state_change_registrar_;
178 PrefChangeRegistrar user_prefs_change_registrar_;
179
180 // The local_state prefs (should only be accessed from UI thread)
174 BooleanPrefMember rev_checking_enabled_; 181 BooleanPrefMember rev_checking_enabled_;
175 StringPrefMember ssl_version_min_; 182 StringPrefMember ssl_version_min_;
176 StringPrefMember ssl_version_max_; 183 StringPrefMember ssl_version_max_;
177 BooleanPrefMember channel_id_enabled_; 184 BooleanPrefMember channel_id_enabled_;
178 BooleanPrefMember ssl_record_splitting_disabled_; 185 BooleanPrefMember ssl_record_splitting_disabled_;
179 186
180 // The cached list of disabled SSL cipher suites. 187 // The cached list of disabled SSL cipher suites.
181 std::vector<uint16> disabled_cipher_suites_; 188 std::vector<uint16> disabled_cipher_suites_;
182 189
190 // The user_prefs prefs (should only be accessed from UI thread).
191 // |have_user_prefs_| will be false if no user_prefs are associated with this
192 // instance.
193 bool have_user_prefs_;
194 BooleanPrefMember block_third_party_cookies_;
195
196 // Cached value of if cookies are disabled by default.
197 bool cookies_disabled_;
198
183 scoped_refptr<SSLConfigServicePref> ssl_config_service_; 199 scoped_refptr<SSLConfigServicePref> ssl_config_service_;
184 200
185 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); 201 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref);
186 }; 202 };
187 203
188 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( 204 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref(
189 PrefService* local_state) 205 PrefService* local_state, PrefService* user_prefs)
190 : ssl_config_service_(new SSLConfigServicePref()) { 206 : have_user_prefs_(!!user_prefs),
207 ssl_config_service_(new SSLConfigServicePref()) {
191 DCHECK(local_state); 208 DCHECK(local_state);
192 209
193 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, 210 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled,
194 local_state, this); 211 local_state, this);
195 ssl_version_min_.Init(prefs::kSSLVersionMin, local_state, this); 212 ssl_version_min_.Init(prefs::kSSLVersionMin, local_state, this);
196 ssl_version_max_.Init(prefs::kSSLVersionMax, local_state, this); 213 ssl_version_max_.Init(prefs::kSSLVersionMax, local_state, this);
197 channel_id_enabled_.Init(prefs::kEnableOriginBoundCerts, local_state, this); 214 channel_id_enabled_.Init(prefs::kEnableOriginBoundCerts, local_state, this);
198 ssl_record_splitting_disabled_.Init(prefs::kDisableSSLRecordSplitting, 215 ssl_record_splitting_disabled_.Init(prefs::kDisableSSLRecordSplitting,
199 local_state, this); 216 local_state, this);
200 pref_change_registrar_.Init(local_state); 217 local_state_change_registrar_.Init(local_state);
201 pref_change_registrar_.Add(prefs::kCipherSuiteBlacklist, this); 218 local_state_change_registrar_.Add(prefs::kCipherSuiteBlacklist, this);
202 219
203 OnDisabledCipherSuitesChange(local_state); 220 OnDisabledCipherSuitesChange(local_state);
221
222 if (user_prefs) {
223 block_third_party_cookies_.Init(prefs::kBlockThirdPartyCookies, user_prefs,
224 this);
225 user_prefs_change_registrar_.Init(user_prefs);
226 user_prefs_change_registrar_.Add(prefs::kDefaultContentSettings, this);
227
228 OnDefaultContentSettingsChange(user_prefs);
229 }
230
204 // Initialize from UI thread. This is okay as there shouldn't be anything on 231 // Initialize from UI thread. This is okay as there shouldn't be anything on
205 // the IO thread trying to access it yet. 232 // the IO thread trying to access it yet.
206 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); 233 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_);
207 } 234 }
208 235
209 // static 236 // static
210 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* prefs) { 237 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* local_state) {
211 net::SSLConfig default_config; 238 net::SSLConfig default_config;
212 prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled, 239 local_state->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled,
213 default_config.rev_checking_enabled); 240 default_config.rev_checking_enabled);
battre 2012/09/12 12:11:31 nit: can you fix the indentation? also below
mattm 2012/09/12 19:07:17 done
214 std::string version_min_str = 241 std::string version_min_str =
215 SSLProtocolVersionToString(default_config.version_min); 242 SSLProtocolVersionToString(default_config.version_min);
216 std::string version_max_str = 243 std::string version_max_str =
217 SSLProtocolVersionToString(default_config.version_max); 244 SSLProtocolVersionToString(default_config.version_max);
218 prefs->RegisterStringPref(prefs::kSSLVersionMin, version_min_str); 245 local_state->RegisterStringPref(prefs::kSSLVersionMin, version_min_str);
219 prefs->RegisterStringPref(prefs::kSSLVersionMax, version_max_str); 246 local_state->RegisterStringPref(prefs::kSSLVersionMax, version_max_str);
220 prefs->RegisterBooleanPref(prefs::kEnableOriginBoundCerts, 247 local_state->RegisterBooleanPref(prefs::kEnableOriginBoundCerts,
221 default_config.channel_id_enabled); 248 default_config.channel_id_enabled);
222 prefs->RegisterBooleanPref(prefs::kDisableSSLRecordSplitting, 249 local_state->RegisterBooleanPref(prefs::kDisableSSLRecordSplitting,
223 !default_config.false_start_enabled); 250 !default_config.false_start_enabled);
224 prefs->RegisterListPref(prefs::kCipherSuiteBlacklist); 251 local_state->RegisterListPref(prefs::kCipherSuiteBlacklist);
225 } 252 }
226 253
227 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { 254 net::SSLConfigService* SSLConfigServiceManagerPref::Get() {
228 return ssl_config_service_; 255 return ssl_config_service_;
229 } 256 }
230 257
231 void SSLConfigServiceManagerPref::Observe( 258 void SSLConfigServiceManagerPref::Observe(
232 int type, 259 int type,
233 const content::NotificationSource& source, 260 const content::NotificationSource& source,
234 const content::NotificationDetails& details) { 261 const content::NotificationDetails& details) {
235 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 262 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
237 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 264 std::string* pref_name_in = content::Details<std::string>(details).ptr();
238 PrefService* prefs = content::Source<PrefService>(source).ptr(); 265 PrefService* prefs = content::Source<PrefService>(source).ptr();
239 DCHECK(pref_name_in && prefs); 266 DCHECK(pref_name_in && prefs);
240 if (*pref_name_in == prefs::kCipherSuiteBlacklist) 267 if (*pref_name_in == prefs::kCipherSuiteBlacklist)
241 OnDisabledCipherSuitesChange(prefs); 268 OnDisabledCipherSuitesChange(prefs);
269 else if (*pref_name_in == prefs::kDefaultContentSettings)
270 OnDefaultContentSettingsChange(prefs);
242 271
243 net::SSLConfig new_config; 272 net::SSLConfig new_config;
244 GetSSLConfigFromPrefs(&new_config); 273 GetSSLConfigFromPrefs(&new_config);
245 274
246 // Post a task to |io_loop| with the new configuration, so it can 275 // Post a task to |io_loop| with the new configuration, so it can
247 // update |cached_config_|. 276 // update |cached_config_|.
248 BrowserThread::PostTask( 277 BrowserThread::PostTask(
249 BrowserThread::IO, 278 BrowserThread::IO,
250 FROM_HERE, 279 FROM_HERE,
251 base::Bind( 280 base::Bind(
(...skipping 21 matching lines...) Expand all
273 config->version_min = std::max(supported_version_min, version_min); 302 config->version_min = std::max(supported_version_min, version_min);
274 } 303 }
275 if (version_max) { 304 if (version_max) {
276 // TODO(wtc): get the maximum SSL protocol version supported by the 305 // TODO(wtc): get the maximum SSL protocol version supported by the
277 // SSLClientSocket class. 306 // SSLClientSocket class.
278 uint16 supported_version_max = config->version_max; 307 uint16 supported_version_max = config->version_max;
279 config->version_max = std::min(supported_version_max, version_max); 308 config->version_max = std::min(supported_version_max, version_max);
280 } 309 }
281 config->disabled_cipher_suites = disabled_cipher_suites_; 310 config->disabled_cipher_suites = disabled_cipher_suites_;
282 config->channel_id_enabled = channel_id_enabled_.GetValue(); 311 config->channel_id_enabled = channel_id_enabled_.GetValue();
312 if (have_user_prefs_ &&
313 (cookies_disabled_ || block_third_party_cookies_.GetValue()))
314 config->channel_id_enabled = false;
283 // disabling False Start also happens to disable record splitting. 315 // disabling False Start also happens to disable record splitting.
284 config->false_start_enabled = !ssl_record_splitting_disabled_.GetValue(); 316 config->false_start_enabled = !ssl_record_splitting_disabled_.GetValue();
285 SSLConfigServicePref::SetSSLConfigFlags(config); 317 SSLConfigServicePref::SetSSLConfigFlags(config);
286 } 318 }
287 319
288 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( 320 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange(
289 PrefService* prefs) { 321 PrefService* local_state) {
290 const ListValue* value = prefs->GetList(prefs::kCipherSuiteBlacklist); 322 const ListValue* value = local_state->GetList(prefs::kCipherSuiteBlacklist);
291 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value)); 323 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value));
292 } 324 }
293 325
326 void SSLConfigServiceManagerPref::OnDefaultContentSettingsChange(
327 PrefService* user_prefs) {
328 const DictionaryValue* value = user_prefs->GetDictionary(
329 prefs::kDefaultContentSettings);
330 int default_cookie_settings = -1;
331 cookies_disabled_ = (
332 value &&
333 value->GetInteger(
334 content_settings::GetTypeName(CONTENT_SETTINGS_TYPE_COOKIES),
335 &default_cookie_settings) &&
336 default_cookie_settings == CONTENT_SETTING_BLOCK);
337 }
338
294 //////////////////////////////////////////////////////////////////////////////// 339 ////////////////////////////////////////////////////////////////////////////////
295 // SSLConfigServiceManager 340 // SSLConfigServiceManager
296 341
297 // static 342 // static
298 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( 343 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager(
299 PrefService* local_state) { 344 PrefService* local_state, PrefService* user_prefs) {
300 return new SSLConfigServiceManagerPref(local_state); 345 return new SSLConfigServiceManagerPref(local_state, user_prefs);
301 } 346 }
302 347
303 // static 348 // static
304 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) { 349 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) {
305 SSLConfigServiceManagerPref::RegisterPrefs(prefs); 350 SSLConfigServiceManagerPref::RegisterPrefs(prefs);
306 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698