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

Side by Side Diff: net/socket/nss_ssl_util.cc

Issue 757033004: Do not use HTTP/2 without adequate security. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lint. Created 6 years 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 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
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 default_enabled_cipher_suites_.push_back(
140 static_cast<uint16>(ssl_ciphers[i]));
141 }
138 } 142 }
139 } 143 }
140 144
141 // Enable SSL. 145 // Enable SSL.
142 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); 146 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE);
143 147
144 // Calculate the order of ciphers that we'll use for NSS sockets. (Note 148 // 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 149 // that, even if a cipher is specified in the ordering, it must still be
146 // enabled in order to be included in a ClientHello.) 150 // enabled in order to be included in a ClientHello.)
147 // 151 //
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return model_fd_; 202 return model_fd_;
199 } 203 }
200 204
201 ~NSSSSLInitSingleton() { 205 ~NSSSSLInitSingleton() {
202 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. 206 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY.
203 SSL_ClearSessionCache(); 207 SSL_ClearSessionCache();
204 if (model_fd_) 208 if (model_fd_)
205 PR_Close(model_fd_); 209 PR_Close(model_fd_);
206 } 210 }
207 211
212 std::vector<uint16> default_enabled_cipher_suites_;
213
208 private: 214 private:
209 PRFileDesc* model_fd_; 215 PRFileDesc* model_fd_;
210 }; 216 };
211 217
212 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton = 218 base::LazyInstance<NSSSSLInitSingleton>::Leaky g_nss_ssl_init_singleton =
213 LAZY_INSTANCE_INITIALIZER; 219 LAZY_INSTANCE_INITIALIZER;
214 220
215 } // anonymous namespace 221 } // anonymous namespace
216 222
217 // Initialize the NSS SSL library if it isn't already initialized. This must 223 // 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 224 // 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. 225 // 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. 226 // The NSS SSL library will be properly shut down on program exit.
221 void EnsureNSSSSLInit() { 227 void EnsureNSSSSLInit() {
222 // Initializing SSL causes us to do blocking IO. 228 // Initializing SSL causes us to do blocking IO.
223 // Temporarily allow it until we fix 229 // Temporarily allow it until we fix
224 // http://code.google.com/p/chromium/issues/detail?id=59847 230 // http://code.google.com/p/chromium/issues/detail?id=59847
225 base::ThreadRestrictions::ScopedAllowIO allow_io; 231 base::ThreadRestrictions::ScopedAllowIO allow_io;
226 232
227 g_nss_ssl_init_singleton.Get(); 233 g_nss_ssl_init_singleton.Get();
228 } 234 }
229 235
230 PRFileDesc* GetNSSModelSocket() { 236 PRFileDesc* GetNSSModelSocket() {
231 return g_nss_ssl_init_singleton.Get().GetModelSocket(); 237 return g_nss_ssl_init_singleton.Get().GetModelSocket();
232 } 238 }
233 239
240 const std::vector<uint16>& GetNSSDefaultEnabledCipherSuites() {
241 return g_nss_ssl_init_singleton.Get().default_enabled_cipher_suites_;
242 }
243
234 // Map a Chromium net error code to an NSS error code. 244 // Map a Chromium net error code to an NSS error code.
235 // See _MD_unix_map_default_error in the NSS source 245 // See _MD_unix_map_default_error in the NSS source
236 // tree for inspiration. 246 // tree for inspiration.
237 PRErrorCode MapErrorToNSS(int result) { 247 PRErrorCode MapErrorToNSS(int result) {
238 if (result >=0) 248 if (result >=0)
239 return result; 249 return result;
240 250
241 switch (result) { 251 switch (result) {
242 case ERR_IO_PENDING: 252 case ERR_IO_PENDING:
243 return PR_WOULD_BLOCK_ERROR; 253 return PR_WOULD_BLOCK_ERROR;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 base::Bind(&NetLogSSLFailedNSSFunctionCallback, 418 base::Bind(&NetLogSSLFailedNSSFunctionCallback,
409 function, param, PR_GetError())); 419 function, param, PR_GetError()));
410 } 420 }
411 421
412 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error, 422 NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error,
413 int ssl_lib_error) { 423 int ssl_lib_error) {
414 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error); 424 return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error);
415 } 425 }
416 426
417 } // namespace net 427 } // namespace net
OLDNEW
« net/net.gypi ('K') | « net/socket/nss_ssl_util.h ('k') | net/socket/ssl_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698