blob: 22f401e701132cb0856e2d1f8fd9aa24959a722d [file] [log] [blame]
bigbiff7ba75002020-04-11 20:47:09 -04001/*
2 * Copyright (C) 2017 Team Win Recovery 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
17/* To the best of my knowledge there is no native implementation for
18 * Weaver so I made this by looking at the IWeaver.h file that gets
19 * compiled by the build system. I took the information from this header
20 * file and looked at keymaster source to get an idea of the proper way
21 * to write the functions.
22 */
23
24#ifndef TWRP_WEAVER_H
25#define TWRP_WEAVER_H
26
27#include <memory>
28#include <string>
29#include <utility>
30
31#include <android/hardware/weaver/1.0/IWeaver.h>
32#include "Utils.h"
33
34namespace android {
35namespace vold {
36using ::android::hardware::weaver::V1_0::IWeaver;
37
38// Wrapper for a Weaver device
39class Weaver {
40 public:
41 Weaver();
42 // false if we failed to open the weaver device.
43 explicit operator bool() { return mDevice.get() != nullptr; }
44
45 bool GetSlots(uint32_t* slots);
46 bool GetKeySize(uint32_t* keySize);
47 bool GetValueSize(uint32_t* valueSize);
48 // TODO: we should return more information about the status including time delays before the next retry
49 bool WeaverVerify(const uint32_t slot, const void* weaver_key, std::vector<uint8_t>* payload);
50
51 private:
52 sp<hardware::weaver::V1_0::IWeaver> mDevice;
53 hardware::weaver::V1_0::WeaverConfig config;
54 bool GottenConfig;
55
56 bool GetConfig();
57
58 DISALLOW_COPY_AND_ASSIGN(Weaver);
59};
60
61} // namespace vold
62} // namespace android
63
64#endif