ajwong@chromium.org | cf21188 | 2012-07-11 07:19:14 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [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 | |
rvargas@google.com | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 5 | #ifndef CRYPTO_NSS_UTIL_INTERNAL_H_ |
| 6 | #define CRYPTO_NSS_UTIL_INTERNAL_H_ |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 7 | |
| 8 | #include <secmodt.h> |
| 9 | |
mattm@google.com | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 10 | #include "base/callback.h" |
| 11 | #include "base/compiler_specific.h" |
darin@chromium.org | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 12 | #include "crypto/crypto_export.h" |
mattm@google.com | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 13 | #include "crypto/scoped_nss_types.h" |
| 14 | |
| 15 | namespace base { |
| 16 | class FilePath; |
| 17 | } |
rvargas@google.com | e4c9dda | 2011-06-20 23:24:09 | [diff] [blame] | 18 | |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 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. |
| 21 | |
rvargas@google.com | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 22 | namespace crypto { |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 23 | |
mattm@chromium.org | 49631886 | 2014-07-13 07:19:00 | [diff] [blame^] | 24 | // Returns a reference to the default NSS key slot for storing persistent data. |
| 25 | // 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; |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 29 | |
gspencer@google.com | dd24ffc | 2011-06-08 19:46:42 | [diff] [blame] | 30 | // A helper class that acquires the SECMOD list read lock while the |
| 31 | // AutoSECMODListReadLock is in scope. |
mattm@chromium.org | 7037a43c | 2014-01-14 14:00:46 | [diff] [blame] | 32 | class CRYPTO_EXPORT AutoSECMODListReadLock { |
gspencer@google.com | dd24ffc | 2011-06-08 19:46:42 | [diff] [blame] | 33 | public: |
| 34 | AutoSECMODListReadLock(); |
| 35 | ~AutoSECMODListReadLock(); |
| 36 | |
| 37 | private: |
| 38 | SECMODListLock* lock_; |
| 39 | DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock); |
| 40 | }; |
| 41 | |
mattm@google.com | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 42 | #if defined(OS_CHROMEOS) |
mattm@chromium.org | 49631886 | 2014-07-13 07:19:00 | [diff] [blame^] | 43 | // Returns a reference to the system-wide TPM slot. Caller must release |
| 44 | // returned reference with PK11_FreeSlot. |
| 45 | CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT; |
| 46 | |
mattm@google.com | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 47 | // 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. |
| 49 | CRYPTO_EXPORT bool InitializeNSSForChromeOSUser( |
| 50 | const std::string& email, |
| 51 | const std::string& username_hash, |
tbarzic@chromium.org | 4071e6ac | 2014-07-12 12:46:17 | [diff] [blame] | 52 | const base::FilePath& path); |
| 53 | |
| 54 | // Returns whether TPM for ChromeOS user still needs initialization. If |
| 55 | // true is returned, the caller can proceed to initialize TPM slot for the |
| 56 | // user, but should call |WillInitializeTPMForChromeOSUser| first. |
| 57 | // |InitializeNSSForChromeOSUser| must have been called first. |
| 58 | CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser( |
| 59 | const std::string& username_hash) WARN_UNUSED_RESULT; |
| 60 | |
| 61 | // Makes |ShouldInitializeTPMForChromeOSUser| start returning false. |
| 62 | // Should be called before starting TPM initialization for the user. |
| 63 | // Assumes |InitializeNSSForChromeOSUser| had already been called. |
| 64 | CRYPTO_EXPORT void WillInitializeTPMForChromeOSUser( |
| 65 | const std::string& username_hash); |
mattm@google.com | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 66 | |
| 67 | // Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been |
| 68 | // called first. |
| 69 | CRYPTO_EXPORT void InitializeTPMForChromeOSUser( |
| 70 | const std::string& username_hash, |
| 71 | CK_SLOT_ID slot_id); |
| 72 | |
| 73 | // Use the software slot as the private slot for user. |
| 74 | // InitializeNSSForChromeOSUser must have been called first. |
| 75 | CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser( |
| 76 | const std::string& username_hash); |
| 77 | |
| 78 | // Returns a reference to the public slot for user. |
| 79 | CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser( |
| 80 | const std::string& username_hash) WARN_UNUSED_RESULT; |
| 81 | |
| 82 | // 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 |
| 84 | // is loaded. |
| 85 | CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser( |
| 86 | const std::string& username_hash, |
| 87 | const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT; |
| 88 | #endif // defined(OS_CHROMEOS) |
| 89 | |
rvargas@google.com | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 90 | } // namespace crypto |
cmasone@google.com | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 91 | |
rvargas@google.com | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 92 | #endif // CRYPTO_NSS_UTIL_INTERNAL_H_ |