Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Chromium OS 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. |
| 4 | |
| 5 | #ifndef LIBTPMCRYPTO_TPM2_IMPL_H_ |
| 6 | #define LIBTPMCRYPTO_TPM2_IMPL_H_ |
| 7 | |
| 8 | #include <limits> |
| 9 | #include <map> |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | #include <utility> |
| 13 | |
| 14 | #include <base/threading/platform_thread.h> |
| 15 | #include <trunks/trunks_factory.h> |
| 16 | #include <trunks/trunks_factory_impl.h> |
| 17 | |
| 18 | #include "libtpmcrypto/tpm.h" |
| 19 | |
| 20 | namespace brillo { |
| 21 | class SecureBlob; |
| 22 | } // namespace brillo |
| 23 | |
| 24 | namespace tpmcrypto { |
| 25 | |
| 26 | class Tpm2Impl : public Tpm { |
| 27 | public: |
| 28 | Tpm2Impl(); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 29 | Tpm2Impl(const Tpm2Impl&) = delete; |
| 30 | Tpm2Impl& operator=(const Tpm2Impl&) = delete; |
| 31 | |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 32 | ~Tpm2Impl() override; |
| 33 | |
| 34 | bool SealToPCR0(const brillo::SecureBlob& value, |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 35 | brillo::SecureBlob* sealed_value) override; |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 36 | |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 37 | bool Unseal(const brillo::SecureBlob& sealed_value, |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 38 | brillo::SecureBlob* value) override; |
| 39 | |
Amin Hassani | 3ee8c80 | 2018-10-24 17:01:45 -0700 | [diff] [blame] | 40 | bool GetNVAttributes(uint32_t index, uint32_t* attributes) override; |
| 41 | bool NVReadNoAuth(uint32_t index, |
| 42 | uint32_t offset, |
| 43 | size_t size, |
| 44 | std::string* data) override; |
| 45 | |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 46 | private: |
| 47 | // If already initialized this returns true, otherwise attempts to |
| 48 | // initialize and returns whether initialization was successful. |
| 49 | bool EnsureInitialized() WARN_UNUSED_RESULT; |
| 50 | bool CreatePcr0PolicyDigest(std::string* policy_digest); |
| 51 | bool CreateHmacSession(std::unique_ptr<trunks::HmacSession>* hmac_session); |
| 52 | bool CreatePolicySessionForPCR0( |
| 53 | std::unique_ptr<trunks::PolicySession>* policy_session); |
| 54 | bool SealData(trunks::AuthorizationDelegate* session_delegate, |
| 55 | const std::string& policy_digest, |
| 56 | const brillo::SecureBlob& value, |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 57 | brillo::SecureBlob* sealed_value); |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 58 | bool UnsealData(trunks::AuthorizationDelegate* policy_delegate, |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 59 | const brillo::SecureBlob& sealed_value, |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 60 | brillo::SecureBlob* value); |
| 61 | |
| 62 | bool is_initialized_ = false; |
| 63 | std::unique_ptr<trunks::TrunksFactoryImpl> factory_impl_; |
| 64 | std::unique_ptr<trunks::TpmUtility> tpm_utility_; |
Zentaro Kavanagh | 43558d9 | 2018-10-25 18:11:54 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace tpmcrypto |
| 68 | |
| 69 | #endif // LIBTPMCRYPTO_TPM2_IMPL_H_ |