Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Reduce OTA tools's dependency on brillo_update_payload" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Aug 26, 2023
2 parents 8c3bb5b + f6fe0a9 commit fb4fb4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
25 changes: 1 addition & 24 deletions tools/releasetools/ota_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,30 +897,7 @@ def Sign(self, payload_signer):
"""
assert isinstance(payload_signer, PayloadSigner)

# 1. Generate hashes of the payload and metadata files.
payload_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
metadata_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
cmd = ["brillo_update_payload", "hash",
"--unsigned_payload", self.payload_file,
"--signature_size", str(payload_signer.maximum_signature_size),
"--metadata_hash_file", metadata_sig_file,
"--payload_hash_file", payload_sig_file]
self._Run(cmd)

# 2. Sign the hashes.
signed_payload_sig_file = payload_signer.SignHashFile(payload_sig_file)
signed_metadata_sig_file = payload_signer.SignHashFile(metadata_sig_file)

# 3. Insert the signatures back into the payload file.
signed_payload_file = common.MakeTempFile(prefix="signed-payload-",
suffix=".bin")
cmd = ["brillo_update_payload", "sign",
"--unsigned_payload", self.payload_file,
"--payload", signed_payload_file,
"--signature_size", str(payload_signer.maximum_signature_size),
"--metadata_signature_file", signed_metadata_sig_file,
"--payload_signature_file", signed_payload_sig_file]
self._Run(cmd)
signed_payload_file = payload_signer.SignPayload(self.payload_file)

self.payload_file = signed_payload_file

Expand Down
23 changes: 11 additions & 12 deletions tools/releasetools/payload_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def SignPayload(self, unsigned_payload):
# 1. Generate hashes of the payload and metadata files.
payload_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
metadata_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
cmd = ["brillo_update_payload", "hash",
"--unsigned_payload", unsigned_payload,
"--signature_size", str(self.maximum_signature_size),
"--metadata_hash_file", metadata_sig_file,
"--payload_hash_file", payload_sig_file]
cmd = ["delta_generator",
"--in_file=" + unsigned_payload,
"--signature_size=" + str(self.maximum_signature_size),
"--out_metadata_hash_file=" + metadata_sig_file,
"--out_hash_file=" + payload_sig_file]
self._Run(cmd)

# 2. Sign the hashes.
Expand All @@ -109,16 +109,15 @@ def SignPayload(self, unsigned_payload):
# 3. Insert the signatures back into the payload file.
signed_payload_file = common.MakeTempFile(prefix="signed-payload-",
suffix=".bin")
cmd = ["brillo_update_payload", "sign",
"--unsigned_payload", unsigned_payload,
"--payload", signed_payload_file,
"--signature_size", str(self.maximum_signature_size),
"--metadata_signature_file", signed_metadata_sig_file,
"--payload_signature_file", signed_payload_sig_file]
cmd = ["delta_generator",
"--in_file=" + unsigned_payload,
"--out_file=" + signed_payload_file,
"--signature_size=" + str(self.maximum_signature_size),
"--metadata_signature_file=" + signed_metadata_sig_file,
"--payload_signature_file=" + signed_payload_sig_file]
self._Run(cmd)
return signed_payload_file


def SignHashFile(self, in_file):
"""Signs the given input file. Returns the output filename."""
out_file = common.MakeTempFile(prefix="signed-", suffix=".bin")
Expand Down

0 comments on commit fb4fb4b

Please sign in to comment.