blob: 5b197a405ebbd60294047defd89bec44db54e588 [file] [log] [blame]
Zentaro Kavanagh43558d92018-10-25 18:11:54 -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_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
20namespace brillo {
21class SecureBlob;
22} // namespace brillo
23
24namespace tpmcrypto {
25
26class Tpm2Impl : public Tpm {
27 public:
28 Tpm2Impl();
Qijiang Fan6bc59e12020-11-11 02:51:06 +090029 Tpm2Impl(const Tpm2Impl&) = delete;
30 Tpm2Impl& operator=(const Tpm2Impl&) = delete;
31
Zentaro Kavanagh43558d92018-10-25 18:11:54 -070032 ~Tpm2Impl() override;
33
34 bool SealToPCR0(const brillo::SecureBlob& value,
Sarthak Kukreti95f75a02019-01-15 18:34:17 -080035 brillo::SecureBlob* sealed_value) override;
Zentaro Kavanagh43558d92018-10-25 18:11:54 -070036
Sarthak Kukreti95f75a02019-01-15 18:34:17 -080037 bool Unseal(const brillo::SecureBlob& sealed_value,
Zentaro Kavanagh43558d92018-10-25 18:11:54 -070038 brillo::SecureBlob* value) override;
39
Amin Hassani3ee8c802018-10-24 17:01:45 -070040 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 Kavanagh43558d92018-10-25 18:11:54 -070046 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 Kukreti95f75a02019-01-15 18:34:17 -080057 brillo::SecureBlob* sealed_value);
Zentaro Kavanagh43558d92018-10-25 18:11:54 -070058 bool UnsealData(trunks::AuthorizationDelegate* policy_delegate,
Sarthak Kukreti95f75a02019-01-15 18:34:17 -080059 const brillo::SecureBlob& sealed_value,
Zentaro Kavanagh43558d92018-10-25 18:11:54 -070060 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 Kavanagh43558d92018-10-25 18:11:54 -070065};
66
67} // namespace tpmcrypto
68
69#endif // LIBTPMCRYPTO_TPM2_IMPL_H_