Skip to content

Commit

Permalink
Add support of A12 keymaster_key_blob files structure
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zhenyolka authored and epicX67 committed Nov 14, 2021
1 parent af7bc5c commit c45169e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crypto/fscrypt/KeyStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static constexpr size_t STRETCHED_BYTES = 1 << 6;

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";
Expand Down Expand Up @@ -247,6 +249,10 @@ static KeymasterOperation begin(Keymaster& keymaster, const std::string& dir,
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 (;;) {
Expand Down Expand Up @@ -590,6 +596,10 @@ bool retrieveKey(const std::string& dir, const KeyAuthentication& auth, KeyBuffe
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;
Expand Down

0 comments on commit c45169e

Please sign in to comment.