athena: Re-add ui_chromeos resources in athena_resources.pak.
[chromium-blink-merge.git] / crypto / nss_util_internal.h
blobcb1b9bd538264b318ab43b7e66972dbd5914ee37
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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_NSS_UTIL_INTERNAL_H_
6 #define CRYPTO_NSS_UTIL_INTERNAL_H_
8 #include <secmodt.h>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "crypto/crypto_export.h"
13 #include "crypto/scoped_nss_types.h"
15 namespace base {
16 class FilePath;
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.
22 namespace crypto {
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);
31 #if !defined(OS_CHROMEOS)
32 // Returns a reference to the default NSS key slot for storing persistent data.
33 // Caller must release returned reference with PK11_FreeSlot.
34 CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT;
35 #endif
37 // A helper class that acquires the SECMOD list read lock while the
38 // AutoSECMODListReadLock is in scope.
39 class CRYPTO_EXPORT AutoSECMODListReadLock {
40 public:
41 AutoSECMODListReadLock();
42 ~AutoSECMODListReadLock();
44 private:
45 SECMODListLock* lock_;
46 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
49 #if defined(OS_CHROMEOS)
50 // Returns a reference to the system-wide TPM slot if it is loaded. If it is not
51 // loaded and |callback| is non-null, the |callback| will be run once the slot
52 // is loaded.
53 CRYPTO_EXPORT ScopedPK11Slot GetSystemNSSKeySlot(
54 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
56 // Sets the test system slot. If this was called before
57 // InitializeTPMTokenAndSystemSlot and no system token is provided by the Chaps
58 // module, then this test slot will be used and the initialization continues as
59 // if Chaps had provided this test slot. In particular, |slot| will be exposed
60 // by |GetSystemNSSKeySlot| and |IsTPMTokenReady| will return true.
61 // This must must not be called consecutively with a |slot| != NULL. If |slot|
62 // is NULL, the test system slot is unset.
63 CRYPTO_EXPORT_PRIVATE void SetSystemKeySlotForTesting(ScopedPK11Slot slot);
65 // Prepare per-user NSS slot mapping. It is safe to call this function multiple
66 // times. Returns true if the user was added, or false if it already existed.
67 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
68 const std::string& email,
69 const std::string& username_hash,
70 const base::FilePath& path);
72 // Returns whether TPM for ChromeOS user still needs initialization. If
73 // true is returned, the caller can proceed to initialize TPM slot for the
74 // user, but should call |WillInitializeTPMForChromeOSUser| first.
75 // |InitializeNSSForChromeOSUser| must have been called first.
76 CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser(
77 const std::string& username_hash) WARN_UNUSED_RESULT;
79 // Makes |ShouldInitializeTPMForChromeOSUser| start returning false.
80 // Should be called before starting TPM initialization for the user.
81 // Assumes |InitializeNSSForChromeOSUser| had already been called.
82 CRYPTO_EXPORT void WillInitializeTPMForChromeOSUser(
83 const std::string& username_hash);
85 // Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been
86 // called first.
87 CRYPTO_EXPORT void InitializeTPMForChromeOSUser(
88 const std::string& username_hash,
89 CK_SLOT_ID slot_id);
91 // Use the software slot as the private slot for user.
92 // InitializeNSSForChromeOSUser must have been called first.
93 CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
94 const std::string& username_hash);
96 // Returns a reference to the public slot for user.
97 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
98 const std::string& username_hash) WARN_UNUSED_RESULT;
100 // Returns the private slot for |username_hash| if it is loaded. If it is not
101 // loaded and |callback| is non-null, the |callback| will be run once the slot
102 // is loaded.
103 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
104 const std::string& username_hash,
105 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
107 // Closes the NSS DB for |username_hash| that was previously opened by the
108 // *Initialize*ForChromeOSUser functions.
109 CRYPTO_EXPORT_PRIVATE void CloseChromeOSUserForTesting(
110 const std::string& username_hash);
111 #endif // defined(OS_CHROMEOS)
113 } // namespace crypto
115 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_