From 166d819fe47c903f731decd1c77b7f8111e7c6a8 Mon Sep 17 00:00:00 2001 From: Oleksiy Avramchenko Date: Thu, 20 Jan 2022 22:10:52 +0100 Subject: [PATCH] Support relative key path in VerifiedBootVersion2VerityImageBuilder Otatools archive can be unpacked to an arbitrary directory together with bundled external/avb/test/data keys. Calling add_img_to_target_files from a different directory fails to build an image which has avb_{}_key_path pointing to the bundled key since add_hash_footer can't find the key file. Fix this by applying the same logic as in common.AppendAVBSigningArgs. Steps to reproduce: $ . build/envsetup.sh && lunch aosp_cf_arm64_phone-userdebug && make dist $ cd out/dist && rm -rf otatools && unzip otatools.zip -d otatools $ zip -d aosp_cf_arm64_phone-*target_files*.zip IMAGES/system_other.img $ otatools/bin/add_img_to_target_files -a -v -p otatools \ aosp_cf_arm64_phone-target_files-*.zip Bug: 218531463 Test: manual, see "steps to reproduce" above Change-Id: Id3f7cf2678e998ef1beda2b6741944c6455c2404 --- tools/releasetools/verity_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/releasetools/verity_utils.py b/tools/releasetools/verity_utils.py index a08ddbede6..d55ad88d8d 100644 --- a/tools/releasetools/verity_utils.py +++ b/tools/releasetools/verity_utils.py @@ -379,6 +379,11 @@ class VerifiedBootVersion2VerityImageBuilder(VerityImageBuilder): self.avbtool = avbtool self.algorithm = algorithm self.key_path = key_path + if key_path and not os.path.exists(key_path) and OPTIONS.search_path: + new_key_path = os.path.join(OPTIONS.search_path, key_path) + if os.path.exists(new_key_path): + self.key_path = new_key_path + self.salt = salt self.signing_args = signing_args self.image_size = None