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