Skip to content

Commit

Permalink
Snap for 7652454 from 9b13902 to s-keystone-qcom-release
Browse files Browse the repository at this point in the history
Change-Id: I8b16dd1c84787f14440d6c778dd37536d7a3bc1a
  • Loading branch information
Android Build Coastguard Worker committed Aug 18, 2021
2 parents a88a26f + 9b13902 commit ba17f95
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion KeyStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ static bool encryptWithKeymasterKey(Keymaster& keymaster, const std::string& dir
const km::AuthorizationSet& keyParams,
const KeyBuffer& message, std::string* ciphertext) {
km::AuthorizationSet opParams =
km::AuthorizationSetBuilder().Authorization(km::TAG_PURPOSE, km::KeyPurpose::ENCRYPT);
km::AuthorizationSetBuilder()
.Authorization(km::TAG_ROLLBACK_RESISTANCE)
.Authorization(km::TAG_PURPOSE, km::KeyPurpose::ENCRYPT);
km::AuthorizationSet outParams;
auto opHandle = BeginKeymasterOp(keymaster, dir, keyParams, opParams, &outParams);
if (!opHandle) return false;
Expand Down Expand Up @@ -434,6 +436,7 @@ static bool decryptWithKeymasterKey(Keymaster& keymaster, const std::string& dir
auto bodyAndMac = ciphertext.substr(GCM_NONCE_BYTES);
auto opParams = km::AuthorizationSetBuilder()
.Authorization(km::TAG_NONCE, nonce)
.Authorization(km::TAG_ROLLBACK_RESISTANCE)
.Authorization(km::TAG_PURPOSE, km::KeyPurpose::DECRYPT);
auto opHandle = BeginKeymasterOp(keymaster, dir, keyParams, opParams, nullptr);
if (!opHandle) return false;
Expand Down
13 changes: 13 additions & 0 deletions Keymaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,18 @@ void Keymaster::earlyBootEnded() {
logKeystore2ExceptionIfPresent(rc, "earlyBootEnded");
}

void Keymaster::deleteAllKeys() {
::ndk::SpAIBinder binder(AServiceManager_getService(maintenance_service_name));
auto maint_service = ks2_maint::IKeystoreMaintenance::fromBinder(binder);

if (!maint_service) {
LOG(ERROR) << "Unable to connect to keystore2 maintenance service for deleteAllKeys";
return;
}

auto rc = maint_service->deleteAllKeys();
logKeystore2ExceptionIfPresent(rc, "deleteAllKeys");
}

} // namespace vold
} // namespace android
3 changes: 3 additions & 0 deletions Keymaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class Keymaster {
// be created or used.
static void earlyBootEnded();

// Tell all Keymint devices to delete all rollback-protected keys.
static void deleteAllKeys();

private:
std::shared_ptr<ks2::IKeystoreSecurityLevel> securityLevel;
DISALLOW_COPY_AND_ASSIGN(Keymaster);
Expand Down
11 changes: 11 additions & 0 deletions MetadataCrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ static bool read_key(const std::string& metadata_key_dir, const KeyGeneration& g
auto dir = metadata_key_dir + "/key";
LOG(DEBUG) << "metadata_key_dir/key: " << dir;
if (!MkdirsSync(dir, 0700)) return false;
if (!pathExists(dir)) {
auto delete_all = android::base::GetBoolProperty(
"ro.crypto.metadata_init_delete_all_keys.enabled", false);
if (delete_all) {
LOG(INFO) << "Metadata key does not exist, calling deleteAllKeys";
Keymaster::deleteAllKeys();
} else {
LOG(DEBUG) << "Metadata key does not exist but "
"ro.crypto.metadata_init_delete_all_keys.enabled is false";
}
}
auto temp = metadata_key_dir + "/tmp";
return retrieveOrGenerateKey(dir, temp, kEmptyAuthentication, gen, key);
}
Expand Down

0 comments on commit ba17f95

Please sign in to comment.