blob: 8175604e0dfcf75b54e9e63ca7858e92ca9797f6 [file] [log] [blame]
[email protected]cf211882012-07-11 07:19:141// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]dcce6cf2010-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
[email protected]4b559b4d2011-04-14 17:37:145#ifndef CRYPTO_NSS_UTIL_INTERNAL_H_
6#define CRYPTO_NSS_UTIL_INTERNAL_H_
[email protected]dcce6cf2010-04-29 17:50:067
8#include <secmodt.h>
9
[email protected]557737f72013-12-06 22:24:0710#include "base/callback.h"
11#include "base/compiler_specific.h"
[email protected]d613a9902011-08-05 20:59:1112#include "crypto/crypto_export.h"
[email protected]557737f72013-12-06 22:24:0713#include "crypto/scoped_nss_types.h"
14
15namespace base {
16class FilePath;
17}
[email protected]e4c9dda2011-06-20 23:24:0918
[email protected]dcce6cf2010-04-29 17:50:0619// 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]4b559b4d2011-04-14 17:37:1422namespace crypto {
[email protected]dcce6cf2010-04-29 17:50:0623
[email protected]6a89ef22011-04-07 17:34:2124// 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]557737f72013-12-06 22:24:0727CRYPTO_EXPORT PK11SlotInfo* GetPublicNSSKeySlot() WARN_UNUSED_RESULT;
[email protected]6a89ef22011-04-07 17:34:2128
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]557737f72013-12-06 22:24:0734CRYPTO_EXPORT PK11SlotInfo* GetPrivateNSSKeySlot() WARN_UNUSED_RESULT;
[email protected]dcce6cf2010-04-29 17:50:0635
[email protected]dd24ffc2011-06-08 19:46:4236// A helper class that acquires the SECMOD list read lock while the
37// AutoSECMODListReadLock is in scope.
[email protected]7037a43c2014-01-14 14:00:4638class CRYPTO_EXPORT AutoSECMODListReadLock {
[email protected]dd24ffc2011-06-08 19:46:4239 public:
40 AutoSECMODListReadLock();
41 ~AutoSECMODListReadLock();
42
43 private:
44 SECMODListLock* lock_;
45 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
46};
47
[email protected]557737f72013-12-06 22:24:0748#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.
51CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
52 const std::string& email,
53 const std::string& username_hash,
[email protected]4071e6ac2014-07-12 12:46:1754 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.
60CRYPTO_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.
66CRYPTO_EXPORT void WillInitializeTPMForChromeOSUser(
67 const std::string& username_hash);
[email protected]557737f72013-12-06 22:24:0768
69// Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been
70// called first.
71CRYPTO_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.
77CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
78 const std::string& username_hash);
79
80// Returns a reference to the public slot for user.
81CRYPTO_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.
87CRYPTO_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]4b559b4d2011-04-14 17:37:1492} // namespace crypto
[email protected]dcce6cf2010-04-29 17:50:0693
[email protected]4b559b4d2011-04-14 17:37:1494#endif // CRYPTO_NSS_UTIL_INTERNAL_H_