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 #include "net/socket/nss_ssl_util_internal.h" |
6 | 7 |
7 #include <nss.h> | 8 #include <nss.h> |
8 #include <secerr.h> | 9 #include <secerr.h> |
9 #include <ssl.h> | 10 #include <ssl.h> |
10 #include <sslerr.h> | 11 #include <sslerr.h> |
11 | 12 |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "crypto/nss_util.h" | 20 #include "crypto/nss_util.h" |
20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
21 #include "net/base/net_log.h" | 22 #include "net/base/net_log.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
| 26 namespace { |
| 27 |
25 class NSSSSLInitSingleton { | 28 class NSSSSLInitSingleton { |
26 public: | 29 public: |
27 NSSSSLInitSingleton() { | 30 NSSSSLInitSingleton() { |
28 crypto::EnsureNSSInit(); | 31 crypto::EnsureNSSInit(); |
29 | 32 |
30 NSS_SetDomesticPolicy(); | 33 NSS_SetDomesticPolicy(); |
31 | 34 |
32 #if defined(USE_SYSTEM_SSL) | 35 #if defined(USE_SYSTEM_SSL) |
33 // Use late binding to avoid scary but benign warning | 36 // Use late binding to avoid scary but benign warning |
34 // "Symbol `SSL_ImplementedCiphers' has different size in shared object, | 37 // "Symbol `SSL_ImplementedCiphers' has different size in shared object, |
(...skipping 27 matching lines...) Expand all Loading... |
62 // All other SSL options are set per-session by SSLClientSocket and | 65 // All other SSL options are set per-session by SSLClientSocket and |
63 // SSLServerSocket. | 66 // SSLServerSocket. |
64 } | 67 } |
65 | 68 |
66 ~NSSSSLInitSingleton() { | 69 ~NSSSSLInitSingleton() { |
67 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. | 70 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. |
68 SSL_ClearSessionCache(); | 71 SSL_ClearSessionCache(); |
69 } | 72 } |
70 }; | 73 }; |
71 | 74 |
| 75 class NSSSSLServerInitSingleton { |
| 76 public: |
| 77 NSSSSLServerInitSingleton() { |
| 78 EnsureNSSSSLInit(); |
| 79 |
| 80 SSL_ConfigServerSessionIDCache(1024, 5, 5, NULL); |
| 81 } |
| 82 |
| 83 ~NSSSSLServerInitSingleton() { |
| 84 SSL_ShutdownServerSessionIDCache(); |
| 85 } |
| 86 }; |
| 87 |
72 static base::LazyInstance<NSSSSLInitSingleton> g_nss_ssl_init_singleton = | 88 static base::LazyInstance<NSSSSLInitSingleton> g_nss_ssl_init_singleton = |
73 LAZY_INSTANCE_INITIALIZER; | 89 LAZY_INSTANCE_INITIALIZER; |
74 | 90 |
| 91 static base::LazyInstance<NSSSSLServerInitSingleton> |
| 92 g_nss_ssl_server_init_singleton = LAZY_INSTANCE_INITIALIZER; |
| 93 |
| 94 } // namespace |
| 95 |
75 // Initialize the NSS SSL library if it isn't already initialized. This must | 96 // Initialize the NSS SSL library if it isn't already initialized. This must |
76 // be called before any other NSS SSL functions. This function is | 97 // be called before any other NSS SSL functions. This function is |
77 // thread-safe, and the NSS SSL library will only ever be initialized once. | 98 // thread-safe, and the NSS SSL library will only ever be initialized once. |
78 // The NSS SSL library will be properly shut down on program exit. | 99 // The NSS SSL library will be properly shut down on program exit. |
79 void EnsureNSSSSLInit() { | 100 void EnsureNSSSSLInit() { |
80 // Initializing SSL causes us to do blocking IO. | 101 // Initializing SSL causes us to do blocking IO. |
81 // Temporarily allow it until we fix | 102 // Temporarily allow it until we fix |
82 // http://code.google.com/p/chromium/issues/detail?id=59847 | 103 // http://code.google.com/p/chromium/issues/detail?id=59847 |
83 base::ThreadRestrictions::ScopedAllowIO allow_io; | 104 base::ThreadRestrictions::ScopedAllowIO allow_io; |
84 | 105 |
85 g_nss_ssl_init_singleton.Get(); | 106 g_nss_ssl_init_singleton.Get(); |
86 } | 107 } |
87 | 108 |
| 109 void EnsureNSSSSLServerInit() { |
| 110 g_nss_ssl_server_init_singleton.Get(); |
| 111 } |
| 112 |
88 // Map a Chromium net error code to an NSS error code. | 113 // Map a Chromium net error code to an NSS error code. |
89 // See _MD_unix_map_default_error in the NSS source | 114 // See _MD_unix_map_default_error in the NSS source |
90 // tree for inspiration. | 115 // tree for inspiration. |
91 PRErrorCode MapErrorToNSS(int result) { | 116 PRErrorCode MapErrorToNSS(int result) { |
92 if (result >=0) | 117 if (result >=0) |
93 return result; | 118 return result; |
94 | 119 |
95 switch (result) { | 120 switch (result) { |
96 case ERR_IO_PENDING: | 121 case ERR_IO_PENDING: |
97 return PR_WOULD_BLOCK_ERROR; | 122 return PR_WOULD_BLOCK_ERROR; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 276 |
252 void LogFailedNSSFunction(const BoundNetLog& net_log, | 277 void LogFailedNSSFunction(const BoundNetLog& net_log, |
253 const char* function, | 278 const char* function, |
254 const char* param) { | 279 const char* param) { |
255 net_log.AddEvent( | 280 net_log.AddEvent( |
256 NetLog::TYPE_SSL_NSS_ERROR, | 281 NetLog::TYPE_SSL_NSS_ERROR, |
257 make_scoped_refptr(new SSLFailedNSSFunctionParams(function, param))); | 282 make_scoped_refptr(new SSLFailedNSSFunctionParams(function, param))); |
258 } | 283 } |
259 | 284 |
260 } // namespace net | 285 } // namespace net |
OLD | NEW |