From eb586efe6f4ee5ccac2f8eba8ca5cd2d1b112bbc Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Mon, 8 Feb 2021 20:11:49 -0500 Subject: [PATCH] Check for existence of private key before generating OTA At the end of OTA generation, we will use some private key to sign the OTA payload. Since signing happens after the payload is being generated, if caller passes an incorrect key path, caller won't notice it until 1 hour later when delta_generator finishes. At which point caller has to staart from scratch, pass in another key path, and wait for an hour. Let's detect incorrect key path before calling delta_generator, so caller will get an error message right at beginning. Test: th Change-Id: Iefb1e0a9ed86f82664be1675afb84c020ec28fe7 --- tools/releasetools/ota_from_target_files.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 16ade38572..2cbaf373e2 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -1405,6 +1405,13 @@ def main(argv): "build/make/target/product/security/testkey") # Get signing keys OPTIONS.key_passwords = common.GetKeyPasswords([OPTIONS.package_key]) + private_key_path = OPTIONS.package_key + OPTIONS.private_key_suffix + if not os.path.exists(private_key_path): + raise common.ExternalError( + "Private key {} doesn't exist. Make sure you passed the" + " correct key path through -k option".format( + private_key_path) + ) if OPTIONS.source_info_dict: source_build_prop = OPTIONS.source_info_dict["build.prop"]