blob: fd27095e4ed00dceb21384953fde86a99994cb94 [file] [log] [blame]
[email protected]02746292012-01-25 04:37:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]bc1e07c72008-09-16 14:32:442// 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_H_
6#define CRYPTO_NSS_UTIL_H_
[email protected]1b1a264a2010-01-14 22:36:357
avidd373b8b2015-12-21 21:34:438#include <stdint.h>
9
[email protected]6a89ef22011-04-07 17:34:2110#include <string>
[email protected]e2ea5ca2014-02-27 22:27:2111#include "base/callback.h"
[email protected]557737f72013-12-06 22:24:0712#include "base/compiler_specific.h"
avidd373b8b2015-12-21 21:34:4313#include "base/macros.h"
Yuta Hijikatabf953202020-11-12 08:43:5514#include "build/chromeos_buildflags.h"
[email protected]d613a9902011-08-05 20:59:1115#include "crypto/crypto_export.h"
[email protected]bc1e07c72008-09-16 14:32:4416
[email protected]4b559b4d2011-04-14 17:37:1417namespace base {
[email protected]4b559b4d2011-04-14 17:37:1418class Time;
19} // namespace base
20
[email protected]41c78fa2010-03-22 20:08:4121// This file specifically doesn't depend on any NSS or NSPR headers because it
22// is included by various (non-crypto) parts of chrome to call the
23// initialization functions.
[email protected]4b559b4d2011-04-14 17:37:1424namespace crypto {
[email protected]1b1a264a2010-01-14 22:36:3525
[email protected]730fb132009-09-02 22:50:2526// Initialize NRPR if it isn't already initialized. This function is
[email protected]4b559b4d2011-04-14 17:37:1427// thread-safe, and NSPR will only ever be initialized once.
[email protected]d613a9902011-08-05 20:59:1128CRYPTO_EXPORT void EnsureNSPRInit();
[email protected]730fb132009-09-02 22:50:2529
[email protected]bc1e07c72008-09-16 14:32:4430// Initialize NSS if it isn't already initialized. This must be called before
31// any other NSS functions. This function is thread-safe, and NSS will only
[email protected]4b559b4d2011-04-14 17:37:1432// ever be initialized once.
[email protected]d613a9902011-08-05 20:59:1133CRYPTO_EXPORT void EnsureNSSInit();
[email protected]bc1e07c72008-09-16 14:32:4434
[email protected]f61c3972010-12-23 09:54:1535// Check if the current NSS version is greater than or equals to |version|.
36// A sample version string is "3.12.3".
37bool CheckNSSVersion(const char* version);
38
Yuta Hijikatabf953202020-11-12 08:43:5539#if BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]496318862014-07-13 07:19:0040// Indicates that NSS should use the Chaps library so that we
41// can access the TPM through NSS. InitializeTPMTokenAndSystemSlot and
42// InitializeTPMForChromeOSUser must still be called to load the slots.
[email protected]450b4ad72012-05-17 10:04:1743CRYPTO_EXPORT void EnableTPMTokenForNSS();
[email protected]74beead2011-04-12 20:40:1244
[email protected]557737f72013-12-06 22:24:0745// Returns true if EnableTPMTokenForNSS has been called.
46CRYPTO_EXPORT bool IsTPMTokenEnabledForNSS();
47
[email protected]c64b9142011-04-19 18:49:5448// Returns true if the TPM is owned and PKCS#11 initialized with the
49// user and security officer PINs, and has been enabled in NSS by
[email protected]84e47722011-11-17 05:12:0250// calling EnableTPMForNSS, and Chaps has been successfully
[email protected]c64b9142011-04-19 18:49:5451// loaded into NSS.
[email protected]557737f72013-12-06 22:24:0752// If |callback| is non-null and the function returns false, the |callback| will
53// be run once the TPM is ready. |callback| will never be run if the function
54// returns true.
tzik88b34c82018-03-09 05:01:1355CRYPTO_EXPORT bool IsTPMTokenReady(base::OnceClosure callback)
[email protected]557737f72013-12-06 22:24:0756 WARN_UNUSED_RESULT;
[email protected]c175cdb2011-06-28 20:41:5557
[email protected]496318862014-07-13 07:19:0058// Initialize the TPM token and system slot. The |callback| will run on the same
59// thread with true if the token and slot were successfully loaded or were
60// already initialized. |callback| will be passed false if loading failed. Once
61// called, InitializeTPMTokenAndSystemSlot must not be called again until the
62// |callback| has been run.
63CRYPTO_EXPORT void InitializeTPMTokenAndSystemSlot(
64 int system_slot_id,
tzik88b34c82018-03-09 05:01:1365 base::OnceCallback<void(bool)> callback);
[email protected]dcce6cf2010-04-29 17:50:0666#endif
67
[email protected]1b1a264a2010-01-14 22:36:3568// Convert a NSS PRTime value into a base::Time object.
avidd373b8b2015-12-21 21:34:4369// We use a int64_t instead of PRTime here to avoid depending on NSPR headers.
70CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime);
[email protected]1b1a264a2010-01-14 22:36:3571
[email protected]ca929ed32011-12-15 20:37:2872// Convert a base::Time object into a PRTime value.
avidd373b8b2015-12-21 21:34:4373// We use a int64_t instead of PRTime here to avoid depending on NSPR headers.
74CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time);
[email protected]ca929ed32011-12-15 20:37:2875
[email protected]4b559b4d2011-04-14 17:37:1476} // namespace crypto
[email protected]bc1e07c72008-09-16 14:32:4477
[email protected]4b559b4d2011-04-14 17:37:1478#endif // CRYPTO_NSS_UTIL_H_