1 /*
2 **
3 ** Copyright 2019, 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
18 #ifndef HIDL_android_hardware_keymaster_V4_1_AndroidKeymaster4Device_H_
19 #define HIDL_android_hardware_keymaster_V4_1_AndroidKeymaster4Device_H_
20
21 #include <android/hardware/keymaster/4.1/IKeymasterDevice.h>
22 #include <android/hardware/keymaster/4.1/types.h>
23 #include <hidl/Status.h>
24
25 #include "AndroidKeymaster4Device.h"
26
27 namespace keymaster {
28 class AndroidKeymaster;
29 class KeymasterContext;
30
31 namespace V4_1 {
32
33 using ::android::hardware::hidl_vec;
34 using ::android::hardware::Return;
35 using ::android::hardware::Void;
36
37 using ::android::hardware::keymaster::V4_0::ErrorCode;
38 using ::android::hardware::keymaster::V4_0::HardwareAuthenticatorType;
39 using ::android::hardware::keymaster::V4_0::HardwareAuthToken;
40 using ::android::hardware::keymaster::V4_0::HmacSharingParameters;
41 using ::android::hardware::keymaster::V4_0::KeyCharacteristics;
42 using ::android::hardware::keymaster::V4_0::KeyFormat;
43 using ::android::hardware::keymaster::V4_0::KeyParameter;
44 using ::android::hardware::keymaster::V4_0::KeyPurpose;
45 using ::android::hardware::keymaster::V4_0::OperationHandle;
46 using ::android::hardware::keymaster::V4_0::SecurityLevel;
47 using ::android::hardware::keymaster::V4_0::VerificationToken;
48 using ::android::hardware::keymaster::V4_1::IKeymasterDevice;
49 using ::android::hardware::keymaster::V4_1::Tag;
50
51 using V41ErrorCode = ::android::hardware::keymaster::V4_1::ErrorCode;
52
convert(ErrorCode error_code)53 V41ErrorCode convert(ErrorCode error_code) {
54 return static_cast<V41ErrorCode>(error_code);
55 }
56
convert(V41ErrorCode error_code)57 ErrorCode convert(V41ErrorCode error_code) {
58 return static_cast<ErrorCode>(error_code);
59 }
60
61 class AndroidKeymaster41Device : public IKeymasterDevice, public V4_0::ng::AndroidKeymaster4Device {
62 using super = V4_0::ng::AndroidKeymaster4Device;
63
64 public:
AndroidKeymaster41Device(SecurityLevel securityLevel)65 explicit AndroidKeymaster41Device(SecurityLevel securityLevel) : super(securityLevel) {}
~AndroidKeymaster41Device()66 virtual ~AndroidKeymaster41Device() {}
67
68 Return<V41ErrorCode> deviceLocked(bool /* passwordOnly */,
69 const VerificationToken& /* verificationToken */) override;
70 Return<V41ErrorCode> earlyBootEnded() override;
71
getHardwareInfo(super::getHardwareInfo_cb _hidl_cb)72 Return<void> getHardwareInfo(super::getHardwareInfo_cb _hidl_cb) override {
73 return super::getHardwareInfo(_hidl_cb);
74 }
75
getHmacSharingParameters(super::getHmacSharingParameters_cb _hidl_cb)76 Return<void> getHmacSharingParameters(super::getHmacSharingParameters_cb _hidl_cb) override {
77 return super::getHmacSharingParameters(_hidl_cb);
78 }
79
computeSharedHmac(const hidl_vec<HmacSharingParameters> & params,super::computeSharedHmac_cb _hidl_cb)80 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>& params,
81 super::computeSharedHmac_cb _hidl_cb) override {
82 return super::computeSharedHmac(params, _hidl_cb);
83 }
84
verifyAuthorization(uint64_t challenge,const hidl_vec<KeyParameter> & parametersToVerify,const HardwareAuthToken & authToken,super::verifyAuthorization_cb _hidl_cb)85 Return<void> verifyAuthorization(uint64_t challenge,
86 const hidl_vec<KeyParameter>& parametersToVerify,
87 const HardwareAuthToken& authToken,
88 super::verifyAuthorization_cb _hidl_cb) override {
89 return super::verifyAuthorization(challenge, parametersToVerify, authToken, _hidl_cb);
90 }
91
addRngEntropy(const hidl_vec<uint8_t> & data)92 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override {
93 return super::addRngEntropy(data);
94 }
95
generateKey(const hidl_vec<KeyParameter> & keyParams,super::generateKey_cb _hidl_cb)96 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
97 super::generateKey_cb _hidl_cb) override {
98 return super::generateKey(keyParams, _hidl_cb);
99 }
100
getKeyCharacteristics(const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,super::getKeyCharacteristics_cb _hidl_cb)101 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
102 const hidl_vec<uint8_t>& clientId,
103 const hidl_vec<uint8_t>& appData,
104 super::getKeyCharacteristics_cb _hidl_cb) override {
105 return super::getKeyCharacteristics(keyBlob, clientId, appData, _hidl_cb);
106 }
107
importKey(const hidl_vec<KeyParameter> & params,KeyFormat keyFormat,const hidl_vec<uint8_t> & keyData,super::importKey_cb _hidl_cb)108 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
109 const hidl_vec<uint8_t>& keyData,
110 super::importKey_cb _hidl_cb) override {
111 return super::importKey(params, keyFormat, keyData, _hidl_cb);
112 }
113
importWrappedKey(const hidl_vec<uint8_t> & wrappedKeyData,const hidl_vec<uint8_t> & wrappingKeyBlob,const hidl_vec<uint8_t> & maskingKey,const hidl_vec<KeyParameter> & unwrappingParams,uint64_t passwordSid,uint64_t biometricSid,super::importWrappedKey_cb _hidl_cb)114 Return<void> importWrappedKey(const hidl_vec<uint8_t>& wrappedKeyData,
115 const hidl_vec<uint8_t>& wrappingKeyBlob,
116 const hidl_vec<uint8_t>& maskingKey,
117 const hidl_vec<KeyParameter>& unwrappingParams,
118 uint64_t passwordSid, uint64_t biometricSid,
119 super::importWrappedKey_cb _hidl_cb) override {
120 return super::importWrappedKey(wrappedKeyData, wrappingKeyBlob, maskingKey,
121 unwrappingParams, passwordSid, biometricSid, _hidl_cb);
122 }
123
exportKey(KeyFormat exportFormat,const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,super::exportKey_cb _hidl_cb)124 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
125 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
126 super::exportKey_cb _hidl_cb) override {
127 return super::exportKey(exportFormat, keyBlob, clientId, appData, _hidl_cb);
128 }
129
attestKey(const hidl_vec<uint8_t> & keyToAttest,const hidl_vec<KeyParameter> & attestParams,super::attestKey_cb _hidl_cb)130 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
131 const hidl_vec<KeyParameter>& attestParams,
132 super::attestKey_cb _hidl_cb) override {
133 return super::attestKey(keyToAttest, attestParams, _hidl_cb);
134 }
135
upgradeKey(const hidl_vec<uint8_t> & keyBlobToUpgrade,const hidl_vec<KeyParameter> & upgradeParams,super::upgradeKey_cb _hidl_cb)136 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
137 const hidl_vec<KeyParameter>& upgradeParams,
138 super::upgradeKey_cb _hidl_cb) override {
139 return super::upgradeKey(keyBlobToUpgrade, upgradeParams, _hidl_cb);
140 }
141
deleteKey(const hidl_vec<uint8_t> & keyBlob)142 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override {
143 return super::deleteKey(keyBlob);
144 }
145
deleteAllKeys()146 Return<ErrorCode> deleteAllKeys() override { return super::deleteAllKeys(); }
147
destroyAttestationIds()148 Return<ErrorCode> destroyAttestationIds() override { return super::destroyAttestationIds(); }
149
begin(KeyPurpose purpose,const hidl_vec<uint8_t> & key,const hidl_vec<KeyParameter> & inParams,const HardwareAuthToken & authToken,super::begin_cb _hidl_cb)150 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
151 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken,
152 super::begin_cb _hidl_cb) override {
153 return super::begin(purpose, key, inParams, authToken, _hidl_cb);
154 }
155
update(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,const HardwareAuthToken & authToken,const VerificationToken & verificationToken,super::update_cb _hidl_cb)156 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
157 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken,
158 const VerificationToken& verificationToken,
159 super::update_cb _hidl_cb) override {
160 return super::update(operationHandle, inParams, input, authToken, verificationToken,
161 _hidl_cb);
162 }
163
finish(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,const hidl_vec<uint8_t> & signature,const HardwareAuthToken & authToken,const VerificationToken & verificationToken,super::finish_cb _hidl_cb)164 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
165 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
166 const HardwareAuthToken& authToken,
167 const VerificationToken& verificationToken,
168 super::finish_cb _hidl_cb) override {
169 return super::finish(operationHandle, inParams, input, signature, authToken,
170 verificationToken, _hidl_cb);
171 }
172
abort(uint64_t operationHandle)173 Return<ErrorCode> abort(uint64_t operationHandle) override {
174 return super::abort(operationHandle);
175 }
176 };
177
178 IKeymasterDevice* CreateKeymasterDevice(SecurityLevel securityLevel);
179
180 } // namespace V4_1
181 } // namespace keymaster
182
183 #endif // HIDL_android_hardware_keymaster_V4_1_AndroidKeymaster4Device_H_
184