[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 5 | #ifndef BASE_NSS_UTIL_H_ |
6 | #define BASE_NSS_UTIL_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 8 | |
9 | #include "base/basictypes.h" | ||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 10 | |
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 11 | #if defined(USE_NSS) |
[email protected] | bb639038 | 2010-08-12 19:49:40 | [diff] [blame] | 12 | class FilePath; |
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 13 | #endif // defined(USE_NSS) |
14 | |||||
[email protected] | 41c78fa | 2010-03-22 20:08:41 | [diff] [blame] | 15 | // This file specifically doesn't depend on any NSS or NSPR headers because it |
16 | // is included by various (non-crypto) parts of chrome to call the | ||||
17 | // initialization functions. | ||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 18 | namespace base { |
19 | |||||
[email protected] | bc581a68 | 2011-01-01 23:16:20 | [diff] [blame] | 20 | class Lock; |
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 21 | class Time; |
22 | |||||
[email protected] | ac3d597 | 2011-01-13 20:33:45 | [diff] [blame^] | 23 | #if defined(USE_NSS) |
24 | // EarlySetupForNSSInit performs lightweight setup which must occur before the | ||||
25 | // process goes multithreaded. This does not initialise NSS. For test, see | ||||
26 | // EnsureNSSInit. | ||||
27 | void EarlySetupForNSSInit(); | ||||
28 | #endif | ||||
29 | |||||
[email protected] | 730fb13 | 2009-09-02 22:50:25 | [diff] [blame] | 30 | // Initialize NRPR if it isn't already initialized. This function is |
31 | // thread-safe, and NSPR will only ever be initialized once. NSPR will be | ||||
32 | // properly shut down on program exit. | ||||
33 | void EnsureNSPRInit(); | ||||
34 | |||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 35 | // Initialize NSS if it isn't already initialized. This must be called before |
36 | // any other NSS functions. This function is thread-safe, and NSS will only | ||||
37 | // ever be initialized once. NSS will be properly shut down on program exit. | ||||
38 | void EnsureNSSInit(); | ||||
39 | |||||
[email protected] | f61c397 | 2010-12-23 09:54:15 | [diff] [blame] | 40 | // Check if the current NSS version is greater than or equals to |version|. |
41 | // A sample version string is "3.12.3". | ||||
42 | bool CheckNSSVersion(const char* version); | ||||
43 | |||||
[email protected] | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 44 | #if defined(OS_CHROMEOS) |
45 | // Open the r/w nssdb that's stored inside the user's encrypted home directory. | ||||
46 | void OpenPersistentNSSDB(); | ||||
47 | #endif | ||||
48 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 49 | // Convert a NSS PRTime value into a base::Time object. |
50 | // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | ||||
51 | Time PRTimeToBaseTime(int64 prtime); | ||||
52 | |||||
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 53 | #if defined(USE_NSS) |
[email protected] | bb639038 | 2010-08-12 19:49:40 | [diff] [blame] | 54 | // Exposed for unittests only. |path| should be an existing directory under |
55 | // which the DB files will be placed. |description| is a user-visible name for | ||||
56 | // the DB, as a utf8 string, which will be truncated at 32 bytes. | ||||
57 | bool OpenTestNSSDB(const FilePath& path, const char* description); | ||||
58 | void CloseTestNSSDB(); | ||||
59 | |||||
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 60 | // NSS has a bug which can cause a deadlock or stall in some cases when writing |
61 | // to the certDB and keyDB. It also has a bug which causes concurrent key pair | ||||
62 | // generations to scribble over each other. To work around this, we synchronize | ||||
63 | // writes to the NSS databases with a global lock. The lock is hidden beneath a | ||||
64 | // function for easy disabling when the bug is fixed. Callers should allow for | ||||
65 | // it to return NULL in the future. | ||||
66 | // | ||||
67 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | ||||
68 | Lock* GetNSSWriteLock(); | ||||
69 | |||||
70 | // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | ||||
71 | // is in scope. | ||||
72 | class AutoNSSWriteLock { | ||||
73 | public: | ||||
74 | AutoNSSWriteLock(); | ||||
75 | ~AutoNSSWriteLock(); | ||||
76 | private: | ||||
77 | Lock *lock_; | ||||
78 | DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | ||||
79 | }; | ||||
80 | |||||
81 | #endif // defined(USE_NSS) | ||||
82 | |||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 83 | } // namespace base |
84 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 85 | #endif // BASE_NSS_UTIL_H_ |