blob: a1e81d2f417a22f6305450f56e3e9fd18498ded5 [file] [log] [blame]
Jooyung Han504105f2021-10-26 15:54:50 +09001#!/usr/bin/env python
2#
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""sign_virt_apex is a command line tool for sign the Virt APEX file.
17
Jooyung Han98498f42022-02-07 15:23:08 +090018Typical usage:
Jooyung Han486609f2022-04-20 11:38:00 +090019 sign_virt_apex payload_key payload_dir
20 -v, --verbose
21 --verify
22 --avbtool path_to_avbtool
23 --signing_args args
Jooyung Han504105f2021-10-26 15:54:50 +090024
25sign_virt_apex uses external tools which are assumed to be available via PATH.
26- avbtool (--avbtool can override the tool)
27- lpmake, lpunpack, simg2img, img2simg
28"""
29import argparse
Jooyung Han02dceed2021-11-08 17:50:22 +090030import hashlib
Jooyung Han504105f2021-10-26 15:54:50 +090031import os
32import re
Jooyung Han98498f42022-02-07 15:23:08 +090033import shlex
Jooyung Han504105f2021-10-26 15:54:50 +090034import subprocess
35import sys
36import tempfile
Jooyung Han486609f2022-04-20 11:38:00 +090037import traceback
38from concurrent import futures
39
40# pylint: disable=line-too-long,consider-using-with
41
42# Use executor to parallelize the invocation of external tools
43# If a task depends on another, pass the future object of the previous task as wait list.
44# Every future object created by a task should be consumed with AwaitAll()
45# so that exceptions are propagated .
46executor = futures.ThreadPoolExecutor()
47
48# Temporary directory for unpacked super.img.
49# We could put its creation/deletion into the task graph as well, but
50# having it as a global setup is much simpler.
51unpack_dir = tempfile.TemporaryDirectory()
52
53# tasks created with Async() are kept in a list so that they are awaited
54# before exit.
55tasks = []
56
57# create an async task and return a future value of it.
58def Async(fn, *args, wait=None, **kwargs):
59
60 # wrap a function with AwaitAll()
61 def wrapped():
62 AwaitAll(wait)
63 fn(*args, **kwargs)
64
65 task = executor.submit(wrapped)
66 tasks.append(task)
67 return task
68
69
70# waits for task (captured in fs as future values) with future.result()
71# so that any exception raised during task can be raised upward.
72def AwaitAll(fs):
73 if fs:
74 for f in fs:
75 f.result()
Jooyung Han504105f2021-10-26 15:54:50 +090076
77
78def ParseArgs(argv):
79 parser = argparse.ArgumentParser(description='Sign the Virt APEX')
Jooyung Han02dceed2021-11-08 17:50:22 +090080 parser.add_argument('--verify', action='store_true',
81 help='Verify the Virt APEX')
Jooyung Han504105f2021-10-26 15:54:50 +090082 parser.add_argument(
83 '-v', '--verbose',
84 action='store_true',
85 help='verbose execution')
86 parser.add_argument(
87 '--avbtool',
88 default='avbtool',
89 help='Optional flag that specifies the AVB tool to use. Defaults to `avbtool`.')
90 parser.add_argument(
Jooyung Han98498f42022-02-07 15:23:08 +090091 '--signing_args',
92 help='the extra signing arguments passed to avbtool.'
93 )
94 parser.add_argument(
Jooyung Han1c3d2fa2022-02-24 02:35:59 +090095 '--key_override',
96 metavar="filename=key",
97 action='append',
98 help='Overrides a signing key for a file e.g. microdroid_bootloader=mykey (for testing)')
99 parser.add_argument(
Jooyung Han504105f2021-10-26 15:54:50 +0900100 'key',
101 help='path to the private key file.')
102 parser.add_argument(
103 'input_dir',
104 help='the directory having files to be packaged')
Jooyung Han1c3d2fa2022-02-24 02:35:59 +0900105 args = parser.parse_args(argv)
106 # preprocess --key_override into a map
107 args.key_overrides = dict()
108 if args.key_override:
109 for pair in args.key_override:
110 name, key = pair.split('=')
111 args.key_overrides[name] = key
112 return args
Jooyung Han504105f2021-10-26 15:54:50 +0900113
114
Jooyung Han486609f2022-04-20 11:38:00 +0900115def RunCommand(args, cmd, env=None, expected_return_values=None):
116 expected_return_values = expected_return_values or {0}
Jooyung Han504105f2021-10-26 15:54:50 +0900117 env = env or {}
118 env.update(os.environ.copy())
119
120 # TODO(b/193504286): we need a way to find other tool (cmd[0]) in various contexts
121 # e.g. sign_apex.py, sign_target_files_apk.py
122 if cmd[0] == 'avbtool':
123 cmd[0] = args.avbtool
124
125 if args.verbose:
126 print('Running: ' + ' '.join(cmd))
127 p = subprocess.Popen(
128 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, universal_newlines=True)
129 output, _ = p.communicate()
130
131 if args.verbose or p.returncode not in expected_return_values:
132 print(output.rstrip())
133
134 assert p.returncode in expected_return_values, (
135 '%d Failed to execute: ' + ' '.join(cmd)) % p.returncode
136 return (output, p.returncode)
137
138
139def ReadBytesSize(value):
140 return int(value.removesuffix(' bytes'))
141
142
Jooyung Han832d11d2021-11-08 12:51:47 +0900143def ExtractAvbPubkey(args, key, output):
144 RunCommand(args, ['avbtool', 'extract_public_key',
145 '--key', key, '--output', output])
146
147
148def AvbInfo(args, image_path):
Jooyung Han504105f2021-10-26 15:54:50 +0900149 """Parses avbtool --info image output
150
151 Args:
152 args: program arguments.
153 image_path: The path to the image.
154 descriptor_name: Descriptor name of interest.
155
156 Returns:
157 A pair of
158 - a dict that contains VBMeta info. None if there's no VBMeta info.
Jooyung Han832d11d2021-11-08 12:51:47 +0900159 - a list of descriptors.
Jooyung Han504105f2021-10-26 15:54:50 +0900160 """
161 if not os.path.exists(image_path):
162 raise ValueError('Failed to find image: {}'.format(image_path))
163
164 output, ret_code = RunCommand(
165 args, ['avbtool', 'info_image', '--image', image_path], expected_return_values={0, 1})
166 if ret_code == 1:
167 return None, None
168
Jooyung Han832d11d2021-11-08 12:51:47 +0900169 info, descriptors = {}, []
Jooyung Han504105f2021-10-26 15:54:50 +0900170
171 # Read `avbtool info_image` output as "key:value" lines
172 matcher = re.compile(r'^(\s*)([^:]+):\s*(.*)$')
173
174 def IterateLine(output):
175 for line in output.split('\n'):
176 line_info = matcher.match(line)
177 if not line_info:
178 continue
179 yield line_info.group(1), line_info.group(2), line_info.group(3)
180
181 gen = IterateLine(output)
Jooyung Han832d11d2021-11-08 12:51:47 +0900182
183 def ReadDescriptors(cur_indent, cur_name, cur_value):
184 descriptor = cur_value if cur_name == 'Prop' else {}
185 descriptors.append((cur_name, descriptor))
186 for indent, key, value in gen:
187 if indent <= cur_indent:
188 # read descriptors recursively to pass the read key as descriptor name
189 ReadDescriptors(indent, key, value)
190 break
191 descriptor[key] = value
192
Jooyung Han504105f2021-10-26 15:54:50 +0900193 # Read VBMeta info
194 for _, key, value in gen:
195 if key == 'Descriptors':
Jooyung Han832d11d2021-11-08 12:51:47 +0900196 ReadDescriptors(*next(gen))
Jooyung Han504105f2021-10-26 15:54:50 +0900197 break
198 info[key] = value
199
Jooyung Han832d11d2021-11-08 12:51:47 +0900200 return info, descriptors
Jooyung Han504105f2021-10-26 15:54:50 +0900201
Jooyung Han832d11d2021-11-08 12:51:47 +0900202
203# Look up a list of (key, value) with a key. Returns the value of the first matching pair.
204def LookUp(pairs, key):
205 for k, v in pairs:
206 if key == k:
207 return v
208 return None
Jooyung Han504105f2021-10-26 15:54:50 +0900209
210
211def AddHashFooter(args, key, image_path):
Jooyung Han1c3d2fa2022-02-24 02:35:59 +0900212 if os.path.basename(image_path) in args.key_overrides:
213 key = args.key_overrides[os.path.basename(image_path)]
Jooyung Han832d11d2021-11-08 12:51:47 +0900214 info, descriptors = AvbInfo(args, image_path)
Jooyung Han504105f2021-10-26 15:54:50 +0900215 if info:
Jooyung Han832d11d2021-11-08 12:51:47 +0900216 descriptor = LookUp(descriptors, 'Hash descriptor')
Jooyung Han504105f2021-10-26 15:54:50 +0900217 image_size = ReadBytesSize(info['Image size'])
218 algorithm = info['Algorithm']
219 partition_name = descriptor['Partition Name']
220 partition_size = str(image_size)
221
222 cmd = ['avbtool', 'add_hash_footer',
223 '--key', key,
224 '--algorithm', algorithm,
225 '--partition_name', partition_name,
226 '--partition_size', partition_size,
227 '--image', image_path]
Jooyung Han98498f42022-02-07 15:23:08 +0900228 if args.signing_args:
229 cmd.extend(shlex.split(args.signing_args))
Jooyung Han504105f2021-10-26 15:54:50 +0900230 RunCommand(args, cmd)
231
232
233def AddHashTreeFooter(args, key, image_path):
Jooyung Han1c3d2fa2022-02-24 02:35:59 +0900234 if os.path.basename(image_path) in args.key_overrides:
235 key = args.key_overrides[os.path.basename(image_path)]
Jooyung Han832d11d2021-11-08 12:51:47 +0900236 info, descriptors = AvbInfo(args, image_path)
Jooyung Han504105f2021-10-26 15:54:50 +0900237 if info:
Jooyung Han832d11d2021-11-08 12:51:47 +0900238 descriptor = LookUp(descriptors, 'Hashtree descriptor')
Jooyung Han504105f2021-10-26 15:54:50 +0900239 image_size = ReadBytesSize(info['Image size'])
240 algorithm = info['Algorithm']
241 partition_name = descriptor['Partition Name']
242 partition_size = str(image_size)
243
244 cmd = ['avbtool', 'add_hashtree_footer',
245 '--key', key,
246 '--algorithm', algorithm,
247 '--partition_name', partition_name,
248 '--partition_size', partition_size,
249 '--do_not_generate_fec',
250 '--image', image_path]
Jooyung Han98498f42022-02-07 15:23:08 +0900251 if args.signing_args:
252 cmd.extend(shlex.split(args.signing_args))
Jooyung Han504105f2021-10-26 15:54:50 +0900253 RunCommand(args, cmd)
254
255
Jooyung Han832d11d2021-11-08 12:51:47 +0900256def MakeVbmetaImage(args, key, vbmeta_img, images=None, chained_partitions=None):
Jooyung Han1c3d2fa2022-02-24 02:35:59 +0900257 if os.path.basename(vbmeta_img) in args.key_overrides:
258 key = args.key_overrides[os.path.basename(vbmeta_img)]
Jooyung Han832d11d2021-11-08 12:51:47 +0900259 info, descriptors = AvbInfo(args, vbmeta_img)
260 if info is None:
261 return
262
Jooyung Han486609f2022-04-20 11:38:00 +0900263 with tempfile.TemporaryDirectory() as work_dir:
Jooyung Han504105f2021-10-26 15:54:50 +0900264 algorithm = info['Algorithm']
265 rollback_index = info['Rollback Index']
266 rollback_index_location = info['Rollback Index Location']
267
268 cmd = ['avbtool', 'make_vbmeta_image',
269 '--key', key,
270 '--algorithm', algorithm,
271 '--rollback_index', rollback_index,
272 '--rollback_index_location', rollback_index_location,
273 '--output', vbmeta_img]
Jooyung Han832d11d2021-11-08 12:51:47 +0900274 if images:
275 for img in images:
276 cmd.extend(['--include_descriptors_from_image', img])
277
278 # replace pubkeys of chained_partitions as well
279 for name, descriptor in descriptors:
280 if name == 'Chain Partition descriptor':
281 part_name = descriptor['Partition Name']
282 ril = descriptor['Rollback Index Location']
283 part_key = chained_partitions[part_name]
284 avbpubkey = os.path.join(work_dir, part_name + '.avbpubkey')
285 ExtractAvbPubkey(args, part_key, avbpubkey)
286 cmd.extend(['--chain_partition', '%s:%s:%s' %
287 (part_name, ril, avbpubkey)])
288
Jooyung Han98498f42022-02-07 15:23:08 +0900289 if args.signing_args:
290 cmd.extend(shlex.split(args.signing_args))
291
Jooyung Han504105f2021-10-26 15:54:50 +0900292 RunCommand(args, cmd)
293 # libavb expects to be able to read the maximum vbmeta size, so we must provide a partition
294 # which matches this or the read will fail.
Jooyung Handcb0b492022-02-26 09:04:17 +0900295 with open(vbmeta_img, 'a') as f:
296 f.truncate(65536)
Jooyung Han504105f2021-10-26 15:54:50 +0900297
298
Jooyung Han486609f2022-04-20 11:38:00 +0900299def UnpackSuperImg(args, super_img, work_dir):
300 tmp_super_img = os.path.join(work_dir, 'super.img')
301 RunCommand(args, ['simg2img', super_img, tmp_super_img])
302 RunCommand(args, ['lpunpack', tmp_super_img, work_dir])
Jooyung Han504105f2021-10-26 15:54:50 +0900303
304
305def MakeSuperImage(args, partitions, output):
Jooyung Han486609f2022-04-20 11:38:00 +0900306 with tempfile.TemporaryDirectory() as work_dir:
Jooyung Han504105f2021-10-26 15:54:50 +0900307 cmd = ['lpmake', '--device-size=auto', '--metadata-slots=2', # A/B
308 '--metadata-size=65536', '--sparse', '--output=' + output]
309
310 for part, img in partitions.items():
311 tmp_img = os.path.join(work_dir, part)
312 RunCommand(args, ['img2simg', img, tmp_img])
313
314 image_arg = '--image=%s=%s' % (part, img)
315 partition_arg = '--partition=%s:readonly:%d:default' % (
316 part, os.path.getsize(img))
317 cmd.extend([image_arg, partition_arg])
318
319 RunCommand(args, cmd)
320
321
Jooyung Han486609f2022-04-20 11:38:00 +0900322def SignSuperImg(args, key, super_img, work_dir):
323 # unpack super.img
324 UnpackSuperImg(args, super_img, work_dir)
325
326 system_a_img = os.path.join(work_dir, 'system_a.img')
327 vendor_a_img = os.path.join(work_dir, 'vendor_a.img')
328
329 # re-sign each partition
330 system_a_f = Async(AddHashTreeFooter, args, key, system_a_img)
331 vendor_a_f = Async(AddHashTreeFooter, args, key, vendor_a_img)
332
333 # 3. re-pack super.img
334 partitions = {"system_a": system_a_img, "vendor_a": vendor_a_img}
335 Async(MakeSuperImage, args, partitions, super_img, wait=[system_a_f, vendor_a_f])
336
337
Jooyung Han31b1c2b2021-10-27 03:35:42 +0900338def ReplaceBootloaderPubkey(args, key, bootloader, bootloader_pubkey):
Jooyung Han1c3d2fa2022-02-24 02:35:59 +0900339 if os.path.basename(bootloader) in args.key_overrides:
340 key = args.key_overrides[os.path.basename(bootloader)]
Jooyung Han31b1c2b2021-10-27 03:35:42 +0900341 # read old pubkey before replacement
342 with open(bootloader_pubkey, 'rb') as f:
343 old_pubkey = f.read()
344
Jooyung Han832d11d2021-11-08 12:51:47 +0900345 # replace bootloader pubkey (overwrite the old one with the new one)
346 ExtractAvbPubkey(args, key, bootloader_pubkey)
Jooyung Han31b1c2b2021-10-27 03:35:42 +0900347
348 # read new pubkey
349 with open(bootloader_pubkey, 'rb') as f:
350 new_pubkey = f.read()
351
352 assert len(old_pubkey) == len(new_pubkey)
353
354 # replace pubkey embedded in bootloader
355 with open(bootloader, 'r+b') as bl_f:
356 pos = bl_f.read().find(old_pubkey)
357 assert pos != -1
358 bl_f.seek(pos)
359 bl_f.write(new_pubkey)
360
361
Jooyung Han486609f2022-04-20 11:38:00 +0900362# dict of (key, file) for re-sign/verification. keys are un-versioned for readability.
363virt_apex_files = {
364 'bootloader.pubkey': 'etc/microdroid_bootloader.avbpubkey',
365 'bootloader': 'etc/microdroid_bootloader',
366 'boot.img': 'etc/fs/microdroid_boot-5.10.img',
367 'vendor_boot.img': 'etc/fs/microdroid_vendor_boot-5.10.img',
368 'init_boot.img': 'etc/fs/microdroid_init_boot.img',
369 'super.img': 'etc/fs/microdroid_super.img',
370 'vbmeta.img': 'etc/fs/microdroid_vbmeta.img',
371 'vbmeta_bootconfig.img': 'etc/fs/microdroid_vbmeta_bootconfig.img',
372 'bootconfig.normal': 'etc/microdroid_bootconfig.normal',
373 'bootconfig.app_debuggable': 'etc/microdroid_bootconfig.app_debuggable',
374 'bootconfig.full_debuggable': 'etc/microdroid_bootconfig.full_debuggable',
375 'uboot_env.img': 'etc/uboot_env.img'
376}
377
378
379def TargetFiles(input_dir):
380 return {k: os.path.join(input_dir, v) for k, v in virt_apex_files.items()}
381
382
Jooyung Han504105f2021-10-26 15:54:50 +0900383def SignVirtApex(args):
384 key = args.key
385 input_dir = args.input_dir
Jooyung Han486609f2022-04-20 11:38:00 +0900386 files = TargetFiles(input_dir)
Jooyung Han504105f2021-10-26 15:54:50 +0900387
Jooyung Han486609f2022-04-20 11:38:00 +0900388 # unpacked files (will be unpacked from super.img below)
389 system_a_img = os.path.join(unpack_dir.name, 'system_a.img')
390 vendor_a_img = os.path.join(unpack_dir.name, 'vendor_a.img')
Jooyung Han504105f2021-10-26 15:54:50 +0900391
Jooyung Han486609f2022-04-20 11:38:00 +0900392 # Key(pubkey) embedded in bootloader should match with the one used to make VBmeta below
Jooyung Han31b1c2b2021-10-27 03:35:42 +0900393 # while it's okay to use different keys for other image files.
Jooyung Han486609f2022-04-20 11:38:00 +0900394 replace_f = Async(ReplaceBootloaderPubkey, args,
395 key, files['bootloader'], files['bootloader.pubkey'])
Jooyung Han31b1c2b2021-10-27 03:35:42 +0900396
Devin Mooredc9158e2022-01-10 18:51:12 +0000397 # re-sign bootloader, boot.img, vendor_boot.img, and init_boot.img
Jooyung Han486609f2022-04-20 11:38:00 +0900398 Async(AddHashFooter, args, key, files['bootloader'], wait=[replace_f])
399 boot_img_f = Async(AddHashFooter, args, key, files['boot.img'])
400 vendor_boot_img_f = Async(AddHashFooter, args, key, files['vendor_boot.img'])
401 init_boot_img_f = Async(AddHashFooter, args, key, files['init_boot.img'])
Jooyung Han504105f2021-10-26 15:54:50 +0900402
403 # re-sign super.img
Jooyung Han486609f2022-04-20 11:38:00 +0900404 super_img_f = Async(SignSuperImg, args, key, files['super.img'], unpack_dir.name)
Jooyung Han504105f2021-10-26 15:54:50 +0900405
Jooyung Han486609f2022-04-20 11:38:00 +0900406 # re-generate vbmeta from re-signed {boot, vendor_boot, init_boot, system_a, vendor_a}.img
407 Async(MakeVbmetaImage, args, key, files['vbmeta.img'],
408 images=[files['boot.img'], files['vendor_boot.img'],
409 files['init_boot.img'], system_a_img, vendor_a_img],
410 wait=[boot_img_f, vendor_boot_img_f, init_boot_img_f, super_img_f])
Jooyung Han504105f2021-10-26 15:54:50 +0900411
Jiyong Park34ad9182022-01-28 21:29:48 +0900412 # Re-sign bootconfigs and the uboot_env with the same key
Jooyung Han832d11d2021-11-08 12:51:47 +0900413 bootconfig_sign_key = key
Jooyung Han486609f2022-04-20 11:38:00 +0900414 Async(AddHashFooter, args, bootconfig_sign_key, files['bootconfig.normal'])
415 Async(AddHashFooter, args, bootconfig_sign_key, files['bootconfig.app_debuggable'])
416 Async(AddHashFooter, args, bootconfig_sign_key, files['bootconfig.full_debuggable'])
417 Async(AddHashFooter, args, bootconfig_sign_key, files['uboot_env.img'])
Jooyung Han832d11d2021-11-08 12:51:47 +0900418
Jiyong Park34ad9182022-01-28 21:29:48 +0900419 # Re-sign vbmeta_bootconfig with chained_partitions to "bootconfig" and
420 # "uboot_env". Note that, for now, `key` and `bootconfig_sign_key` are the
421 # same, but technically they can be different. Vbmeta records pubkeys which
422 # signed chained partitions.
Jooyung Han486609f2022-04-20 11:38:00 +0900423 Async(MakeVbmetaImage, args, key, files['vbmeta_bootconfig.img'], chained_partitions={
424 'bootconfig': bootconfig_sign_key,
425 'uboot_env': bootconfig_sign_key,
Jiyong Park34ad9182022-01-28 21:29:48 +0900426 })
Jooyung Han832d11d2021-11-08 12:51:47 +0900427
Jooyung Han504105f2021-10-26 15:54:50 +0900428
Jooyung Han02dceed2021-11-08 17:50:22 +0900429def VerifyVirtApex(args):
Jooyung Han486609f2022-04-20 11:38:00 +0900430 key = args.key
431 input_dir = args.input_dir
432 files = TargetFiles(input_dir)
Jooyung Han02dceed2021-11-08 17:50:22 +0900433
Jooyung Han486609f2022-04-20 11:38:00 +0900434 # unpacked files
435 UnpackSuperImg(args, files['super.img'], unpack_dir.name)
436 system_a_img = os.path.join(unpack_dir.name, 'system_a.img')
437 vendor_a_img = os.path.join(unpack_dir.name, 'vendor_a.img')
Jooyung Han02dceed2021-11-08 17:50:22 +0900438
Jooyung Han486609f2022-04-20 11:38:00 +0900439 # Read pubkey digest from the input key
440 with tempfile.NamedTemporaryFile() as pubkey_file:
441 ExtractAvbPubkey(args, key, pubkey_file.name)
442 with open(pubkey_file.name, 'rb') as f:
443 pubkey = f.read()
444 pubkey_digest = hashlib.sha1(pubkey).hexdigest()
Jooyung Han02dceed2021-11-08 17:50:22 +0900445
Jooyung Han486609f2022-04-20 11:38:00 +0900446 def contents(file):
447 with open(file, 'rb') as f:
448 return f.read()
Jooyung Han02dceed2021-11-08 17:50:22 +0900449
Jooyung Han486609f2022-04-20 11:38:00 +0900450 def check_equals_pubkey(file):
451 assert contents(file) == pubkey, 'pubkey mismatch: %s' % file
Jooyung Han02dceed2021-11-08 17:50:22 +0900452
Jooyung Han486609f2022-04-20 11:38:00 +0900453 def check_contains_pubkey(file):
454 assert contents(file).find(pubkey) != -1, 'pubkey missing: %s' % file
455
456 def check_avb_pubkey(file):
457 info, _ = AvbInfo(args, file)
458 assert info is not None, 'no avbinfo: %s' % file
459 assert info['Public key (sha1)'] == pubkey_digest, 'pubkey mismatch: %s' % file
460
461 for f in files.values():
462 if f == files['bootloader.pubkey']:
463 Async(check_equals_pubkey, f)
464 elif f == files['bootloader']:
465 Async(check_contains_pubkey, f)
466 elif f == files['super.img']:
467 Async(check_avb_pubkey, system_a_img)
468 Async(check_avb_pubkey, vendor_a_img)
469 else:
470 # Check pubkey for other files using avbtool
471 Async(check_avb_pubkey, f)
Jooyung Han02dceed2021-11-08 17:50:22 +0900472
473
Jooyung Han504105f2021-10-26 15:54:50 +0900474def main(argv):
475 try:
476 args = ParseArgs(argv)
Jooyung Han02dceed2021-11-08 17:50:22 +0900477 if args.verify:
478 VerifyVirtApex(args)
479 else:
480 SignVirtApex(args)
Jooyung Han486609f2022-04-20 11:38:00 +0900481 # ensure all tasks are completed without exceptions
482 AwaitAll(tasks)
483 except: # pylint: disable=bare-except
484 traceback.print_exc()
Jooyung Han504105f2021-10-26 15:54:50 +0900485 sys.exit(1)
486
487
488if __name__ == '__main__':
489 main(sys.argv[1:])