From d31f36d334d19dc946971a0a59b1003937c1b3c2 Mon Sep 17 00:00:00 2001 From: Paul Crowley Date: Thu, 12 Aug 2021 19:20:40 +0000 Subject: [PATCH 1/2] Revert^2 "Detect factory reset and deleteAllKeys" Revert submission 15536724-revert-15521094-vold-deleteAllKeys-GDJSMLXRVZ Reason for revert: Underlying KM problem fixed Reverted Changes: I8e2621bef:Revert "Detect factory reset and deleteAllKeys" I546b980bb:Revert "Add deleteAllKeys to IKeystoreMaintenance"... I1ed68dd9e:Revert "Allow vold to deleteAllKeys in Keystore" Bug: 187105270 Test: booted Cuttlefish twice Merged-In: 1e6a5f51065173224700d551693867bd33c7e5b9 Change-Id: Id641444b4ebba951aa8c5474ed60844cfaae1e20 --- Keymaster.cpp | 13 +++++++++++++ Keymaster.h | 3 +++ MetadataCrypt.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/Keymaster.cpp b/Keymaster.cpp index 8038681..2314550 100644 --- a/Keymaster.cpp +++ b/Keymaster.cpp @@ -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 diff --git a/Keymaster.h b/Keymaster.h index 1100840..47bf4a2 100644 --- a/Keymaster.h +++ b/Keymaster.h @@ -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 securityLevel; DISALLOW_COPY_AND_ASSIGN(Keymaster); diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp index dc50679..9038e8d 100644 --- a/MetadataCrypt.cpp +++ b/MetadataCrypt.cpp @@ -112,6 +112,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); } From c0a46c81064dd9a632e446c4987145db61874b44 Mon Sep 17 00:00:00 2001 From: Haiping Yang Date: Mon, 23 Aug 2021 01:24:25 +0000 Subject: [PATCH 2/2] Revert "Add ROLLBACK_RESISTANCE tag to key usage" This reverts commit 2601eb7f8c241f9cf24510115e0a572819fd0514. Ignore-AOSP-First: reverted change was introduced in sc-dev Bug: 196887752 Test: R11 boots on master Reason for revert: R11 boot failure on master Change-Id: I8d2f566f3991f30cd65c48d959d26df8b6c85f32 --- KeyStorage.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/KeyStorage.cpp b/KeyStorage.cpp index 93c5c29..472e6b1 100644 --- a/KeyStorage.cpp +++ b/KeyStorage.cpp @@ -379,9 +379,7 @@ 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_ROLLBACK_RESISTANCE) - .Authorization(km::TAG_PURPOSE, km::KeyPurpose::ENCRYPT); + km::AuthorizationSetBuilder().Authorization(km::TAG_PURPOSE, km::KeyPurpose::ENCRYPT); km::AuthorizationSet outParams; auto opHandle = BeginKeymasterOp(keymaster, dir, keyParams, opParams, &outParams); if (!opHandle) return false; @@ -410,7 +408,6 @@ 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;