From 764d62e204380d1d9a218b31f5f9b48ae64eaf22 Mon Sep 17 00:00:00 2001 From: "Yan, Shaopu" Date: Thu, 23 Aug 2018 14:47:56 +0800 Subject: add the impementation of delete_key, delete_all_key for Legacy HAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the new layer (Keymaster2PassthroughContext) will call the related function operation, however, currently it’s null so it will have null pointer reference issue and we need to provide them in the keymater legacy HAL. Bug: 113084196 Change-Id: Id1b0df47c03d341aedc7a0634cb101966143641c --- .../legacy/trusty_keymaster_device.h | 2 + .../keymaster/legacy/trusty_keymaster_device.cpp | 43 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'trusty') diff --git a/trusty/keymaster/include/trusty_keymaster/legacy/trusty_keymaster_device.h b/trusty/keymaster/include/trusty_keymaster/legacy/trusty_keymaster_device.h index 5a80795e3..a483c0db6 100644 --- a/trusty/keymaster/include/trusty_keymaster/legacy/trusty_keymaster_device.h +++ b/trusty/keymaster/include/trusty_keymaster/legacy/trusty_keymaster_device.h @@ -80,6 +80,8 @@ class TrustyKeymasterDevice { const keymaster_blob_t* input, const keymaster_blob_t* signature, keymaster_key_param_set_t* out_params, keymaster_blob_t* output); keymaster_error_t abort(keymaster_operation_handle_t operation_handle); + keymaster_error_t delete_key(const keymaster_key_blob_t* key); + keymaster_error_t delete_all_keys(); private: keymaster_error_t Send(uint32_t command, const Serializable& request, diff --git a/trusty/keymaster/legacy/trusty_keymaster_device.cpp b/trusty/keymaster/legacy/trusty_keymaster_device.cpp index ea00a92e0..6c0752275 100644 --- a/trusty/keymaster/legacy/trusty_keymaster_device.cpp +++ b/trusty/keymaster/legacy/trusty_keymaster_device.cpp @@ -70,8 +70,8 @@ TrustyKeymasterDevice::TrustyKeymasterDevice(const hw_module_t* module) { device_.export_key = export_key; device_.attest_key = attest_key; device_.upgrade_key = upgrade_key; - device_.delete_key = nullptr; - device_.delete_all_keys = nullptr; + device_.delete_key = delete_key; + device_.delete_all_keys = delete_all_keys; device_.begin = begin; device_.update = update; device_.finish = finish; @@ -606,6 +606,34 @@ keymaster_error_t TrustyKeymasterDevice::abort(keymaster_operation_handle_t oper return trusty_keymaster_send(KM_ABORT_OPERATION, request, &response); } +keymaster_error_t TrustyKeymasterDevice::delete_key(const keymaster_key_blob_t* key) { + ALOGD("Device received delete_key"); + + if (error_ != KM_ERROR_OK) { + return error_; + } + + if (!key || !key->key_material) + return KM_ERROR_UNEXPECTED_NULL_POINTER; + + DeleteKeyRequest request(message_version_); + request.SetKeyMaterial(*key); + DeleteKeyResponse response(message_version_); + return trusty_keymaster_send(KM_DELETE_KEY, request, &response); +} + +keymaster_error_t TrustyKeymasterDevice::delete_all_keys() { + ALOGD("Device received delete_all_key"); + + if (error_ != KM_ERROR_OK) { + return error_; + } + + DeleteAllKeysRequest request(message_version_); + DeleteAllKeysResponse response(message_version_); + return trusty_keymaster_send(KM_DELETE_ALL_KEYS, request, &response); +} + hw_device_t* TrustyKeymasterDevice::hw_device() { return &device_.common; } @@ -719,4 +747,15 @@ keymaster_error_t TrustyKeymasterDevice::abort(const keymaster2_device_t* dev, return convert_device(dev)->abort(operation_handle); } +/* static */ +keymaster_error_t TrustyKeymasterDevice::delete_key(const keymaster2_device_t* dev, + const keymaster_key_blob_t* key) { + return convert_device(dev)->delete_key(key); +} + +/* static */ +keymaster_error_t TrustyKeymasterDevice::delete_all_keys(const keymaster2_device_t* dev) { + return convert_device(dev)->delete_all_keys(); +} + } // namespace keymaster -- cgit v1.2.3