blob: 19594ec329b7a63dadc538070165f0d25101b4b2 [file] [log] [blame]
Zentaro Kavanagh04eb2b02018-10-25 18:21:22 -07001// 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 Hassani3ee8c802018-10-24 17:01:45 -070010#include <string>
11
Zentaro Kavanagh04eb2b02018-10-25 18:21:22 -070012#include <trousers/tss.h>
13
14namespace brillo {
15class SecureBlob;
16} // namespace brillo
17
18namespace tpmcrypto {
19
20class Tpm1Impl : public Tpm {
21 public:
22 Tpm1Impl();
Qijiang Fan6bc59e12020-11-11 02:51:06 +090023 Tpm1Impl(const Tpm1Impl&) = delete;
24 Tpm1Impl& operator=(const Tpm1Impl&) = delete;
25
Zentaro Kavanagh04eb2b02018-10-25 18:21:22 -070026 ~Tpm1Impl() override;
27
28 bool SealToPCR0(const brillo::SecureBlob& value,
Sarthak Kukreti95f75a02019-01-15 18:34:17 -080029 brillo::SecureBlob* sealed_value) override;
Zentaro Kavanagh04eb2b02018-10-25 18:21:22 -070030
Sarthak Kukreti95f75a02019-01-15 18:34:17 -080031 bool Unseal(const brillo::SecureBlob& sealed_value,
Zentaro Kavanagh04eb2b02018-10-25 18:21:22 -070032 brillo::SecureBlob* value) override;
33
Amin Hassani3ee8c802018-10-24 17:01:45 -070034 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 Kavanagh04eb2b02018-10-25 18:21:22 -070040 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 Kavanagh04eb2b02018-10-25 18:21:22 -070063};
64
65} // namespace tpmcrypto
66
67#endif // LIBTPMCRYPTO_TPM1_IMPL_H_