[go: nahoru, domu]

blob: 080ac1026de2b75f4f932197dab8baf8323825f7 [file] [log] [blame]
ajwong@chromium.orgcf211882012-07-11 07:19:141// Copyright (c) 2012 The Chromium Authors. All rights reserved.
cmasone@google.comdcce6cf2010-04-29 17:50:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
rvargas@google.com4b559b4d2011-04-14 17:37:145#ifndef CRYPTO_NSS_UTIL_INTERNAL_H_
6#define CRYPTO_NSS_UTIL_INTERNAL_H_
cmasone@google.comdcce6cf2010-04-29 17:50:067
8#include <secmodt.h>
9
davidben6004dc52017-02-03 04:15:2910#include <string>
11
mattm@google.com557737f72013-12-06 22:24:0712#include "base/callback.h"
13#include "base/compiler_specific.h"
avidd373b82015-12-21 21:34:4314#include "base/macros.h"
darin@chromium.orgd613a9902011-08-05 20:59:1115#include "crypto/crypto_export.h"
mattm@google.com557737f72013-12-06 22:24:0716#include "crypto/scoped_nss_types.h"
17
18namespace base {
19class FilePath;
20}
rvargas@google.come4c9dda2011-06-20 23:24:0921
cmasone@google.comdcce6cf2010-04-29 17:50:0622// These functions return a type defined in an NSS header, and so cannot be
23// declared in nss_util.h. Hence, they are declared here.
24
rvargas@google.com4b559b4d2011-04-14 17:37:1425namespace crypto {
cmasone@google.comdcce6cf2010-04-29 17:50:0626
pneubeck@chromium.org190933f2014-07-28 09:56:5127// Opens an NSS software database in folder |path|, with the (potentially)
28// user-visible description |description|. Returns the slot for the opened
rsleeviffe5a132016-06-28 01:51:5229// database, or nullptr if the database could not be opened.
xhwang3e9ca562015-11-06 18:50:3630CRYPTO_EXPORT ScopedPK11Slot OpenSoftwareNSSDB(const base::FilePath& path,
31 const std::string& description);
pneubeck@chromium.org190933f2014-07-28 09:56:5132
33#if !defined(OS_CHROMEOS)
mattm@chromium.org496318862014-07-13 07:19:0034// Returns a reference to the default NSS key slot for storing persistent data.
35// Caller must release returned reference with PK11_FreeSlot.
mattm@chromium.org496318862014-07-13 07:19:0036CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT;
pneubeck@chromium.org190933f2014-07-28 09:56:5137#endif
cmasone@google.comdcce6cf2010-04-29 17:50:0638
gspencer@google.comdd24ffc2011-06-08 19:46:4239// A helper class that acquires the SECMOD list read lock while the
40// AutoSECMODListReadLock is in scope.
mattm@chromium.org7037a43c2014-01-14 14:00:4641class CRYPTO_EXPORT AutoSECMODListReadLock {
gspencer@google.comdd24ffc2011-06-08 19:46:4242 public:
43 AutoSECMODListReadLock();
44 ~AutoSECMODListReadLock();
45
46 private:
47 SECMODListLock* lock_;
48 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
49};
50
mattm@google.com557737f72013-12-06 22:24:0751#if defined(OS_CHROMEOS)
pneubeck@chromium.org8edd7212014-07-30 12:24:2952// Returns a reference to the system-wide TPM slot if it is loaded. If it is not
53// loaded and |callback| is non-null, the |callback| will be run once the slot
54// is loaded.
55CRYPTO_EXPORT ScopedPK11Slot GetSystemNSSKeySlot(
56 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
pneubeck@chromium.org190933f2014-07-28 09:56:5157
pneubeck@chromium.org442233d42014-08-02 07:37:2458// Sets the test system slot to |slot|, which means that |slot| will be exposed
59// through |GetSystemNSSKeySlot| and |IsTPMTokenReady| will return true.
60// |InitializeTPMTokenAndSystemSlot|, which triggers the TPM initialization,
61// does not have to be called if the test system slot is set.
rsleeviffe5a132016-06-28 01:51:5262// This must must not be called consecutively with a |slot| != nullptr. If
63// |slot| is nullptr, the test system slot is unset.
xhwang3e9ca562015-11-06 18:50:3664CRYPTO_EXPORT void SetSystemKeySlotForTesting(ScopedPK11Slot slot);
mattm@chromium.org496318862014-07-13 07:19:0065
mattm@google.com557737f72013-12-06 22:24:0766// Prepare per-user NSS slot mapping. It is safe to call this function multiple
67// times. Returns true if the user was added, or false if it already existed.
68CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
mattm@google.com557737f72013-12-06 22:24:0769 const std::string& username_hash,
tbarzic@chromium.org4071e6ac2014-07-12 12:46:1770 const base::FilePath& path);
71
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.
76CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser(
77 const std::string& username_hash) WARN_UNUSED_RESULT;
78
79// Makes |ShouldInitializeTPMForChromeOSUser| start returning false.
80// Should be called before starting TPM initialization for the user.
81// Assumes |InitializeNSSForChromeOSUser| had already been called.
82CRYPTO_EXPORT void WillInitializeTPMForChromeOSUser(
83 const std::string& username_hash);
mattm@google.com557737f72013-12-06 22:24:0784
85// Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been
86// called first.
87CRYPTO_EXPORT void InitializeTPMForChromeOSUser(
88 const std::string& username_hash,
89 CK_SLOT_ID slot_id);
90
91// Use the software slot as the private slot for user.
92// InitializeNSSForChromeOSUser must have been called first.
93CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
94 const std::string& username_hash);
95
96// Returns a reference to the public slot for user.
97CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
98 const std::string& username_hash) WARN_UNUSED_RESULT;
99
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.
103CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
104 const std::string& username_hash,
105 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
pneubeck@chromium.org190933f2014-07-28 09:56:51106
107// Closes the NSS DB for |username_hash| that was previously opened by the
108// *Initialize*ForChromeOSUser functions.
xhwang3e9ca562015-11-06 18:50:36109CRYPTO_EXPORT void CloseChromeOSUserForTesting(
pneubeck@chromium.org190933f2014-07-28 09:56:51110 const std::string& username_hash);
mattm@google.com557737f72013-12-06 22:24:07111#endif // defined(OS_CHROMEOS)
112
rvargas@google.com4b559b4d2011-04-14 17:37:14113} // namespace crypto
cmasone@google.comdcce6cf2010-04-29 17:50:06114
rvargas@google.com4b559b4d2011-04-14 17:37:14115#endif // CRYPTO_NSS_UTIL_INTERNAL_H_