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 | 4 |
5 #include "net/socket/nss_ssl_util.h" | 5 #include "net/socket/nss_ssl_util.h" |
6 | 6 |
7 #include <nss.h> | 7 #include <nss.h> |
8 #include <secerr.h> | 8 #include <secerr.h> |
9 #include <ssl.h> | 9 #include <ssl.h> |
10 #include <sslerr.h> | 10 #include <sslerr.h> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 info.nonStandard || | 128 info.nonStandard || |
129 strcmp(info.keaTypeName, "ECDH") == 0) { | 129 strcmp(info.keaTypeName, "ECDH") == 0) { |
130 enabled = false; | 130 enabled = false; |
131 } | 131 } |
132 | 132 |
133 if (ssl_ciphers[i] == TLS_DHE_DSS_WITH_AES_128_CBC_SHA) { | 133 if (ssl_ciphers[i] == TLS_DHE_DSS_WITH_AES_128_CBC_SHA) { |
134 // Enabled to allow servers with only a DSA certificate to function. | 134 // Enabled to allow servers with only a DSA certificate to function. |
135 enabled = true; | 135 enabled = true; |
136 } | 136 } |
137 SSL_CipherPrefSetDefault(ssl_ciphers[i], enabled); | 137 SSL_CipherPrefSetDefault(ssl_ciphers[i], enabled); |
| 138 if (enabled) |
| 139 enabled_cipher_suites_.push_back(static_cast<uint16>(ssl_ciphers[i])); |
138 } | 140 } |
139 } | 141 } |
140 | 142 |
141 // Enable SSL. | 143 // Enable SSL. |
142 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); | 144 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); |
143 | 145 |
144 // Calculate the order of ciphers that we'll use for NSS sockets. (Note | 146 // Calculate the order of ciphers that we'll use for NSS sockets. (Note |
145 // that, even if a cipher is specified in the ordering, it must still be | 147 // that, even if a cipher is specified in the ordering, it must still be |
146 // enabled in order to be included in a ClientHello.) | 148 // enabled in order to be included in a ClientHello.) |
147 // | 149 // |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return model_fd_; | 200 return model_fd_; |
199 } | 201 } |
200 | 202 |
201 ~NSSSSLInitSingleton() { | 203 ~NSSSSLInitSingleton() { |
202 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. | 204 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. |
203 SSL_ClearSessionCache(); | 205 SSL_ClearSessionCache(); |
204 if (model_fd_) | 206 if (model_fd_) |
205 PR_Close(model_fd_); | 207 PR_Close(model_fd_); |
206 } | 208 } |
207 | 209 |
| 210 std::vector<uint16> enabled_cipher_suites_; |
| 211 |
208 private: | 212 private: |
209 PRFileDesc* model_fd_; | 213 PRFileDesc* model_fd_; |
210 }; | 214 }; |
211 | 215 |
212 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton = | 216 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton = |
213 LAZY_INSTANCE_INITIALIZER; | 217 LAZY_INSTANCE_INITIALIZER; |
214 | 218 |
215 } // anonymous namespace | 219 } // anonymous namespace |
216 | 220 |
217 // Initialize the NSS SSL library if it isn't already initialized. This must | 221 // Initialize the NSS SSL library if it isn't already initialized. This must |
218 // be called before any other NSS SSL functions. This function is | 222 // be called before any other NSS SSL functions. This function is |
219 // thread-safe, and the NSS SSL library will only ever be initialized once. | 223 // thread-safe, and the NSS SSL library will only ever be initialized once. |
220 // The NSS SSL library will be properly shut down on program exit. | 224 // The NSS SSL library will be properly shut down on program exit. |
221 void EnsureNSSSSLInit() { | 225 void EnsureNSSSSLInit() { |
222 // Initializing SSL causes us to do blocking IO. | 226 // Initializing SSL causes us to do blocking IO. |
223 // Temporarily allow it until we fix | 227 // Temporarily allow it until we fix |
224 // http://code.google.com/p/chromium/issues/detail?id=59847 | 228 // http://code.google.com/p/chromium/issues/detail?id=59847 |
225 base::ThreadRestrictions::ScopedAllowIO allow_io; | 229 base::ThreadRestrictions::ScopedAllowIO allow_io; |
226 | 230 |
227 g_nss_ssl_init_singleton.Get(); | 231 g_nss_ssl_init_singleton.Get(); |
228 } | 232 } |
229 | 233 |
230 PRFileDesc* GetNSSModelSocket() { | 234 PRFileDesc* GetNSSModelSocket() { |
231 return g_nss_ssl_init_singleton.Get().GetModelSocket(); | 235 return g_nss_ssl_init_singleton.Get().GetModelSocket(); |
232 } | 236 } |
233 | 237 |
| 238 const std::vector<uint16>& GetNSSEnabledCipherSuites() { |
| 239 return g_nss_ssl_init_singleton.Get().enabled_cipher_suites_; |
| 240 } |
| 241 |
234 // Map a Chromium net error code to an NSS error code. | 242 // Map a Chromium net error code to an NSS error code. |
235 // See _MD_unix_map_default_error in the NSS source | 243 // See _MD_unix_map_default_error in the NSS source |
236 // tree for inspiration. | 244 // tree for inspiration. |
237 PRErrorCode MapErrorToNSS(int result) { | 245 PRErrorCode MapErrorToNSS(int result) { |
238 if (result >=0) | 246 if (result >=0) |
239 return result; | 247 return result; |
240 | 248 |
241 switch (result) { | 249 switch (result) { |
242 case ERR_IO_PENDING: | 250 case ERR_IO_PENDING: |
243 return PR_WOULD_BLOCK_ERROR; | 251 return PR_WOULD_BLOCK_ERROR; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 base::Bind(&NetLogSSLFailedNSSFunctionCallback, | 416 base::Bind(&NetLogSSLFailedNSSFunctionCallback, |
409 function, param, PR_GetError())); | 417 function, param, PR_GetError())); |
410 } | 418 } |
411 | 419 |
412 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error, | 420 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error, |
413 int ssl_lib_error) { | 421 int ssl_lib_error) { |
414 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error); | 422 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error); |
415 } | 423 } |
416 | 424 |
417 } // namespace net | 425 } // namespace net |
OLD | NEW |