diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp index 6f506dd213bc887abee91c20b81235af9716e407..d90b99914e2b5a1e4f6686bb4da3ae10893ccba2 100644 --- a/keystore/keystore.cpp +++ b/keystore/keystore.cpp @@ -1156,19 +1156,25 @@ static ResponseCode del_key(KeyStore* keyStore, int, uid_t uid, Value* keyName, return responseCode; } + ResponseCode rc = NO_ERROR; + const keymaster_device_t* device = keyStore->getDevice(); if (device == NULL) { - return SYSTEM_ERROR; + rc = SYSTEM_ERROR; + } else { + // A device doesn't have to implement delete_keypair. + if (device->delete_keypair != NULL) { + if (device->delete_keypair(device, keyBlob.getValue(), keyBlob.getLength())) { + rc = SYSTEM_ERROR; + } + } } - if (device->delete_keypair == NULL) { - ALOGE("device has no delete_keypair implementation!"); - return SYSTEM_ERROR; + if (rc != NO_ERROR) { + return rc; } - int rc = device->delete_keypair(device, keyBlob.getValue(), keyBlob.getLength()); - - return rc ? SYSTEM_ERROR : NO_ERROR; + return (unlink(filename) && errno != ENOENT) ? SYSTEM_ERROR : NO_ERROR; } static ResponseCode sign(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value* data,