[go: nahoru, domu]

blob: e9d4870daf6bb9119e5865d7ac7205f01e1a7e60 [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
mattm@google.com557737f72013-12-06 22:24:0710#include "base/callback.h"
11#include "base/compiler_specific.h"
darin@chromium.orgd613a9902011-08-05 20:59:1112#include "crypto/crypto_export.h"
mattm@google.com557737f72013-12-06 22:24:0713#include "crypto/scoped_nss_types.h"
14
15namespace base {
16class FilePath;
17}
rvargas@google.come4c9dda2011-06-20 23:24:0918
cmasone@google.comdcce6cf2010-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
rvargas@google.com4b559b4d2011-04-14 17:37:1422namespace crypto {
cmasone@google.comdcce6cf2010-04-29 17:50:0623
mattm@chromium.org496318862014-07-13 07:19:0024// Returns a reference to the default NSS key slot for storing persistent data.
25// 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.
28CRYPTO_EXPORT PK11SlotInfo* GetPersistentNSSKeySlot() WARN_UNUSED_RESULT;
cmasone@google.comdcce6cf2010-04-29 17:50:0629
gspencer@google.comdd24ffc2011-06-08 19:46:4230// A helper class that acquires the SECMOD list read lock while the
31// AutoSECMODListReadLock is in scope.
mattm@chromium.org7037a43c2014-01-14 14:00:4632class CRYPTO_EXPORT AutoSECMODListReadLock {
gspencer@google.comdd24ffc2011-06-08 19:46:4233 public:
34 AutoSECMODListReadLock();
35 ~AutoSECMODListReadLock();
36
37 private:
38 SECMODListLock* lock_;
39 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
40};
41
mattm@google.com557737f72013-12-06 22:24:0742#if defined(OS_CHROMEOS)
mattm@chromium.org496318862014-07-13 07:19:0043// Returns a reference to the system-wide TPM slot. Caller must release
44// returned reference with PK11_FreeSlot.
45CRYPTO_EXPORT PK11SlotInfo* GetSystemNSSKeySlot() WARN_UNUSED_RESULT;
46
mattm@google.com557737f72013-12-06 22:24:0747// 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.
49CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
50 const std::string& email,
51 const std::string& username_hash,
tbarzic@chromium.org4071e6ac2014-07-12 12:46:1752 const base::FilePath& path);
53
54// Returns whether TPM for ChromeOS user still needs initialization. If
55// true is returned, the caller can proceed to initialize TPM slot for the
56// user, but should call |WillInitializeTPMForChromeOSUser| first.
57// |InitializeNSSForChromeOSUser| must have been called first.
58CRYPTO_EXPORT bool ShouldInitializeTPMForChromeOSUser(
59 const std::string& username_hash) WARN_UNUSED_RESULT;
60
61// Makes |ShouldInitializeTPMForChromeOSUser| start returning false.
62// Should be called before starting TPM initialization for the user.
63// Assumes |InitializeNSSForChromeOSUser| had already been called.
64CRYPTO_EXPORT void WillInitializeTPMForChromeOSUser(
65 const std::string& username_hash);
mattm@google.com557737f72013-12-06 22:24:0766
67// Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been
68// called first.
69CRYPTO_EXPORT void InitializeTPMForChromeOSUser(
70 const std::string& username_hash,
71 CK_SLOT_ID slot_id);
72
73// Use the software slot as the private slot for user.
74// InitializeNSSForChromeOSUser must have been called first.
75CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
76 const std::string& username_hash);
77
78// Returns a reference to the public slot for user.
79CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
80 const std::string& username_hash) WARN_UNUSED_RESULT;
81
82// 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
84// is loaded.
85CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
86 const std::string& username_hash,
87 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
88#endif // defined(OS_CHROMEOS)
89
rvargas@google.com4b559b4d2011-04-14 17:37:1490} // namespace crypto
cmasone@google.comdcce6cf2010-04-29 17:50:0691
rvargas@google.com4b559b4d2011-04-14 17:37:1492#endif // CRYPTO_NSS_UTIL_INTERNAL_H_