summaryrefslogtreecommitdiffstats
path: root/crypto/ext4crypt/KeyStorage4.cpp
diff options
context:
space:
mode:
authorPeter Cai <peter@typeblog.net>2019-05-25 15:12:29 +0200
committerbig biff <bigbiff@teamw.in>2019-09-01 19:34:09 +0200
commit05cd3f86167e7a55fbcf9727ce07297fad59b12d (patch)
tree616eec72cb914c039653ccfc1741ec1c5c9bf339 /crypto/ext4crypt/KeyStorage4.cpp
parentext4crypt: support wrappedkey for FBE (diff)
downloadandroid_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar.gz
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar.bz2
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar.lz
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar.xz
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.tar.zst
android_bootable_recovery-05cd3f86167e7a55fbcf9727ce07297fad59b12d.zip
Diffstat (limited to 'crypto/ext4crypt/KeyStorage4.cpp')
-rw-r--r--crypto/ext4crypt/KeyStorage4.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/crypto/ext4crypt/KeyStorage4.cpp b/crypto/ext4crypt/KeyStorage4.cpp
index cab88a19d..b91d6e46b 100644
--- a/crypto/ext4crypt/KeyStorage4.cpp
+++ b/crypto/ext4crypt/KeyStorage4.cpp
@@ -165,10 +165,28 @@ bool getEphemeralWrappedKey(km::KeyFormat format, KeyBuffer& kmKey, KeyBuffer* k
std::string key_temp;
Keymaster keymaster;
if (!keymaster) return false;
- if (!keymaster.exportKey(format, kmKey, "!", "!", &key_temp)) return false;
- *key = KeyBuffer(key_temp.size());
- memcpy(reinterpret_cast<void*>(key->data()), key_temp.c_str(), key->size());
- return true;
+
+ //Export once, if upgrade needed, upgrade and export again
+ bool export_again = true;
+ while (export_again) {
+ export_again = false;
+ auto ret = keymaster.exportKey(format, kmKey, "!", "!", &key_temp);
+ if (ret == km::ErrorCode::OK) {
+ *key = KeyBuffer(key_temp.size());
+ memcpy(reinterpret_cast<void*>(key->data()), key_temp.c_str(), key->size());
+ return true;
+ }
+ if (ret != km::ErrorCode::KEY_REQUIRES_UPGRADE) return false;
+ LOG(DEBUG) << "Upgrading key";
+ std::string kmKeyStr(reinterpret_cast<const char*>(kmKey.data()), kmKey.size());
+ std::string newKey;
+ if (!keymaster.upgradeKey(kmKeyStr, km::AuthorizationSet(), &newKey)) return false;
+ memcpy(reinterpret_cast<void*>(kmKey.data()), newKey.c_str(), kmKey.size());
+ LOG(INFO) << "Key upgraded";
+ export_again = true;
+ }
+ //Should never come here
+ return false;
}
static std::pair<km::AuthorizationSet, km::HardwareAuthToken> beginParams(