• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 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 
18 #include <string>
19 
20 #include <json/json.h>
21 #include <tss2/tss2_tpm2_types.h>
22 
23 #include "host/commands/secure_env/gatekeeper_storage.h"
24 #include "host/commands/secure_env/tpm_resource_manager.h"
25 
26 /**
27  * A GatekeeperStorage fallback implementation that is less secure. It uses an
28  * index file that is signed and encrypted by the TPM and the sensitive data
29  * is contained inside the index file. This file can be deleted or corrupted
30  * to lose access to the data inside, and is also susceptible to replay attacks.
31  * If the index file is replaced with an older version and the secure
32  * environment is restarted, it will still accept the old file with the old
33  * data.
34  *
35  * This class is not thread-safe, and should be synchronized externally if it
36  * is going to be used from multiple threads.
37  */
38 class InsecureFallbackStorage : public GatekeeperStorage {
39 public:
40   InsecureFallbackStorage(TpmResourceManager&, const std::string& index_file);
41   ~InsecureFallbackStorage() = default;
42 
43   bool Allocate(const Json::Value& key, uint16_t size) override;
44   bool HasKey(const Json::Value& key) const override;
45 
46   std::unique_ptr<TPM2B_MAX_NV_BUFFER> Read(const Json::Value& key) const
47       override;
48   bool Write(const Json::Value& key, const TPM2B_MAX_NV_BUFFER& data) override;
49 private:
50   Json::Value* GetEntry(const Json::Value& key);
51   const Json::Value* GetEntry(const Json::Value& key) const;
52 
53   TpmResourceManager& resource_manager_;
54   std::string index_file_;
55   Json::Value index_;
56 };
57