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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_NSS_UTIL_H_
6 #define CRYPTO_NSS_UTIL_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "crypto/crypto_export.h"
20 // This file specifically doesn't depend on any NSS or NSPR headers because it
21 // is included by various (non-crypto) parts of chrome to call the
22 // initialization functions.
25 // Initialize NRPR if it isn't already initialized. This function is
26 // thread-safe, and NSPR will only ever be initialized once.
27 CRYPTO_EXPORT void EnsureNSPRInit();
29 // Initialize NSS if it isn't already initialized. This must be called before
30 // any other NSS functions. This function is thread-safe, and NSS will only
31 // ever be initialized once.
32 CRYPTO_EXPORT void EnsureNSSInit();
34 // Check if the current NSS version is greater than or equals to |version|.
35 // A sample version string is "3.12.3".
36 bool CheckNSSVersion(const char* version);
38 #if defined(OS_CHROMEOS)
39 // Indicates that NSS should use the Chaps library so that we
40 // can access the TPM through NSS. InitializeTPMTokenAndSystemSlot and
41 // InitializeTPMForChromeOSUser must still be called to load the slots.
42 CRYPTO_EXPORT void EnableTPMTokenForNSS();
44 // Returns true if EnableTPMTokenForNSS has been called.
45 CRYPTO_EXPORT bool IsTPMTokenEnabledForNSS();
47 // Returns true if the TPM is owned and PKCS#11 initialized with the
48 // user and security officer PINs, and has been enabled in NSS by
49 // calling EnableTPMForNSS, and Chaps has been successfully
51 // If |callback| is non-null and the function returns false, the |callback| will
52 // be run once the TPM is ready. |callback| will never be run if the function
54 CRYPTO_EXPORT bool IsTPMTokenReady(base::OnceClosure callback)
57 // Initialize the TPM token and system slot. The |callback| will run on the same
58 // thread with true if the token and slot were successfully loaded or were
59 // already initialized. |callback| will be passed false if loading failed. Once
60 // called, InitializeTPMTokenAndSystemSlot must not be called again until the
61 // |callback| has been run.
62 CRYPTO_EXPORT void InitializeTPMTokenAndSystemSlot(
64 base::OnceCallback<void(bool)> callback);
67 // Convert a NSS PRTime value into a base::Time object.
68 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers.
69 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime);
71 // Convert a base::Time object into a PRTime value.
72 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers.
73 CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time);
77 #endif // CRYPTO_NSS_UTIL_H_