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

Side by Side Diff: crypto/nss_util_internal.h

Issue 401623006: Extract ScopedTestNSSDB from nss_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a DCHECK to SetTestSystemKeySlot. Created 6 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) 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 #if defined(USE_NSS)
Ryan Sleevi 2014/07/23 02:15:28 I don't think you need this #ifdef - see lines 19/
pneubeck (no reviews) 2014/07/23 14:34:17 Done.
25 // Opens an NSS software database in folder |path|, with the (potentially)
26 // user-visible description |description|. Returns the slot for the opened
27 // database, or NULL if the database could not be opened.
28 CRYPTO_EXPORT_PRIVATE ScopedPK11Slot
29 OpenSoftwareNSSDB(const base::FilePath& path,
30 const std::string& description);
31
32 #if !defined(OS_CHROMEOS)
24 // Returns a reference to the default NSS key slot for storing persistent data. 33 // Returns a reference to the default NSS key slot for storing persistent data.
25 // Caller must release returned reference with PK11_FreeSlot. 34 // 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; 35 CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT;
36 #endif
37 #endif
29 38
30 // A helper class that acquires the SECMOD list read lock while the 39 // A helper class that acquires the SECMOD list read lock while the
31 // AutoSECMODListReadLock is in scope. 40 // AutoSECMODListReadLock is in scope.
32 class CRYPTO_EXPORT AutoSECMODListReadLock { 41 class CRYPTO_EXPORT AutoSECMODListReadLock {
33 public: 42 public:
34 AutoSECMODListReadLock(); 43 AutoSECMODListReadLock();
35 ~AutoSECMODListReadLock(); 44 ~AutoSECMODListReadLock();
36 45
37 private: 46 private:
38 SECMODListLock* lock_; 47 SECMODListLock* lock_;
39 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock); 48 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
40 }; 49 };
41 50
42 #if defined(OS_CHROMEOS) 51 #if defined(OS_CHROMEOS)
43 // Returns a reference to the system-wide TPM slot. Caller must release 52 // Returns a reference to the system-wide TPM slot. Caller must release returned
44 // returned reference with PK11_FreeSlot. 53 // reference with PK11_FreeSlot.
45 CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT; 54 CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT;
46 55
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| i s
62 // NULL, the test system slot is unset.
63 CRYPTO_EXPORT_PRIVATE void SetTestSystemKeySlot(ScopedPK11Slot slot);
64
47 // Prepare per-user NSS slot mapping. It is safe to call this function multiple 65 // 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. 66 // times. Returns true if the user was added, or false if it already existed.
49 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser( 67 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
50 const std::string& email, 68 const std::string& email,
51 const std::string& username_hash, 69 const std::string& username_hash,
52 const base::FilePath& path); 70 const base::FilePath& path);
53 71
54 // Returns whether TPM for ChromeOS user still needs initialization. If 72 // Returns whether TPM for ChromeOS user still needs initialization. If
55 // true is returned, the caller can proceed to initialize TPM slot for the 73 // true is returned, the caller can proceed to initialize TPM slot for the
56 // user, but should call |WillInitializeTPMForChromeOSUser| first. 74 // user, but should call |WillInitializeTPMForChromeOSUser| first.
(...skipping 21 matching lines...) Expand all
78 // Returns a reference to the public slot for user. 96 // Returns a reference to the public slot for user.
79 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser( 97 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
80 const std::string& username_hash) WARN_UNUSED_RESULT; 98 const std::string& username_hash) WARN_UNUSED_RESULT;
81 99
82 // Returns the private slot for |username_hash| if it is loaded. If it is not 100 // 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 101 // loaded and |callback| is non-null, the |callback| will be run once the slot
84 // is loaded. 102 // is loaded.
85 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser( 103 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
86 const std::string& username_hash, 104 const std::string& username_hash,
87 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT; 105 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
106
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);
88 #endif // defined(OS_CHROMEOS) 111 #endif // defined(OS_CHROMEOS)
89 112
90 } // namespace crypto 113 } // namespace crypto
91 114
92 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_ 115 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698