Android-cuttlefish cvd tool
tpm_storage.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020-2023 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
19
20#include <memory>
21#include <optional>
22#include <string>
23#include <vector>
24
25#include <tss2/tss2_esys.h>
26#include <tss2/tss2_tpm2_types.h>
27#include <json/json.h>
28
31
32namespace cuttlefish {
33namespace secure_env {
34
49 public:
50 TpmStorage(TpmResourceManager& resource_manager, const std::string& index_file);
51
52 Result<bool> HasKey(const std::string& key) const override;
53 Result<ManagedStorageData> Read(const std::string& key) const override;
54 Result<void> Write(const std::string& key, const StorageData& data) override;
55 bool Exists() const override;
56
57 private:
58 Result<std::optional<TPM2_HANDLE>> GetHandle(const std::string& key) const;
59 TPM2_HANDLE GenerateRandomHandle();
60 Result<void> Allocate(const std::string& key, uint16_t size);
61
63 std::string index_file_;
64 Json::Value index_;
65
66 std::string path_;
67};
68
69} // namespace secure_env
70} // namespace cuttlefish
Definition: expected.h:86
Definition: tpm_resource_manager.h:50
Definition: storage.h:58
Definition: tpm_storage.h:48
TpmStorage(TpmResourceManager &resource_manager, const std::string &index_file)
Definition: tpm_storage.cpp:33
TPM2_HANDLE GenerateRandomHandle()
Definition: tpm_storage.cpp:151
TpmResourceManager & resource_manager_
Definition: tpm_storage.h:62
Result< bool > HasKey(const std::string &key) const override
Definition: tpm_storage.cpp:53
Result< void > Allocate(const std::string &key, uint16_t size)
Definition: tpm_storage.cpp:176
std::string path_
Definition: tpm_storage.h:66
Result< std::optional< TPM2_HANDLE > > GetHandle(const std::string &key) const
Definition: tpm_storage.cpp:164
std::string index_file_
Definition: tpm_storage.h:63
Result< void > Write(const std::string &key, const StorageData &data) override
Definition: tpm_storage.cpp:111
Json::Value index_
Definition: tpm_storage.h:64
bool Exists() const override
Definition: tpm_storage.cpp:49
Result< ManagedStorageData > Read(const std::string &key) const override
Definition: tpm_storage.cpp:57
char data[Size]
Definition: incremental_server.cpp:1
uint32_t size
Definition: io.h:2
Definition: alloc_utils.cpp:23
Definition: secure_env_windows_lib.cpp:35
Definition: storage.h:26