Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -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_TPM1_IMPL_H_ |
| 6 | #define LIBTPMCRYPTO_TPM1_IMPL_H_ |
| 7 | |
| 8 | #include "libtpmcrypto/tpm.h" |
| 9 | |
Amin Hassani | 3ee8c80 | 2018-10-24 17:01:45 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 12 | #include <trousers/tss.h> |
| 13 | |
| 14 | namespace brillo { |
| 15 | class SecureBlob; |
| 16 | } // namespace brillo |
| 17 | |
| 18 | namespace tpmcrypto { |
| 19 | |
| 20 | class Tpm1Impl : public Tpm { |
| 21 | public: |
| 22 | Tpm1Impl(); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 23 | Tpm1Impl(const Tpm1Impl&) = delete; |
| 24 | Tpm1Impl& operator=(const Tpm1Impl&) = delete; |
| 25 | |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 26 | ~Tpm1Impl() override; |
| 27 | |
| 28 | bool SealToPCR0(const brillo::SecureBlob& value, |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 29 | brillo::SecureBlob* sealed_value) override; |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 30 | |
Sarthak Kukreti | 95f75a0 | 2019-01-15 18:34:17 -0800 | [diff] [blame] | 31 | bool Unseal(const brillo::SecureBlob& sealed_value, |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 32 | brillo::SecureBlob* value) override; |
| 33 | |
Amin Hassani | 3ee8c80 | 2018-10-24 17:01:45 -0700 | [diff] [blame] | 34 | bool GetNVAttributes(uint32_t index, uint32_t* attributes) override; |
| 35 | bool NVReadNoAuth(uint32_t index, |
| 36 | uint32_t offset, |
| 37 | size_t size, |
| 38 | std::string* data) override; |
| 39 | |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 40 | private: |
| 41 | // Tries to connect to the TPM |
| 42 | TSS_HCONTEXT ConnectContext(); |
| 43 | |
| 44 | // Connects to the TPM and return its context at |context_handle|. |
| 45 | bool OpenAndConnectTpm(TSS_HCONTEXT* context_handle, TSS_RESULT* result); |
| 46 | |
| 47 | // Gets a handle to the TPM from the specified context |
| 48 | // |
| 49 | // Parameters |
| 50 | // context_handle - The context handle for the TPM session |
| 51 | // tpm_handle (OUT) - The handle for the TPM on success |
| 52 | bool GetTpm(TSS_HCONTEXT context_handle, TSS_HTPM* tpm_handle); |
| 53 | |
| 54 | // Populates |context_handle| with a valid TSS_HCONTEXT and |tpm_handle| with |
| 55 | // its matching TPM object iff the context can be created and a TPM object |
| 56 | // exists in the TSS. |
| 57 | bool ConnectContextAsUser(TSS_HCONTEXT* context_handle, TSS_HTPM* tpm_handle); |
| 58 | |
| 59 | // Gets a handle to the SRK. |
| 60 | bool LoadSrk(TSS_HCONTEXT context_handle, |
| 61 | TSS_HKEY* srk_handle, |
| 62 | TSS_RESULT* result) const; |
Zentaro Kavanagh | 04eb2b0 | 2018-10-25 18:21:22 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace tpmcrypto |
| 66 | |
| 67 | #endif // LIBTPMCRYPTO_TPM1_IMPL_H_ |