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])); | |
140 } | |
Ryan Hamilton
2014/12/10 21:11:41
nit: net style says to not use {}s on 1 line if st
Bence
2014/12/11 16:50:49
This is formatted by git cl format, which does not
| |
138 } | 141 } |
139 } | 142 } |
140 | 143 |
141 // Enable SSL. | 144 // Enable SSL. |
142 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); | 145 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); |
143 | 146 |
144 // Calculate the order of ciphers that we'll use for NSS sockets. (Note | 147 // 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 | 148 // that, even if a cipher is specified in the ordering, it must still be |
146 // enabled in order to be included in a ClientHello.) | 149 // enabled in order to be included in a ClientHello.) |
147 // | 150 // |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 return model_fd_; | 201 return model_fd_; |
199 } | 202 } |
200 | 203 |
201 ~NSSSSLInitSingleton() { | 204 ~NSSSSLInitSingleton() { |
202 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. | 205 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. |
203 SSL_ClearSessionCache(); | 206 SSL_ClearSessionCache(); |
204 if (model_fd_) | 207 if (model_fd_) |
205 PR_Close(model_fd_); | 208 PR_Close(model_fd_); |
206 } | 209 } |
207 | 210 |
211 std::vector<uint16> enabled_cipher_suites_; | |
212 | |
208 private: | 213 private: |
209 PRFileDesc* model_fd_; | 214 PRFileDesc* model_fd_; |
210 }; | 215 }; |
211 | 216 |
212 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton = | 217 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton = |
213 LAZY_INSTANCE_INITIALIZER; | 218 LAZY_INSTANCE_INITIALIZER; |
214 | 219 |
215 } // anonymous namespace | 220 } // anonymous namespace |
216 | 221 |
217 // Initialize the NSS SSL library if it isn't already initialized. This must | 222 // 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 | 223 // 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. | 224 // 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. | 225 // The NSS SSL library will be properly shut down on program exit. |
221 void EnsureNSSSSLInit() { | 226 void EnsureNSSSSLInit() { |
222 // Initializing SSL causes us to do blocking IO. | 227 // Initializing SSL causes us to do blocking IO. |
223 // Temporarily allow it until we fix | 228 // Temporarily allow it until we fix |
224 // http://code.google.com/p/chromium/issues/detail?id=59847 | 229 // http://code.google.com/p/chromium/issues/detail?id=59847 |
225 base::ThreadRestrictions::ScopedAllowIO allow_io; | 230 base::ThreadRestrictions::ScopedAllowIO allow_io; |
226 | 231 |
227 g_nss_ssl_init_singleton.Get(); | 232 g_nss_ssl_init_singleton.Get(); |
228 } | 233 } |
229 | 234 |
230 PRFileDesc* GetNSSModelSocket() { | 235 PRFileDesc* GetNSSModelSocket() { |
231 return g_nss_ssl_init_singleton.Get().GetModelSocket(); | 236 return g_nss_ssl_init_singleton.Get().GetModelSocket(); |
232 } | 237 } |
233 | 238 |
239 const std::vector<uint16>& GetNSSEnabledCipherSuites() { | |
240 return g_nss_ssl_init_singleton.Get().enabled_cipher_suites_; | |
241 } | |
242 | |
234 // Map a Chromium net error code to an NSS error code. | 243 // Map a Chromium net error code to an NSS error code. |
235 // See _MD_unix_map_default_error in the NSS source | 244 // See _MD_unix_map_default_error in the NSS source |
236 // tree for inspiration. | 245 // tree for inspiration. |
237 PRErrorCode MapErrorToNSS(int result) { | 246 PRErrorCode MapErrorToNSS(int result) { |
238 if (result >=0) | 247 if (result >=0) |
239 return result; | 248 return result; |
240 | 249 |
241 switch (result) { | 250 switch (result) { |
242 case ERR_IO_PENDING: | 251 case ERR_IO_PENDING: |
243 return PR_WOULD_BLOCK_ERROR; | 252 return PR_WOULD_BLOCK_ERROR; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 base::Bind(&NetLogSSLFailedNSSFunctionCallback, | 417 base::Bind(&NetLogSSLFailedNSSFunctionCallback, |
409 function, param, PR_GetError())); | 418 function, param, PR_GetError())); |
410 } | 419 } |
411 | 420 |
412 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error, | 421 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error, |
413 int ssl_lib_error) { | 422 int ssl_lib_error) { |
414 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error); | 423 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error); |
415 } | 424 } |
416 | 425 |
417 } // namespace net | 426 } // namespace net |
OLD | NEW |