keystore: add upgradeKeyBlob call into keystore exportKey.
am: 2c1423111a
Change-Id: If8a056b093b567ea1efeeba45878e2b10bbd7d1b
diff --git a/keystore/key_store_service.cpp b/keystore/key_store_service.cpp
index f2207c0..99a0057 100644
--- a/keystore/key_store_service.cpp
+++ b/keystore/key_store_service.cpp
@@ -874,6 +874,23 @@
}
keymaster_blob_t output = {NULL, 0};
rc = dev->export_key(dev, format, &key, clientId, appData, &output);
+ if (rc == KM_ERROR_KEY_REQUIRES_UPGRADE) {
+ AuthorizationSet upgradeParams;
+ if (clientId && clientId->data && clientId->data_length) {
+ upgradeParams.push_back(TAG_APPLICATION_ID, *clientId);
+ }
+ if (appData && appData->data && appData->data_length) {
+ upgradeParams.push_back(TAG_APPLICATION_DATA, *appData);
+ }
+ rc = upgradeKeyBlob(name, targetUid, upgradeParams, &keyBlob);
+ if (rc != ::NO_ERROR) {
+ result->resultCode = rc;
+ return;
+ }
+ key = {keyBlob.getValue(), static_cast<size_t>(keyBlob.getLength())};
+ rc = dev->export_key(dev, format, &key, clientId, appData, &output);
+ }
+
result->exportData.reset(const_cast<uint8_t*>(output.data));
result->dataLength = output.data_length;
result->resultCode = rc ? rc : ::NO_ERROR;