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_INTERNAL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_INTERNAL_H_ |
6 #define CRYPTO_NSS_UTIL_INTERNAL_H_ | 6 #define CRYPTO_NSS_UTIL_INTERNAL_H_ |
7 | 7 |
8 #include <secmodt.h> | 8 #include <secmodt.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "crypto/crypto_export.h" | 12 #include "crypto/crypto_export.h" |
13 #include "crypto/scoped_nss_types.h" | 13 #include "crypto/scoped_nss_types.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class FilePath; | 16 class FilePath; |
17 } | 17 } |
18 | 18 |
19 // These functions return a type defined in an NSS header, and so cannot be | 19 // These functions return a type defined in an NSS header, and so cannot be |
20 // declared in nss_util.h. Hence, they are declared here. | 20 // declared in nss_util.h. Hence, they are declared here. |
21 | 21 |
22 namespace crypto { | 22 namespace crypto { |
23 | 23 |
24 // Opens an NSS software database in folder |path|, with the (potentially) | |
25 // user-visible description |description|. Returns the slot for the opened | |
26 // database, or NULL if the database could not be opened. | |
27 CRYPTO_EXPORT_PRIVATE ScopedPK11Slot | |
28 OpenSoftwareNSSDB(const base::FilePath& path, | |
29 const std::string& description); | |
30 | |
31 #if !defined(OS_CHROMEOS) | |
24 // Returns a reference to the default NSS key slot for storing persistent data. | 32 // Returns a reference to the default NSS key slot for storing persistent data. |
25 // Caller must release returned reference with PK11_FreeSlot. | 33 // Caller must release returned reference with PK11_FreeSlot. |
26 // TODO(mattm): this should be if !defined(OS_CHROMEOS), but some tests need to | |
27 // be fixed first. | |
28 CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT; | 34 CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT; |
35 #endif | |
29 | 36 |
30 // A helper class that acquires the SECMOD list read lock while the | 37 // A helper class that acquires the SECMOD list read lock while the |
31 // AutoSECMODListReadLock is in scope. | 38 // AutoSECMODListReadLock is in scope. |
32 class CRYPTO_EXPORT AutoSECMODListReadLock { | 39 class CRYPTO_EXPORT AutoSECMODListReadLock { |
33 public: | 40 public: |
34 AutoSECMODListReadLock(); | 41 AutoSECMODListReadLock(); |
35 ~AutoSECMODListReadLock(); | 42 ~AutoSECMODListReadLock(); |
36 | 43 |
37 private: | 44 private: |
38 SECMODListLock* lock_; | 45 SECMODListLock* lock_; |
39 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock); | 46 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock); |
40 }; | 47 }; |
41 | 48 |
42 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
43 // Returns a reference to the system-wide TPM slot. Caller must release | 50 // Returns a reference to the system-wide TPM slot. Caller must release returned |
44 // returned reference with PK11_FreeSlot. | 51 // reference with PK11_FreeSlot. |
45 CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT; | 52 CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT; |
46 | 53 |
54 // Sets the test system slot. If this was called before | |
55 // InitializeTPMTokenAndSystemSlot and no system token is provided by the Chaps | |
56 // module, then this test slot will be used and the initialization continues as | |
57 // if Chaps had provided this test slot. In particular, |slot| will be exposed | |
58 // by |GetSystemNSSKeySlot| and |IsTPMTokenReady| will return true. | |
59 // This must must not be called consecutively with a |slot| != NULL. If |slot| | |
60 // is NULL, the test system slot is unset. | |
Ryan Sleevi
2014/07/24 23:14:02
To confirm:
Is the following valid
Set(!=NULL)
S
pneubeck (no reviews)
2014/07/25 08:35:14
In principal yes. Although, in tests nobody should
| |
61 CRYPTO_EXPORT_PRIVATE void SetSystemKeySlotForTesting(ScopedPK11Slot slot); | |
62 | |
47 // Prepare per-user NSS slot mapping. It is safe to call this function multiple | 63 // Prepare per-user NSS slot mapping. It is safe to call this function multiple |
48 // times. Returns true if the user was added, or false if it already existed. | 64 // times. Returns true if the user was added, or false if it already existed. |
49 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser( | 65 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser( |
50 const std::string& email, | 66 const std::string& email, |
51 const std::string& username_hash, | 67 const std::string& username_hash, |
52 const base::FilePath& path); | 68 const base::FilePath& path); |
53 | 69 |
54 // Returns whether TPM for ChromeOS user still needs initialization. If | 70 // Returns whether TPM for ChromeOS user still needs initialization. If |
55 // true is returned, the caller can proceed to initialize TPM slot for the | 71 // true is returned, the caller can proceed to initialize TPM slot for the |
56 // user, but should call |WillInitializeTPMForChromeOSUser| first. | 72 // user, but should call |WillInitializeTPMForChromeOSUser| first. |
(...skipping 21 matching lines...) Expand all Loading... | |
78 // Returns a reference to the public slot for user. | 94 // Returns a reference to the public slot for user. |
79 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser( | 95 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser( |
80 const std::string& username_hash) WARN_UNUSED_RESULT; | 96 const std::string& username_hash) WARN_UNUSED_RESULT; |
81 | 97 |
82 // Returns the private slot for |username_hash| if it is loaded. If it is not | 98 // Returns the private slot for |username_hash| if it is loaded. If it is not |
83 // loaded and |callback| is non-null, the |callback| will be run once the slot | 99 // loaded and |callback| is non-null, the |callback| will be run once the slot |
84 // is loaded. | 100 // is loaded. |
85 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser( | 101 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser( |
86 const std::string& username_hash, | 102 const std::string& username_hash, |
87 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT; | 103 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT; |
104 | |
105 // Closes the NSS DB for |username_hash| that was previously opened by the | |
106 // *Initialize*ForChromeOSUser functions. | |
107 CRYPTO_EXPORT_PRIVATE void CloseChromeOSUserForTesting( | |
108 const std::string& username_hash); | |
88 #endif // defined(OS_CHROMEOS) | 109 #endif // defined(OS_CHROMEOS) |
89 | 110 |
90 } // namespace crypto | 111 } // namespace crypto |
91 | 112 |
92 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_ | 113 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_ |
OLD | NEW |