OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | |
13 #include "chrome/browser/prefs/pref_change_registrar.h" | 12 #include "chrome/browser/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/prefs/pref_member.h" | 13 #include "chrome/browser/prefs/pref_member.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | |
18 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
22 #include "net/base/ssl_cipher_suite_names.h" | 20 #include "net/base/ssl_cipher_suite_names.h" |
23 #include "net/base/ssl_config_service.h" | 21 #include "net/base/ssl_config_service.h" |
24 | 22 |
25 namespace { | 23 namespace { |
26 | 24 |
27 // Converts a ListValue of StringValues into a vector of strings. Any Values | 25 // Converts a ListValue of StringValues into a vector of strings. Any Values |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void GetSSLConfigFromPrefs(net::SSLConfig* config); | 129 void GetSSLConfigFromPrefs(net::SSLConfig* config); |
132 | 130 |
133 // Processes changes to the disabled cipher suites preference, updating the | 131 // Processes changes to the disabled cipher suites preference, updating the |
134 // cached list of parsed SSL/TLS cipher suites that are disabled. | 132 // cached list of parsed SSL/TLS cipher suites that are disabled. |
135 void OnDisabledCipherSuitesChange(PrefService* prefs); | 133 void OnDisabledCipherSuitesChange(PrefService* prefs); |
136 | 134 |
137 PrefChangeRegistrar pref_change_registrar_; | 135 PrefChangeRegistrar pref_change_registrar_; |
138 | 136 |
139 // The prefs (should only be accessed from UI thread) | 137 // The prefs (should only be accessed from UI thread) |
140 BooleanPrefMember rev_checking_enabled_; | 138 BooleanPrefMember rev_checking_enabled_; |
| 139 BooleanPrefMember ssl3_enabled_; |
| 140 BooleanPrefMember tls1_enabled_; |
141 | 141 |
142 // The cached list of disabled SSL cipher suites. | 142 // The cached list of disabled SSL cipher suites. |
143 std::vector<uint16> disabled_cipher_suites_; | 143 std::vector<uint16> disabled_cipher_suites_; |
144 | 144 |
145 scoped_refptr<SSLConfigServicePref> ssl_config_service_; | 145 scoped_refptr<SSLConfigServicePref> ssl_config_service_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); | 147 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); |
148 }; | 148 }; |
149 | 149 |
150 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( | 150 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( |
151 PrefService* local_state) | 151 PrefService* local_state) |
152 : ssl_config_service_(new SSLConfigServicePref()) { | 152 : ssl_config_service_(new SSLConfigServicePref()) { |
153 DCHECK(local_state); | 153 DCHECK(local_state); |
154 | 154 |
155 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, | 155 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, |
156 local_state, this); | 156 local_state, this); |
| 157 ssl3_enabled_.Init(prefs::kSSL3Enabled, local_state, this); |
| 158 tls1_enabled_.Init(prefs::kTLS1Enabled, local_state, this); |
157 pref_change_registrar_.Init(local_state); | 159 pref_change_registrar_.Init(local_state); |
158 pref_change_registrar_.Add(prefs::kCipherSuiteBlacklist, this); | 160 pref_change_registrar_.Add(prefs::kCipherSuiteBlacklist, this); |
159 | 161 |
160 OnDisabledCipherSuitesChange(local_state); | 162 OnDisabledCipherSuitesChange(local_state); |
161 // Initialize from UI thread. This is okay as there shouldn't be anything on | 163 // Initialize from UI thread. This is okay as there shouldn't be anything on |
162 // the IO thread trying to access it yet. | 164 // the IO thread trying to access it yet. |
163 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); | 165 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); |
164 } | 166 } |
165 | 167 |
166 // static | 168 // static |
167 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* prefs) { | 169 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* prefs) { |
168 net::SSLConfig default_config; | 170 net::SSLConfig default_config; |
169 prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled, | 171 prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled, |
170 default_config.rev_checking_enabled); | 172 default_config.rev_checking_enabled); |
| 173 prefs->RegisterBooleanPref(prefs::kSSL3Enabled, |
| 174 default_config.ssl3_enabled); |
| 175 prefs->RegisterBooleanPref(prefs::kTLS1Enabled, |
| 176 default_config.tls1_enabled); |
171 prefs->RegisterListPref(prefs::kCipherSuiteBlacklist); | 177 prefs->RegisterListPref(prefs::kCipherSuiteBlacklist); |
| 178 // The Options menu used to allow changing the ssl.ssl3.enabled and |
| 179 // ssl.tls1.enabled preferences, so some users' Local State may have |
| 180 // these preferences. Remove them from Local State. |
| 181 prefs->ClearPref(prefs::kSSL3Enabled); |
| 182 prefs->ClearPref(prefs::kTLS1Enabled); |
172 } | 183 } |
173 | 184 |
174 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { | 185 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { |
175 return ssl_config_service_; | 186 return ssl_config_service_; |
176 } | 187 } |
177 | 188 |
178 void SSLConfigServiceManagerPref::Observe( | 189 void SSLConfigServiceManagerPref::Observe( |
179 int type, | 190 int type, |
180 const content::NotificationSource& source, | 191 const content::NotificationSource& source, |
181 const content::NotificationDetails& details) { | 192 const content::NotificationDetails& details) { |
(...skipping 16 matching lines...) Expand all Loading... |
198 base::Bind( | 209 base::Bind( |
199 &SSLConfigServicePref::SetNewSSLConfig, | 210 &SSLConfigServicePref::SetNewSSLConfig, |
200 ssl_config_service_.get(), | 211 ssl_config_service_.get(), |
201 new_config)); | 212 new_config)); |
202 } | 213 } |
203 } | 214 } |
204 | 215 |
205 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( | 216 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( |
206 net::SSLConfig* config) { | 217 net::SSLConfig* config) { |
207 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); | 218 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); |
208 | 219 config->ssl3_enabled = ssl3_enabled_.GetValue(); |
209 config->ssl3_enabled = | 220 config->tls1_enabled = tls1_enabled_.GetValue(); |
210 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSSL3); | |
211 config->tls1_enabled = | |
212 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTLS1); | |
213 | |
214 config->disabled_cipher_suites = disabled_cipher_suites_; | 221 config->disabled_cipher_suites = disabled_cipher_suites_; |
215 SSLConfigServicePref::SetSSLConfigFlags(config); | 222 SSLConfigServicePref::SetSSLConfigFlags(config); |
216 } | 223 } |
217 | 224 |
218 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( | 225 void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( |
219 PrefService* prefs) { | 226 PrefService* prefs) { |
220 const ListValue* value = prefs->GetList(prefs::kCipherSuiteBlacklist); | 227 const ListValue* value = prefs->GetList(prefs::kCipherSuiteBlacklist); |
221 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value)); | 228 disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value)); |
222 } | 229 } |
223 | 230 |
224 //////////////////////////////////////////////////////////////////////////////// | 231 //////////////////////////////////////////////////////////////////////////////// |
225 // SSLConfigServiceManager | 232 // SSLConfigServiceManager |
226 | 233 |
227 // static | 234 // static |
228 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( | 235 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( |
229 PrefService* local_state) { | 236 PrefService* local_state) { |
230 return new SSLConfigServiceManagerPref(local_state); | 237 return new SSLConfigServiceManagerPref(local_state); |
231 } | 238 } |
232 | 239 |
233 // static | 240 // static |
234 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) { | 241 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) { |
235 SSLConfigServiceManagerPref::RegisterPrefs(prefs); | 242 SSLConfigServiceManagerPref::RegisterPrefs(prefs); |
236 } | 243 } |
OLD | NEW |