OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 BASE_NSS_UTIL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_H_ |
6 #define BASE_NSS_UTIL_H_ | 6 #define CRYPTO_NSS_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 | 11 |
12 #if defined(USE_NSS) | 12 #if defined(USE_NSS) |
13 class FilePath; | 13 class FilePath; |
14 #endif // defined(USE_NSS) | 14 #endif // defined(USE_NSS) |
15 | 15 |
| 16 namespace base { |
| 17 class Lock; |
| 18 class Time; |
| 19 } // namespace base |
| 20 |
16 // This file specifically doesn't depend on any NSS or NSPR headers because it | 21 // This file specifically doesn't depend on any NSS or NSPR headers because it |
17 // is included by various (non-crypto) parts of chrome to call the | 22 // is included by various (non-crypto) parts of chrome to call the |
18 // initialization functions. | 23 // initialization functions. |
19 namespace base { | 24 namespace crypto { |
20 | |
21 class Lock; | |
22 class Time; | |
23 | 25 |
24 #if defined(USE_NSS) | 26 #if defined(USE_NSS) |
25 // EarlySetupForNSSInit performs lightweight setup which must occur before the | 27 // EarlySetupForNSSInit performs lightweight setup which must occur before the |
26 // process goes multithreaded. This does not initialise NSS. For test, see | 28 // process goes multithreaded. This does not initialise NSS. For test, see |
27 // EnsureNSSInit. | 29 // EnsureNSSInit. |
28 void EarlySetupForNSSInit(); | 30 void EarlySetupForNSSInit(); |
29 #endif | 31 #endif |
30 | 32 |
31 // Initialize NRPR if it isn't already initialized. This function is | 33 // Initialize NRPR if it isn't already initialized. This function is |
32 // thread-safe, and NSPR will only ever be initialized once. NSPR will be | 34 // thread-safe, and NSPR will only ever be initialized once. |
33 // properly shut down on program exit. | |
34 void EnsureNSPRInit(); | 35 void EnsureNSPRInit(); |
35 | 36 |
36 // Initialize NSS if it isn't already initialized. This must be called before | 37 // Initialize NSS if it isn't already initialized. This must be called before |
37 // any other NSS functions. This function is thread-safe, and NSS will only | 38 // any other NSS functions. This function is thread-safe, and NSS will only |
38 // ever be initialized once. NSS will be properly shut down on program exit. | 39 // ever be initialized once. |
39 void EnsureNSSInit(); | 40 void EnsureNSSInit(); |
40 | 41 |
41 // Call this before calling EnsureNSSInit() will force NSS to initialize | 42 // Call this before calling EnsureNSSInit() will force NSS to initialize |
42 // without a persistent DB. This is used for the special case where access of | 43 // without a persistent DB. This is used for the special case where access of |
43 // persistent DB is prohibited. | 44 // persistent DB is prohibited. |
44 // | 45 // |
45 // TODO(hclam): Isolate loading default root certs. | 46 // TODO(hclam): Isolate loading default root certs. |
46 // | 47 // |
47 // NSS will be initialized without loading any user security modules, including | 48 // NSS will be initialized without loading any user security modules, including |
48 // the built-in root certificates module. User security modules need to be | 49 // the built-in root certificates module. User security modules need to be |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // return the TPM slot if one was found. Returns false if it was | 91 // return the TPM slot if one was found. Returns false if it was |
91 // unable to load opencryptoki or open the TPM slot. | 92 // unable to load opencryptoki or open the TPM slot. |
92 bool EnableTPMForNSS(); | 93 bool EnableTPMForNSS(); |
93 | 94 |
94 // Get name for the built-in TPM token on ChromeOS. | 95 // Get name for the built-in TPM token on ChromeOS. |
95 std::string GetTPMTokenName(); | 96 std::string GetTPMTokenName(); |
96 #endif | 97 #endif |
97 | 98 |
98 // Convert a NSS PRTime value into a base::Time object. | 99 // Convert a NSS PRTime value into a base::Time object. |
99 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 100 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
100 Time PRTimeToBaseTime(int64 prtime); | 101 base::Time PRTimeToBaseTime(int64 prtime); |
101 | 102 |
102 #if defined(USE_NSS) | 103 #if defined(USE_NSS) |
103 // Exposed for unittests only. |path| should be an existing directory under | 104 // Exposed for unittests only. |path| should be an existing directory under |
104 // which the DB files will be placed. |description| is a user-visible name for | 105 // which the DB files will be placed. |description| is a user-visible name for |
105 // the DB, as a utf8 string, which will be truncated at 32 bytes. | 106 // the DB, as a utf8 string, which will be truncated at 32 bytes. |
106 bool OpenTestNSSDB(const FilePath& path, const char* description); | 107 bool OpenTestNSSDB(const FilePath& path, const char* description); |
107 void CloseTestNSSDB(); | 108 void CloseTestNSSDB(); |
108 | 109 |
109 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 110 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
110 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 111 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
(...skipping 11 matching lines...) Expand all Loading... |
122 public: | 123 public: |
123 AutoNSSWriteLock(); | 124 AutoNSSWriteLock(); |
124 ~AutoNSSWriteLock(); | 125 ~AutoNSSWriteLock(); |
125 private: | 126 private: |
126 Lock *lock_; | 127 Lock *lock_; |
127 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 128 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
128 }; | 129 }; |
129 | 130 |
130 #endif // defined(USE_NSS) | 131 #endif // defined(USE_NSS) |
131 | 132 |
132 } // namespace base | 133 } // namespace crypto |
133 | 134 |
134 #endif // BASE_NSS_UTIL_H_ | 135 #endif // CRYPTO_NSS_UTIL_H_ |
OLD | NEW |