releasetools: Add common.ExtractAvbPublicKey().

Bug: 123716522
Test: python -m unittest test_common
Change-Id: I1f645008a14cc882ef280f169c36e4b14a53ef88
This commit is contained in:
Tao Bao
2019-03-15 10:44:43 -07:00
parent badceb2d60
commit 2cc0ca1770
2 changed files with 26 additions and 7 deletions

View File

@@ -50,7 +50,8 @@ class Options(object):
if base_out_path is None:
base_search_path = "out"
else:
base_search_path = os.path.join(base_out_path, os.path.basename(os.getcwd()))
base_search_path = os.path.join(base_out_path,
os.path.basename(os.getcwd()))
platform_search_path = {
"linux2": os.path.join(base_search_path, "host/linux-x86"),
@@ -552,11 +553,7 @@ def GetAvbChainedPartitionArg(partition, info_dict, key=None):
"""
if key is None:
key = info_dict["avb_" + partition + "_key_path"]
avbtool = os.getenv('AVBTOOL') or info_dict["avb_avbtool"]
pubkey_path = MakeTempFile(prefix="avb-", suffix=".pubkey")
RunAndCheckOutput(
[avbtool, "extract_public_key", "--key", key, "--output", pubkey_path])
pubkey_path = ExtractAvbPublicKey(key)
rollback_index_location = info_dict[
"avb_" + partition + "_rollback_index_location"]
return "{}:{}:{}".format(partition, rollback_index_location, pubkey_path)
@@ -2123,6 +2120,21 @@ def ExtractPublicKey(cert):
return pubkey
def ExtractAvbPublicKey(key):
"""Extracts the AVB public key from the given public or private key.
Args:
key: The input key file, which should be PEM-encoded public or private key.
Returns:
The path to the extracted AVB public key file.
"""
output = MakeTempFile(prefix='avb-', suffix='.avbpubkey')
RunAndCheckOutput(
['avbtool', 'extract_public_key', "--key", key, "--output", output])
return output
def MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img,
info_dict=None):
"""Generates the recovery-from-boot patch and writes the script to output.