#!/usr/bin/env python3 # # Copyright (C) 2022 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
import common import logging import shlex import argparse import tempfile import zipfile import shutil from common import OPTIONS, OptionHandler from ota_signing_utils import AddSigningArgumentParse
@staticmethod def ParseOptions(o, a): if o in ("-k", "--package_key"):
OPTIONS.package_key = a elif o == "--payload_signer":
OPTIONS.payload_signer = a elif o == "--payload_signer_args":
OPTIONS.payload_signer_args = shlex.split(a) elif o == "--payload_signer_maximum_signature_size":
OPTIONS.payload_signer_maximum_signature_size = a elif o == "--payload_signer_key_size": # TODO(xunchang) remove this option after cleaning up the callers.
logger.warning("The option '--payload_signer_key_size' is deprecated." " Use '--payload_signer_maximum_signature_size' instead.")
OPTIONS.payload_signer_maximum_signature_size = a else: returnFalse returnTrue
class PayloadSigner(object): """A class that wraps the payload signing works.
When generating a Payload, hashes of the payload and metadata files will be
signed with the device key, either by calling an external payload signer or
by calling openssl with the package key. This class provides a unified
interface, so that callers can just call PayloadSigner.Sign().
If an external payload signer has been specified (OPTIONS.payload_signer), it
calls the signer with the provided args (OPTIONS.payload_signer_args). Note
that the signing key should be provided as part of the payload_signer_args.
Otherwise without an external signer, it uses the package key
(OPTIONS.package_key) and calls openssl for the signing works. """
def __init__(self, package_key=None, private_key_suffix=None, pw=None, payload_signer=None,
payload_signer_args=None, payload_signer_maximum_signature_size=None): if package_key isNone:
package_key = OPTIONS.package_key if private_key_suffix isNone:
private_key_suffix = OPTIONS.private_key_suffix if payload_signer_args isNone:
payload_signer_args = OPTIONS.payload_signer_args if payload_signer_maximum_signature_size isNone:
payload_signer_maximum_signature_size = OPTIONS.payload_signer_maximum_signature_size
if payload_signer isNone: # Prepare the payload signing key.
private_key = package_key + private_key_suffix
def SignOtaPackage(input_path, output_path):
payload_signer = PayloadSigner(
OPTIONS.package_key, OPTIONS.private_key_suffix, None, OPTIONS.payload_signer, OPTIONS.payload_signer_args)
common.ZipExclude(input_path, output_path, [PAYLOAD_BIN, PAYLOAD_PROPERTIES_TXT]) with tempfile.NamedTemporaryFile() as unsigned_payload, zipfile.ZipFile(input_path, "r", allowZip64=True) as zfp: with zfp.open("payload.bin") as payload_fp:
shutil.copyfileobj(payload_fp, unsigned_payload)
unsigned_payload.flush()
signed_payload = payload_signer.SignPayload(unsigned_payload.name)
properties_file = GeneratePayloadProperties(signed_payload) with zipfile.ZipFile(output_path, "a", compression=zipfile.ZIP_STORED, allowZip64=True) as output_zfp:
common.ZipWrite(output_zfp, signed_payload, PAYLOAD_BIN)
common.ZipWrite(output_zfp, properties_file, PAYLOAD_PROPERTIES_TXT)
def main(argv):
parser = argparse.ArgumentParser(
prog=argv[0], description="Given a series of .img files, produces a full OTA package that installs thoese images")
parser.add_argument("input_ota", type=str,
help="Input OTA for signing")
parser.add_argument('output_ota', type=str,
help='Output OTA for the signed package')
parser.add_argument("-v", action="store_true",
help="Enable verbose logging", dest="verbose")
AddSigningArgumentParse(parser)
args = parser.parse_args(argv[1:])
input_ota = args.input_ota
output_ota = args.output_ota if args.verbose:
OPTIONS.verbose = True
common.InitLogging() if args.package_key:
OPTIONS.package_key = args.package_key
logger.info("Re-signing OTA package {}".format(input_ota))
SignOtaPackage(input_ota, output_ota)
if __name__ == "__main__": import sys
main(sys.argv)
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.