1 /*
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 
18 #define LOG_TAG "android.hardware.keymaster@3.0-impl"
19 
20 #include "include/AndroidKeymaster3Device.h"
21 
22 #include <android/log.h>
23 
24 #include "include/authorization_set.h"
25 
26 #include <keymaster/android_keymaster.h>
27 #include <keymaster/android_keymaster_messages.h>
28 #include <keymaster/contexts/keymaster1_passthrough_context.h>
29 #include <keymaster/contexts/keymaster2_passthrough_context.h>
30 #include <keymaster/contexts/pure_soft_keymaster_context.h>
31 #include <keymaster/contexts/soft_keymaster_context.h>
32 #include <keymaster/keymaster_configuration.h>
33 #include <keymaster/keymaster_enforcement.h>
34 #include <keymaster/km_openssl/soft_keymaster_enforcement.h>
35 
36 using ::keymaster::AbortOperationRequest;
37 using ::keymaster::AbortOperationResponse;
38 using ::keymaster::AddEntropyRequest;
39 using ::keymaster::AddEntropyResponse;
40 using ::keymaster::AttestKeyRequest;
41 using ::keymaster::AttestKeyResponse;
42 using ::keymaster::AuthorizationSet;
43 using ::keymaster::BeginOperationRequest;
44 using ::keymaster::BeginOperationResponse;
45 using ::keymaster::ExportKeyRequest;
46 using ::keymaster::ExportKeyResponse;
47 using ::keymaster::FinishOperationRequest;
48 using ::keymaster::FinishOperationResponse;
49 using ::keymaster::GenerateKeyRequest;
50 using ::keymaster::GenerateKeyResponse;
51 using ::keymaster::GetKeyCharacteristicsRequest;
52 using ::keymaster::GetKeyCharacteristicsResponse;
53 using ::keymaster::ImportKeyRequest;
54 using ::keymaster::ImportKeyResponse;
55 using ::keymaster::UpdateOperationRequest;
56 using ::keymaster::UpdateOperationResponse;
57 
58 namespace keymaster {
59 namespace ng {
60 
61 namespace {
62 
63 constexpr size_t kOperationTableSize = 16;
64 
legacy_enum_conversion(const Tag value)65 inline keymaster_tag_t legacy_enum_conversion(const Tag value) {
66     return keymaster_tag_t(value);
67 }
legacy_enum_conversion(const keymaster_tag_t value)68 inline Tag legacy_enum_conversion(const keymaster_tag_t value) {
69     return Tag(value);
70 }
legacy_enum_conversion(const KeyPurpose value)71 inline keymaster_purpose_t legacy_enum_conversion(const KeyPurpose value) {
72     return keymaster_purpose_t(value);
73 }
legacy_enum_conversion(const KeyFormat value)74 inline keymaster_key_format_t legacy_enum_conversion(const KeyFormat value) {
75     return keymaster_key_format_t(value);
76 }
legacy_enum_conversion(const keymaster_error_t value)77 inline ErrorCode legacy_enum_conversion(const keymaster_error_t value) {
78     return ErrorCode(value);
79 }
80 
typeFromTag(const keymaster_tag_t tag)81 inline keymaster_tag_type_t typeFromTag(const keymaster_tag_t tag) {
82     return keymaster_tag_get_type(tag);
83 }
84 
85 class KmParamSet : public keymaster_key_param_set_t {
86   public:
KmParamSet(const hidl_vec<KeyParameter> & keyParams)87     explicit KmParamSet(const hidl_vec<KeyParameter>& keyParams) {
88         params = new keymaster_key_param_t[keyParams.size()];
89         length = keyParams.size();
90         for (size_t i = 0; i < keyParams.size(); ++i) {
91             auto tag = legacy_enum_conversion(keyParams[i].tag);
92             switch (typeFromTag(tag)) {
93             case KM_ENUM:
94             case KM_ENUM_REP:
95                 params[i] = keymaster_param_enum(tag, keyParams[i].f.integer);
96                 break;
97             case KM_UINT:
98             case KM_UINT_REP:
99                 params[i] = keymaster_param_int(tag, keyParams[i].f.integer);
100                 break;
101             case KM_ULONG:
102             case KM_ULONG_REP:
103                 params[i] = keymaster_param_long(tag, keyParams[i].f.longInteger);
104                 break;
105             case KM_DATE:
106                 params[i] = keymaster_param_date(tag, keyParams[i].f.dateTime);
107                 break;
108             case KM_BOOL:
109                 if (keyParams[i].f.boolValue)
110                     params[i] = keymaster_param_bool(tag);
111                 else
112                     params[i].tag = KM_TAG_INVALID;
113                 break;
114             case KM_BIGNUM:
115             case KM_BYTES:
116                 params[i] =
117                     keymaster_param_blob(tag, &keyParams[i].blob[0], keyParams[i].blob.size());
118                 break;
119             case KM_INVALID:
120             default:
121                 params[i].tag = KM_TAG_INVALID;
122                 /* just skip */
123                 break;
124             }
125         }
126     }
KmParamSet(KmParamSet && other)127     KmParamSet(KmParamSet&& other) : keymaster_key_param_set_t{other.params, other.length} {
128         other.length = 0;
129         other.params = nullptr;
130     }
131     KmParamSet(const KmParamSet&) = delete;
~KmParamSet()132     ~KmParamSet() { delete[] params; }
133 };
134 
kmBlob2hidlVec(const keymaster_key_blob_t & blob)135 inline hidl_vec<uint8_t> kmBlob2hidlVec(const keymaster_key_blob_t& blob) {
136     hidl_vec<uint8_t> result;
137     result.setToExternal(const_cast<unsigned char*>(blob.key_material), blob.key_material_size);
138     return result;
139 }
140 
kmBlob2hidlVec(const keymaster_blob_t & blob)141 inline hidl_vec<uint8_t> kmBlob2hidlVec(const keymaster_blob_t& blob) {
142     hidl_vec<uint8_t> result;
143     result.setToExternal(const_cast<unsigned char*>(blob.data), blob.data_length);
144     return result;
145 }
146 
kmBuffer2hidlVec(const::keymaster::Buffer & buf)147 inline hidl_vec<uint8_t> kmBuffer2hidlVec(const ::keymaster::Buffer& buf) {
148     hidl_vec<uint8_t> result;
149     result.setToExternal(const_cast<unsigned char*>(buf.peek_read()), buf.available_read());
150     return result;
151 }
152 
153 inline static hidl_vec<hidl_vec<uint8_t>>
kmCertChain2Hidl(const keymaster_cert_chain_t & cert_chain)154 kmCertChain2Hidl(const keymaster_cert_chain_t& cert_chain) {
155     hidl_vec<hidl_vec<uint8_t>> result;
156     if (!cert_chain.entry_count || !cert_chain.entries) return result;
157 
158     result.resize(cert_chain.entry_count);
159     for (size_t i = 0; i < cert_chain.entry_count; ++i) {
160         result[i] = kmBlob2hidlVec(cert_chain.entries[i]);
161     }
162 
163     return result;
164 }
165 
kmParamSet2Hidl(const keymaster_key_param_set_t & set)166 static inline hidl_vec<KeyParameter> kmParamSet2Hidl(const keymaster_key_param_set_t& set) {
167     hidl_vec<KeyParameter> result;
168     if (set.length == 0 || set.params == nullptr) return result;
169 
170     result.resize(set.length);
171     keymaster_key_param_t* params = set.params;
172     for (size_t i = 0; i < set.length; ++i) {
173         auto tag = params[i].tag;
174         result[i].tag = legacy_enum_conversion(tag);
175         switch (typeFromTag(tag)) {
176         case KM_ENUM:
177         case KM_ENUM_REP:
178             result[i].f.integer = params[i].enumerated;
179             break;
180         case KM_UINT:
181         case KM_UINT_REP:
182             result[i].f.integer = params[i].integer;
183             break;
184         case KM_ULONG:
185         case KM_ULONG_REP:
186             result[i].f.longInteger = params[i].long_integer;
187             break;
188         case KM_DATE:
189             result[i].f.dateTime = params[i].date_time;
190             break;
191         case KM_BOOL:
192             result[i].f.boolValue = params[i].boolean;
193             break;
194         case KM_BIGNUM:
195         case KM_BYTES:
196             result[i].blob.setToExternal(const_cast<unsigned char*>(params[i].blob.data),
197                                          params[i].blob.data_length);
198             break;
199         case KM_INVALID:
200         default:
201             params[i].tag = KM_TAG_INVALID;
202             /* just skip */
203             break;
204         }
205     }
206     return result;
207 }
208 
addClientAndAppData(const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,::keymaster::AuthorizationSet * params)209 void addClientAndAppData(const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
210                          ::keymaster::AuthorizationSet* params) {
211     params->Clear();
212     if (clientId.size()) {
213         params->push_back(::keymaster::TAG_APPLICATION_ID, clientId.data(), clientId.size());
214     }
215     if (appData.size()) {
216         params->push_back(::keymaster::TAG_APPLICATION_DATA, appData.data(), appData.size());
217     }
218 }
219 
220 }  // anonymous namespace
221 
AndroidKeymaster3Device()222 AndroidKeymaster3Device::AndroidKeymaster3Device()
223     : impl_(new ::keymaster::AndroidKeymaster(
224           []() -> auto {
225               auto context = new PureSoftKeymasterContext(KmVersion::KEYMASTER_3);
226               context->SetSystemVersion(GetOsVersion(), GetOsPatchlevel());
227               return context;
228           }(),
229           kOperationTableSize)),
230       profile_(KeymasterHardwareProfile::SW) {}
231 
AndroidKeymaster3Device(KeymasterContext * context,KeymasterHardwareProfile profile)232 AndroidKeymaster3Device::AndroidKeymaster3Device(KeymasterContext* context,
233                                                  KeymasterHardwareProfile profile)
234     : impl_(new ::keymaster::AndroidKeymaster(context, kOperationTableSize)), profile_(profile) {}
235 
~AndroidKeymaster3Device()236 AndroidKeymaster3Device::~AndroidKeymaster3Device() {}
237 
238 // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.
getHardwareFeatures(getHardwareFeatures_cb _hidl_cb)239 Return<void> AndroidKeymaster3Device::getHardwareFeatures(getHardwareFeatures_cb _hidl_cb) {
240     switch (profile_) {
241     case KeymasterHardwareProfile::KM0:
242         _hidl_cb(true /* is_secure */, false /* supports_ec */,
243                  false /* supports_symmetric_cryptography */, false /* supports_attestation */,
244                  false /* supportsAllDigests */, "SoftwareWrappedKeymaster0Device", "Google");
245         break;
246     case KeymasterHardwareProfile::KM1:
247         _hidl_cb(true /* is_secure */, true /* supports_ec */,
248                  true /* supports_symmetric_cryptography */, false /* supports_attestation */,
249                  false /* supportsAllDigests */, "SoftwareWrappedKeymaster1Device", "Google");
250         break;
251     case KeymasterHardwareProfile::KM2:
252         _hidl_cb(true /* is_secure */, true /* supports_ec */,
253                  true /* supports_symmetric_cryptography */, true /* supports_attestation */,
254                  true /* supportsAllDigests */, "SoftwareWrappedKeymaster2Device", "Google");
255         break;
256     case KeymasterHardwareProfile::SW:
257     default:
258         _hidl_cb(false /* is_secure */, false /* supports_ec */,
259                  false /* supports_symmetric_cryptography */, false /* supports_attestation */,
260                  false /* supportsAllDigests */, "SoftwareKeymasterDevice", "Google");
261         break;
262     }
263     return Void();
264 }
265 
addRngEntropy(const hidl_vec<uint8_t> & data)266 Return<ErrorCode> AndroidKeymaster3Device::addRngEntropy(const hidl_vec<uint8_t>& data) {
267     if (data.size() == 0) return ErrorCode::OK;
268     AddEntropyRequest request(impl_->message_version());
269     request.random_data.Reinitialize(data.data(), data.size());
270 
271     AddEntropyResponse response(impl_->message_version());
272     impl_->AddRngEntropy(request, &response);
273 
274     return legacy_enum_conversion(response.error);
275 }
276 
generateKey(const hidl_vec<KeyParameter> & keyParams,generateKey_cb _hidl_cb)277 Return<void> AndroidKeymaster3Device::generateKey(const hidl_vec<KeyParameter>& keyParams,
278                                                   generateKey_cb _hidl_cb) {
279     GenerateKeyRequest request(impl_->message_version());
280     request.key_description.Reinitialize(KmParamSet(keyParams));
281 
282     GenerateKeyResponse response(impl_->message_version());
283     impl_->GenerateKey(request, &response);
284 
285     KeyCharacteristics resultCharacteristics;
286     hidl_vec<uint8_t> resultKeyBlob;
287     if (response.error == KM_ERROR_OK) {
288         resultKeyBlob = kmBlob2hidlVec(response.key_blob);
289         resultCharacteristics.teeEnforced = kmParamSet2Hidl(response.enforced);
290         resultCharacteristics.softwareEnforced = kmParamSet2Hidl(response.unenforced);
291     }
292     _hidl_cb(legacy_enum_conversion(response.error), resultKeyBlob, resultCharacteristics);
293     return Void();
294 }
295 
getKeyCharacteristics(const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,getKeyCharacteristics_cb _hidl_cb)296 Return<void> AndroidKeymaster3Device::getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
297                                                             const hidl_vec<uint8_t>& clientId,
298                                                             const hidl_vec<uint8_t>& appData,
299                                                             getKeyCharacteristics_cb _hidl_cb) {
300     GetKeyCharacteristicsRequest request(impl_->message_version());
301     request.SetKeyMaterial(keyBlob.data(), keyBlob.size());
302     addClientAndAppData(clientId, appData, &request.additional_params);
303 
304     GetKeyCharacteristicsResponse response(impl_->message_version());
305     impl_->GetKeyCharacteristics(request, &response);
306 
307     KeyCharacteristics resultCharacteristics;
308     if (response.error == KM_ERROR_OK) {
309         resultCharacteristics.teeEnforced = kmParamSet2Hidl(response.enforced);
310         resultCharacteristics.softwareEnforced = kmParamSet2Hidl(response.unenforced);
311     }
312     _hidl_cb(legacy_enum_conversion(response.error), resultCharacteristics);
313     return Void();
314 }
315 
importKey(const hidl_vec<KeyParameter> & params,KeyFormat keyFormat,const hidl_vec<uint8_t> & keyData,importKey_cb _hidl_cb)316 Return<void> AndroidKeymaster3Device::importKey(const hidl_vec<KeyParameter>& params,
317                                                 KeyFormat keyFormat,
318                                                 const hidl_vec<uint8_t>& keyData,
319                                                 importKey_cb _hidl_cb) {
320     ImportKeyRequest request(impl_->message_version());
321     request.key_description.Reinitialize(KmParamSet(params));
322     request.key_format = legacy_enum_conversion(keyFormat);
323     request.key_data = KeymasterKeyBlob(keyData.data(), keyData.size());
324 
325     ImportKeyResponse response(impl_->message_version());
326     impl_->ImportKey(request, &response);
327 
328     KeyCharacteristics resultCharacteristics;
329     hidl_vec<uint8_t> resultKeyBlob;
330     if (response.error == KM_ERROR_OK) {
331         resultKeyBlob = kmBlob2hidlVec(response.key_blob);
332         resultCharacteristics.teeEnforced = kmParamSet2Hidl(response.enforced);
333         resultCharacteristics.softwareEnforced = kmParamSet2Hidl(response.unenforced);
334     }
335     _hidl_cb(legacy_enum_conversion(response.error), resultKeyBlob, resultCharacteristics);
336     return Void();
337 }
338 
exportKey(KeyFormat exportFormat,const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,exportKey_cb _hidl_cb)339 Return<void> AndroidKeymaster3Device::exportKey(KeyFormat exportFormat,
340                                                 const hidl_vec<uint8_t>& keyBlob,
341                                                 const hidl_vec<uint8_t>& clientId,
342                                                 const hidl_vec<uint8_t>& appData,
343                                                 exportKey_cb _hidl_cb) {
344     ExportKeyRequest request(impl_->message_version());
345     request.key_format = legacy_enum_conversion(exportFormat);
346     request.SetKeyMaterial(keyBlob.data(), keyBlob.size());
347     addClientAndAppData(clientId, appData, &request.additional_params);
348 
349     ExportKeyResponse response(impl_->message_version());
350     impl_->ExportKey(request, &response);
351 
352     hidl_vec<uint8_t> resultKeyBlob;
353     if (response.error == KM_ERROR_OK) {
354         resultKeyBlob.setToExternal(response.key_data, response.key_data_length);
355     }
356     _hidl_cb(legacy_enum_conversion(response.error), resultKeyBlob);
357     return Void();
358 }
359 
attestKey(const hidl_vec<uint8_t> & keyToAttest,const hidl_vec<KeyParameter> & attestParams,attestKey_cb _hidl_cb)360 Return<void> AndroidKeymaster3Device::attestKey(const hidl_vec<uint8_t>& keyToAttest,
361                                                 const hidl_vec<KeyParameter>& attestParams,
362                                                 attestKey_cb _hidl_cb) {
363     AttestKeyRequest request(impl_->message_version());
364     request.SetKeyMaterial(keyToAttest.data(), keyToAttest.size());
365     request.attest_params.Reinitialize(KmParamSet(attestParams));
366 
367     AttestKeyResponse response(impl_->message_version());
368     impl_->AttestKey(request, &response);
369 
370     hidl_vec<hidl_vec<uint8_t>> resultCertChain;
371     if (response.error == KM_ERROR_OK) {
372         resultCertChain = kmCertChain2Hidl(response.certificate_chain);
373     }
374     _hidl_cb(legacy_enum_conversion(response.error), resultCertChain);
375     return Void();
376 }
377 
upgradeKey(const hidl_vec<uint8_t> & keyBlobToUpgrade,const hidl_vec<KeyParameter> & upgradeParams,upgradeKey_cb _hidl_cb)378 Return<void> AndroidKeymaster3Device::upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
379                                                  const hidl_vec<KeyParameter>& upgradeParams,
380                                                  upgradeKey_cb _hidl_cb) {
381     // There's nothing to be done to upgrade software key blobs.  Further, the software
382     // implementation never returns ErrorCode::KEY_REQUIRES_UPGRADE, so this should never be called.
383     UpgradeKeyRequest request(impl_->message_version());
384     request.SetKeyMaterial(keyBlobToUpgrade.data(), keyBlobToUpgrade.size());
385     request.upgrade_params.Reinitialize(KmParamSet(upgradeParams));
386 
387     UpgradeKeyResponse response(impl_->message_version());
388     impl_->UpgradeKey(request, &response);
389 
390     if (response.error == KM_ERROR_OK) {
391         _hidl_cb(ErrorCode::OK, kmBlob2hidlVec(response.upgraded_key));
392     } else {
393         _hidl_cb(legacy_enum_conversion(response.error), hidl_vec<uint8_t>());
394     }
395     return Void();
396 }
397 
deleteKey(const hidl_vec<uint8_t> & keyBlob)398 Return<ErrorCode> AndroidKeymaster3Device::deleteKey(const hidl_vec<uint8_t>& keyBlob) {
399     // There's nothing to be done to delete software key blobs.
400     DeleteKeyRequest request(impl_->message_version());
401     request.SetKeyMaterial(keyBlob.data(), keyBlob.size());
402 
403     DeleteKeyResponse response(impl_->message_version());
404     impl_->DeleteKey(request, &response);
405 
406     return legacy_enum_conversion(response.error);
407 }
408 
deleteAllKeys()409 Return<ErrorCode> AndroidKeymaster3Device::deleteAllKeys() {
410     // There's nothing to be done to delete software key blobs.
411     DeleteAllKeysRequest request(impl_->message_version());
412     DeleteAllKeysResponse response(impl_->message_version());
413     impl_->DeleteAllKeys(request, &response);
414 
415     return legacy_enum_conversion(response.error);
416 }
417 
destroyAttestationIds()418 Return<ErrorCode> AndroidKeymaster3Device::destroyAttestationIds() {
419     return ErrorCode::UNIMPLEMENTED;
420 }
421 
begin(KeyPurpose purpose,const hidl_vec<uint8_t> & key,const hidl_vec<KeyParameter> & inParams,begin_cb _hidl_cb)422 Return<void> AndroidKeymaster3Device::begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
423                                             const hidl_vec<KeyParameter>& inParams,
424                                             begin_cb _hidl_cb) {
425 
426     BeginOperationRequest request(impl_->message_version());
427     request.purpose = legacy_enum_conversion(purpose);
428     request.SetKeyMaterial(key.data(), key.size());
429     request.additional_params.Reinitialize(KmParamSet(inParams));
430 
431     BeginOperationResponse response(impl_->message_version());
432     impl_->BeginOperation(request, &response);
433 
434     hidl_vec<KeyParameter> resultParams;
435     if (response.error == KM_ERROR_OK) {
436         resultParams = kmParamSet2Hidl(response.output_params);
437     }
438 
439     _hidl_cb(legacy_enum_conversion(response.error), resultParams, response.op_handle);
440     return Void();
441 }
442 
update(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,update_cb _hidl_cb)443 Return<void> AndroidKeymaster3Device::update(uint64_t operationHandle,
444                                              const hidl_vec<KeyParameter>& inParams,
445                                              const hidl_vec<uint8_t>& input, update_cb _hidl_cb) {
446     UpdateOperationRequest request(impl_->message_version());
447     request.op_handle = operationHandle;
448     request.input.Reinitialize(input.data(), input.size());
449     request.additional_params.Reinitialize(KmParamSet(inParams));
450 
451     UpdateOperationResponse response(impl_->message_version());
452     impl_->UpdateOperation(request, &response);
453 
454     uint32_t resultConsumed = 0;
455     hidl_vec<KeyParameter> resultParams;
456     hidl_vec<uint8_t> resultBlob;
457     if (response.error == KM_ERROR_OK) {
458         resultConsumed = response.input_consumed;
459         resultParams = kmParamSet2Hidl(response.output_params);
460         resultBlob = kmBuffer2hidlVec(response.output);
461     }
462     _hidl_cb(legacy_enum_conversion(response.error), resultConsumed, resultParams, resultBlob);
463     return Void();
464 }
465 
finish(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,const hidl_vec<uint8_t> & signature,finish_cb _hidl_cb)466 Return<void> AndroidKeymaster3Device::finish(uint64_t operationHandle,
467                                              const hidl_vec<KeyParameter>& inParams,
468                                              const hidl_vec<uint8_t>& input,
469                                              const hidl_vec<uint8_t>& signature,
470                                              finish_cb _hidl_cb) {
471     FinishOperationRequest request(impl_->message_version());
472     request.op_handle = operationHandle;
473     request.input.Reinitialize(input.data(), input.size());
474     request.signature.Reinitialize(signature.data(), signature.size());
475     request.additional_params.Reinitialize(KmParamSet(inParams));
476 
477     FinishOperationResponse response(impl_->message_version());
478     impl_->FinishOperation(request, &response);
479 
480     hidl_vec<KeyParameter> resultParams;
481     hidl_vec<uint8_t> resultBlob;
482     if (response.error == KM_ERROR_OK) {
483         resultParams = kmParamSet2Hidl(response.output_params);
484         resultBlob = kmBuffer2hidlVec(response.output);
485     }
486     _hidl_cb(legacy_enum_conversion(response.error), resultParams, resultBlob);
487     return Void();
488 }
489 
abort(uint64_t operationHandle)490 Return<ErrorCode> AndroidKeymaster3Device::abort(uint64_t operationHandle) {
491     AbortOperationRequest request(impl_->message_version());
492     request.op_handle = operationHandle;
493 
494     AbortOperationResponse response(impl_->message_version());
495     impl_->AbortOperation(request, &response);
496 
497     return legacy_enum_conversion(response.error);
498 }
499 
CreateKeymasterDevice()500 IKeymasterDevice* CreateKeymasterDevice() {
501     return new AndroidKeymaster3Device();
502 }
503 
CreateKeymasterDevice(keymaster2_device_t * km2_device)504 IKeymasterDevice* CreateKeymasterDevice(keymaster2_device_t* km2_device) {
505     if (ConfigureDevice(km2_device) != KM_ERROR_OK) return nullptr;
506     auto context = new Keymaster2PassthroughContext(KmVersion::KEYMASTER_3, km2_device);
507     context->SetSystemVersion(GetOsVersion(), GetOsPatchlevel());
508     return new AndroidKeymaster3Device(context, KeymasterHardwareProfile::KM2);
509 }
510 
CreateKeymasterDevice(keymaster1_device_t * km1_device)511 IKeymasterDevice* CreateKeymasterDevice(keymaster1_device_t* km1_device) {
512     auto context = new Keymaster1PassthroughContext(KmVersion::KEYMASTER_3, km1_device);
513     context->SetSystemVersion(GetOsVersion(), GetOsPatchlevel());
514     return new AndroidKeymaster3Device(context, KeymasterHardwareProfile::KM1);
515 }
516 
517 }  // namespace ng
518 }  // namespace keymaster
519