Add support of A12 keymaster_key_blob files structure
In A12 keymaster_key_blob format changed
Compared to A11 it contains another new 8 bytes at beginning "pKMblob\0" (in hex 0x704B4D626C6F6200)
We can just ignore them
Change-Id: I8a1701a248be536fdd000b9011122ef954c8e4d1
diff --git a/crypto/fscrypt/KeyStorage.cpp b/crypto/fscrypt/KeyStorage.cpp
index edb23a2..8afc579 100755
--- a/crypto/fscrypt/KeyStorage.cpp
+++ b/crypto/fscrypt/KeyStorage.cpp
@@ -62,6 +62,8 @@
static constexpr uint32_t AUTH_TIMEOUT = 30; // Seconds
+static const std::string kPkmBlob("pKMblob\x00", 8);
+
static const char* kCurrentVersion = "1";
static const char* kRmPath = "/system/bin/rm";
static const char* kSecdiscardPath = "/system/bin/secdiscard";
@@ -247,6 +249,10 @@
auto kmKeyPath = dir + "/" + kFn_keymaster_key_blob;
std::string kmKey;
if (!readFileToString(kmKeyPath, &kmKey)) return KeymasterOperation();
+ // In A12 keymaster_key_blob format changed:
+ // it have useless for us bytes in beginning, so remove them to correctly handle key
+ if (!kmKey.compare(0, kPkmBlob.size(), kPkmBlob))
+ kmKey.erase(0, kPkmBlob.size());
km::AuthorizationSet inParams(keyParams);
inParams.append(opParams.begin(), opParams.end());
for (;;) {
@@ -590,6 +596,10 @@
static bool deleteKey(const std::string& dir) {
std::string kmKey;
if (!readFileToString(dir + "/" + kFn_keymaster_key_blob, &kmKey)) return false;
+ // In A12 keymaster_key_blob format changed:
+ // it have useless for us bytes in beginning, so remove them to correctly handle key
+ if (!kmKey.compare(0, kPkmBlob.size(), kPkmBlob))
+ kmKey.erase(0, kPkmBlob.size());
Keymaster keymaster;
if (!keymaster) return false;
if (!keymaster.deleteKey(kmKey)) return false;