blob: 17f472a18c6df1b64d63d08d4465413512e0ce93 [file] [log] [blame]
Janis Danisevskisa68669b2017-02-06 11:46:54 +00001/*
2 **
3 ** Copyright 2016, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
Shawn Willden32873522020-12-14 22:29:46 -070018#pragma once
Janis Danisevskisa68669b2017-02-06 11:46:54 +000019
20#include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
21
22#include <hidl/MQDescriptor.h>
23#include <hidl/Status.h>
24
Jim Blackler4515a7f2021-10-11 13:38:59 +000025typedef struct keymaster0_device keymaster0_device_t;
26typedef struct keymaster1_device keymaster1_device_t;
Janis Danisevskisa68669b2017-02-06 11:46:54 +000027typedef struct keymaster2_device keymaster2_device_t;
28
29namespace keymaster {
30class AndroidKeymaster;
31class KeymasterContext;
32
33namespace ng {
34
Shawn Willden32873522020-12-14 22:29:46 -070035using ::android::sp;
36using ::android::hardware::hidl_string;
37using ::android::hardware::hidl_vec;
38using ::android::hardware::Return;
39using ::android::hardware::Void;
Janis Danisevskisa68669b2017-02-06 11:46:54 +000040using ::android::hardware::keymaster::V3_0::ErrorCode;
41using ::android::hardware::keymaster::V3_0::IKeymasterDevice;
42using ::android::hardware::keymaster::V3_0::KeyCharacteristics;
43using ::android::hardware::keymaster::V3_0::KeyFormat;
44using ::android::hardware::keymaster::V3_0::KeyParameter;
45using ::android::hardware::keymaster::V3_0::KeyPurpose;
Janis Danisevskisa68669b2017-02-06 11:46:54 +000046
47enum class KeymasterHardwareProfile : uint32_t {
48 SW,
49 KM0,
50 KM1,
51 KM2,
52};
53
54class AndroidKeymaster3Device : public IKeymasterDevice {
55 public:
56 AndroidKeymaster3Device();
57 AndroidKeymaster3Device(KeymasterContext* context, KeymasterHardwareProfile profile);
58 virtual ~AndroidKeymaster3Device();
59
60 // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.
61 Return<void> getHardwareFeatures(getHardwareFeatures_cb _hidl_cb);
62 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override;
63 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
64 generateKey_cb _hidl_cb) override;
65 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
66 const hidl_vec<uint8_t>& clientId,
67 const hidl_vec<uint8_t>& appData,
68 getKeyCharacteristics_cb _hidl_cb) override;
69 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
70 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override;
71 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
72 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
73 exportKey_cb _hidl_cb) override;
74 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
75 const hidl_vec<KeyParameter>& attestParams,
76 attestKey_cb _hidl_cb) override;
77 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
78 const hidl_vec<KeyParameter>& upgradeParams,
79 upgradeKey_cb _hidl_cb) override;
80 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override;
81 Return<ErrorCode> deleteAllKeys() override;
82 Return<ErrorCode> destroyAttestationIds() override;
83 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
84 const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) override;
85 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
86 const hidl_vec<uint8_t>& input, update_cb _hidl_cb) override;
87 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
88 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
89 finish_cb _hidl_cb) override;
90 Return<ErrorCode> abort(uint64_t operationHandle) override;
91
92 private:
93 std::unique_ptr<::keymaster::AndroidKeymaster> impl_;
94 KeymasterHardwareProfile profile_;
95};
96
97IKeymasterDevice* CreateKeymasterDevice();
98
Janis Danisevskis2fea2352017-07-26 16:52:33 -070099IKeymasterDevice* CreateKeymasterDevice(keymaster2_device_t* km2_device);
Jim Blackler4515a7f2021-10-11 13:38:59 +0000100IKeymasterDevice* CreateKeymasterDevice(keymaster1_device_t* km1_device);
101IKeymasterDevice* CreateKeymasterDevice(keymaster0_device_t* km0_device);
Janis Danisevskis2fea2352017-07-26 16:52:33 -0700102
Janis Danisevskisa68669b2017-02-06 11:46:54 +0000103} // namespace ng
104} // namespace keymaster