[email protected] | 0274629 | 2012-01-25 04:37:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 5 | #ifndef CRYPTO_NSS_UTIL_H_ |
6 | #define CRYPTO_NSS_UTIL_H_ | ||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 7 | |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | 6a89ef2 | 2011-04-07 17:34:21 | [diff] [blame] | 10 | #include <string> |
[email protected] | e2ea5ca | 2014-02-27 22:27:21 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame] | 13 | #include "base/macros.h" |
Yuta Hijikata | bf95320 | 2020-11-12 08:43:55 | [diff] [blame^] | 14 | #include "build/chromeos_buildflags.h" |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 15 | #include "crypto/crypto_export.h" |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 16 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 17 | namespace base { |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 18 | class Time; |
19 | } // namespace base | ||||
20 | |||||
[email protected] | 41c78fa | 2010-03-22 20:08:41 | [diff] [blame] | 21 | // 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] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 24 | namespace crypto { |
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 25 | |
[email protected] | 730fb13 | 2009-09-02 22:50:25 | [diff] [blame] | 26 | // Initialize NRPR if it isn't already initialized. This function is |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 27 | // thread-safe, and NSPR will only ever be initialized once. |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 28 | CRYPTO_EXPORT void EnsureNSPRInit(); |
[email protected] | 730fb13 | 2009-09-02 22:50:25 | [diff] [blame] | 29 | |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 30 | // 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] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 32 | // ever be initialized once. |
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 33 | CRYPTO_EXPORT void EnsureNSSInit(); |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 34 | |
[email protected] | f61c397 | 2010-12-23 09:54:15 | [diff] [blame] | 35 | // Check if the current NSS version is greater than or equals to |version|. |
36 | // A sample version string is "3.12.3". | ||||
37 | bool CheckNSSVersion(const char* version); | ||||
38 | |||||
Yuta Hijikata | bf95320 | 2020-11-12 08:43:55 | [diff] [blame^] | 39 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 49631886 | 2014-07-13 07:19:00 | [diff] [blame] | 40 | // 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] | 450b4ad7 | 2012-05-17 10:04:17 | [diff] [blame] | 43 | CRYPTO_EXPORT void EnableTPMTokenForNSS(); |
[email protected] | 74beead | 2011-04-12 20:40:12 | [diff] [blame] | 44 | |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 45 | // Returns true if EnableTPMTokenForNSS has been called. |
46 | CRYPTO_EXPORT bool IsTPMTokenEnabledForNSS(); | ||||
47 | |||||
[email protected] | c64b914 | 2011-04-19 18:49:54 | [diff] [blame] | 48 | // 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] | 84e4772 | 2011-11-17 05:12:02 | [diff] [blame] | 50 | // calling EnableTPMForNSS, and Chaps has been successfully |
[email protected] | c64b914 | 2011-04-19 18:49:54 | [diff] [blame] | 51 | // loaded into NSS. |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 52 | // 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. | ||||
tzik | 88b34c8 | 2018-03-09 05:01:13 | [diff] [blame] | 55 | CRYPTO_EXPORT bool IsTPMTokenReady(base::OnceClosure callback) |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 56 | WARN_UNUSED_RESULT; |
[email protected] | c175cdb | 2011-06-28 20:41:55 | [diff] [blame] | 57 | |
[email protected] | 49631886 | 2014-07-13 07:19:00 | [diff] [blame] | 58 | // 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. | ||||
63 | CRYPTO_EXPORT void InitializeTPMTokenAndSystemSlot( | ||||
64 | int system_slot_id, | ||||
tzik | 88b34c8 | 2018-03-09 05:01:13 | [diff] [blame] | 65 | base::OnceCallback<void(bool)> callback); |
[email protected] | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 66 | #endif |
67 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 68 | // Convert a NSS PRTime value into a base::Time object. |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame] | 69 | // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
70 | CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime); | ||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 71 | |
[email protected] | ca929ed3 | 2011-12-15 20:37:28 | [diff] [blame] | 72 | // Convert a base::Time object into a PRTime value. |
avi | dd373b8b | 2015-12-21 21:34:43 | [diff] [blame] | 73 | // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
74 | CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time); | ||||
[email protected] | ca929ed3 | 2011-12-15 20:37:28 | [diff] [blame] | 75 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 76 | } // namespace crypto |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 77 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 78 | #endif // CRYPTO_NSS_UTIL_H_ |