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 #ifndef CRYPTO_NSS_UTIL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_H_ |
6 #define CRYPTO_NSS_UTIL_H_ | 6 #define CRYPTO_NSS_UTIL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "crypto/crypto_export.h" | 14 #include "crypto/crypto_export.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class FilePath; | 17 class FilePath; |
18 class Lock; | 18 class Lock; |
19 class Time; | 19 class Time; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 // This file specifically doesn't depend on any NSS or NSPR headers because it | 22 // This file specifically doesn't depend on any NSS or NSPR headers because it |
23 // is included by various (non-crypto) parts of chrome to call the | 23 // is included by various (non-crypto) parts of chrome to call the |
24 // initialization functions. | 24 // initialization functions. |
25 namespace crypto { | 25 namespace crypto { |
26 | 26 |
27 #if defined(USE_NSS_CERTS) | |
28 // EarlySetupForNSSInit performs lightweight setup which must occur before the | 27 // EarlySetupForNSSInit performs lightweight setup which must occur before the |
29 // process goes multithreaded. This does not initialise NSS. For test, see | 28 // process goes multithreaded. This does not initialise NSS. For test, see |
30 // EnsureNSSInit. | 29 // EnsureNSSInit. |
31 CRYPTO_EXPORT void EarlySetupForNSSInit(); | 30 CRYPTO_EXPORT void EarlySetupForNSSInit(); |
32 #endif | |
33 | 31 |
34 // Initialize NRPR if it isn't already initialized. This function is | 32 // Initialize NRPR if it isn't already initialized. This function is |
35 // thread-safe, and NSPR will only ever be initialized once. | 33 // thread-safe, and NSPR will only ever be initialized once. |
36 CRYPTO_EXPORT void EnsureNSPRInit(); | 34 CRYPTO_EXPORT void EnsureNSPRInit(); |
37 | 35 |
38 // Initialize NSS if it isn't already initialized. This must be called before | 36 // Initialize NSS if it isn't already initialized. This must be called before |
39 // any other NSS functions. This function is thread-safe, and NSS will only | 37 // any other NSS functions. This function is thread-safe, and NSS will only |
40 // ever be initialized once. | 38 // ever be initialized once. |
41 CRYPTO_EXPORT void EnsureNSSInit(); | 39 CRYPTO_EXPORT void EnsureNSSInit(); |
42 | 40 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 #endif | 72 #endif |
75 | 73 |
76 // Convert a NSS PRTime value into a base::Time object. | 74 // Convert a NSS PRTime value into a base::Time object. |
77 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. | 75 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
78 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime); | 76 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime); |
79 | 77 |
80 // Convert a base::Time object into a PRTime value. | 78 // Convert a base::Time object into a PRTime value. |
81 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. | 79 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
82 CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time); | 80 CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time); |
83 | 81 |
84 #if defined(USE_NSS_CERTS) | |
85 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 82 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
86 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 83 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
87 // generations to scribble over each other. To work around this, we synchronize | 84 // generations to scribble over each other. To work around this, we synchronize |
88 // writes to the NSS databases with a global lock. The lock is hidden beneath a | 85 // writes to the NSS databases with a global lock. The lock is hidden beneath a |
89 // function for easy disabling when the bug is fixed. Callers should allow for | 86 // function for easy disabling when the bug is fixed. Callers should allow for |
90 // it to return NULL in the future. | 87 // it to return NULL in the future. |
91 // | 88 // |
92 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | 89 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 |
93 base::Lock* GetNSSWriteLock(); | 90 base::Lock* GetNSSWriteLock(); |
94 | 91 |
95 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | 92 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock |
96 // is in scope. | 93 // is in scope. |
97 class CRYPTO_EXPORT AutoNSSWriteLock { | 94 class CRYPTO_EXPORT AutoNSSWriteLock { |
98 public: | 95 public: |
99 AutoNSSWriteLock(); | 96 AutoNSSWriteLock(); |
100 ~AutoNSSWriteLock(); | 97 ~AutoNSSWriteLock(); |
101 private: | 98 private: |
102 base::Lock *lock_; | 99 base::Lock *lock_; |
103 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 100 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
104 }; | 101 }; |
105 #endif // defined(USE_NSS_CERTS) | |
106 | 102 |
107 } // namespace crypto | 103 } // namespace crypto |
108 | 104 |
109 #endif // CRYPTO_NSS_UTIL_H_ | 105 #endif // CRYPTO_NSS_UTIL_H_ |
OLD | NEW |