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

Side by Side Diff: crypto/nss_util.h

Issue 7233006: Store/Retrieve CrOS user policy in session_manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 9 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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 CRYPTO_NSS_UTIL_H_ 5 #ifndef CRYPTO_NSS_UTIL_H_
6 #define CRYPTO_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"
(...skipping 10 matching lines...) Expand all
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) 27 #if defined(USE_NSS)
28 // EarlySetupForNSSInit performs lightweight setup which must occur before the 28 // EarlySetupForNSSInit performs lightweight setup which must occur before the
29 // process goes multithreaded. This does not initialise NSS. For test, see 29 // process goes multithreaded. This does not initialise NSS. For test, see
30 // EnsureNSSInit. 30 // EnsureNSSInit.
31 CRYPTO_API void EarlySetupForNSSInit(); 31 void EarlySetupForNSSInit();
32 #endif 32 #endif
33 33
34 // Initialize NRPR if it isn't already initialized. This function is 34 // Initialize NRPR if it isn't already initialized. This function is
35 // thread-safe, and NSPR will only ever be initialized once. 35 // thread-safe, and NSPR will only ever be initialized once.
36 void CRYPTO_API EnsureNSPRInit(); 36 void CRYPTO_API EnsureNSPRInit();
37 37
38 // Initialize NSS if it isn't already initialized. This must be called before 38 // 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 39 // any other NSS functions. This function is thread-safe, and NSS will only
40 // ever be initialized once. 40 // ever be initialized once.
41 void CRYPTO_API EnsureNSSInit(); 41 void CRYPTO_API EnsureNSSInit();
42 42
43 // Call this before calling EnsureNSSInit() will force NSS to initialize 43 // Call this before calling EnsureNSSInit() will force NSS to initialize
44 // without a persistent DB. This is used for the special case where access of 44 // without a persistent DB. This is used for the special case where access of
45 // persistent DB is prohibited. 45 // persistent DB is prohibited.
46 // 46 //
47 // TODO(hclam): Isolate loading default root certs. 47 // TODO(hclam): Isolate loading default root certs.
48 // 48 //
49 // NSS will be initialized without loading any user security modules, including 49 // NSS will be initialized without loading any user security modules, including
50 // the built-in root certificates module. User security modules need to be 50 // the built-in root certificates module. User security modules need to be
51 // loaded manually after NSS initialization. 51 // loaded manually after NSS initialization.
52 // 52 //
53 // If EnsureNSSInit() is called before then this function has no effect. 53 // If EnsureNSSInit() is called before then this function has no effect.
54 // 54 //
55 // Calling this method only has effect on Linux. 55 // Calling this method only has effect on Linux.
56 // 56 //
57 // WARNING: Use this with caution. 57 // WARNING: Use this with caution.
58 CRYPTO_API void ForceNSSNoDBInit(); 58 void ForceNSSNoDBInit();
59 59
60 // This methods is used to disable checks in NSS when used in a forked process. 60 // This methods is used to disable checks in NSS when used in a forked process.
61 // NSS checks whether it is running a forked process to avoid problems when 61 // NSS checks whether it is running a forked process to avoid problems when
62 // using user security modules in a forked process. However if we are sure 62 // using user security modules in a forked process. However if we are sure
63 // there are no modules loaded before the process is forked then there is no 63 // there are no modules loaded before the process is forked then there is no
64 // harm disabling the check. 64 // harm disabling the check.
65 // 65 //
66 // This method must be called before EnsureNSSInit() to take effect. 66 // This method must be called before EnsureNSSInit() to take effect.
67 // 67 //
68 // WARNING: Use this with caution. 68 // WARNING: Use this with caution.
69 CRYPTO_API void DisableNSSForkCheck(); 69 void DisableNSSForkCheck();
70 70
71 // Load NSS library files. This function has no effect on Mac and Windows. 71 // Load NSS library files. This function has no effect on Mac and Windows.
72 // This loads the necessary NSS library files so that NSS can be initialized 72 // This loads the necessary NSS library files so that NSS can be initialized
73 // after loading additional library files is disallowed, for example when the 73 // after loading additional library files is disallowed, for example when the
74 // sandbox is active. 74 // sandbox is active.
75 // 75 //
76 // Note that this does not load libnssckbi.so which contains the root 76 // Note that this does not load libnssckbi.so which contains the root
77 // certificates. 77 // certificates.
78 CRYPTO_API void LoadNSSLibraries(); 78 void LoadNSSLibraries();
79 79
80 // Check if the current NSS version is greater than or equals to |version|. 80 // Check if the current NSS version is greater than or equals to |version|.
81 // A sample version string is "3.12.3". 81 // A sample version string is "3.12.3".
82 bool CheckNSSVersion(const char* version); 82 bool CheckNSSVersion(const char* version);
83 83
84 #if defined(OS_CHROMEOS) 84 #if defined(OS_CHROMEOS)
85 // Open the r/w nssdb that's stored inside the user's encrypted home 85 // Open the r/w nssdb that's stored inside the user's encrypted home
86 // directory. This is the default slot returned by 86 // directory. This is the default slot returned by
87 // GetPublicNSSKeySlot(). 87 // GetPublicNSSKeySlot().
88 CRYPTO_API void OpenPersistentNSSDB(); 88 CRYPTO_API void OpenPersistentNSSDB();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // loaded into NSS. 129 // loaded into NSS.
130 CRYPTO_API bool IsTPMTokenReady(); 130 CRYPTO_API bool IsTPMTokenReady();
131 131
132 // Same as IsTPMTokenReady() except this attempts to initialize the token 132 // Same as IsTPMTokenReady() except this attempts to initialize the token
133 // if necessary. 133 // if necessary.
134 CRYPTO_API bool EnsureTPMTokenReady(); 134 CRYPTO_API bool EnsureTPMTokenReady();
135 #endif 135 #endif
136 136
137 // Convert a NSS PRTime value into a base::Time object. 137 // Convert a NSS PRTime value into a base::Time object.
138 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. 138 // We use a int64 instead of PRTime here to avoid depending on NSPR headers.
139 CRYPTO_API base::Time PRTimeToBaseTime(int64 prtime); 139 base::Time PRTimeToBaseTime(int64 prtime);
140 140
141 #if defined(USE_NSS) 141 #if defined(USE_NSS)
142 // Exposed for unittests only. |path| should be an existing directory under 142 // Exposed for unittests only. |path| should be an existing directory under
143 // which the DB files will be placed. |description| is a user-visible name for 143 // which the DB files will be placed. |description| is a user-visible name for
144 // the DB, as a utf8 string, which will be truncated at 32 bytes. 144 // the DB, as a utf8 string, which will be truncated at 32 bytes.
145 CRYPTO_API bool OpenTestNSSDB(const FilePath& path, const char* description); 145 bool OpenTestNSSDB(const FilePath& path, const char* description);
146 CRYPTO_API void CloseTestNSSDB(); 146 void CloseTestNSSDB();
147 147
148 // NSS has a bug which can cause a deadlock or stall in some cases when writing 148 // NSS has a bug which can cause a deadlock or stall in some cases when writing
149 // to the certDB and keyDB. It also has a bug which causes concurrent key pair 149 // to the certDB and keyDB. It also has a bug which causes concurrent key pair
150 // generations to scribble over each other. To work around this, we synchronize 150 // generations to scribble over each other. To work around this, we synchronize
151 // writes to the NSS databases with a global lock. The lock is hidden beneath a 151 // writes to the NSS databases with a global lock. The lock is hidden beneath a
152 // function for easy disabling when the bug is fixed. Callers should allow for 152 // function for easy disabling when the bug is fixed. Callers should allow for
153 // it to return NULL in the future. 153 // it to return NULL in the future.
154 // 154 //
155 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 155 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011
156 base::Lock* GetNSSWriteLock(); 156 base::Lock* GetNSSWriteLock();
157 157
158 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock 158 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock
159 // is in scope. 159 // is in scope.
160 class CRYPTO_API AutoNSSWriteLock { 160 class AutoNSSWriteLock {
161 public: 161 public:
162 AutoNSSWriteLock(); 162 AutoNSSWriteLock();
163 ~AutoNSSWriteLock(); 163 ~AutoNSSWriteLock();
164 private: 164 private:
165 base::Lock *lock_; 165 base::Lock *lock_;
166 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); 166 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock);
167 }; 167 };
168 168
169 #endif // defined(USE_NSS) 169 #endif // defined(USE_NSS)
170 170
171 } // namespace crypto 171 } // namespace crypto
172 172
173 #endif // CRYPTO_NSS_UTIL_H_ 173 #endif // CRYPTO_NSS_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698