From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04721C433F5 for ; Sat, 25 Dec 2021 01:53:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C4F22837CE; Sat, 25 Dec 2021 02:53:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GoGEHH6t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7AF898379C; Fri, 24 Dec 2021 19:23:46 +0100 (CET) Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9F5EB837A4 for ; Fri, 24 Dec 2021 19:23:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=fr0st61te@gmail.com Received: by mail-lf1-x136.google.com with SMTP id bt1so20435270lfb.13 for ; Fri, 24 Dec 2021 10:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/QANfRlcrniQ7BlEbqOpursZ1Djfsau+n/Y6bRBpnpA=; b=GoGEHH6tl0U3/nuXoWykmYZx2/9od/notZ9Og5c4iXFhg1eY2iU6Sg72msO5rEyZlD 0WGJEW5URsUZDZiwptdqc+as0HPFj7eVNvQg2ILIvumt9sP3LaWVLyV399g+TbSaSaGW PujtsM4fxOtosXUmD1wPhJ+4pU3xPqr4s7+C5QXFTNDjaGC/UP8DgML6QgmVGqvUFb7T vYIPHOglrimNeEemFBX5VO9SeZu2yG5rNzinF/jF+8vM9R8wBXQryMtKAscDxXYc5uBZ Bh1N2kfK+FQFafNN0tj1LuBpxOI5DaU9DmritSYOlNjYXrUelJfd5jKEfQbKaKFL6Gd6 lbXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/QANfRlcrniQ7BlEbqOpursZ1Djfsau+n/Y6bRBpnpA=; b=IKfb+E+x+fiGIaV42Z13vLxi8z+9zlKwxd3aSwEKCgHF0nvGRC28YGHrA6hYJpFAb2 podArrBaOqTi6MBdnttFYfr0tq3ttTLcj2zIcRIbIZtdmpMYQK7oTHcRuso2SD3j9Tlu KPBcsJoJAUqKX9UKBHSLjL9Hja7ABOwKpfD/eBkDMbWoMvufF1FofmC5M4K/ENmEqmtl afNoyNHGU/ryOK14ChVvXxVxgKppR3uzmB8Q7aZHKx0yd1BSNuqPAZ45CvaxmDCBYTBo ppHOJck5UcVgDCxjkrYeXtE6ONorW2FOouIAAu/OYgABUhxKE5cPIW0VWtw1xscBek7W CY2g== X-Gm-Message-State: AOAM531HfzrewF10ZOvAGDiAY3cwHGMceIx50kavhgAy7L0LZr/5sfhL je80vLAm2fhMC9DPkhJHVKi70kX29Dgv6A== X-Google-Smtp-Source: ABdhPJwxmrvghy/3r6JN9h2Uq9wVQ7MhcRrMZQQVSsWEcehIe5eR8TQr7BqZz0J1GDV27rAhkv5rMg== X-Received: by 2002:a05:6512:3196:: with SMTP id i22mr6059472lfe.241.1640370221898; Fri, 24 Dec 2021 10:23:41 -0800 (PST) Received: from localhost.localdomain (93-80-65-34.broadband.corbina.ru. [93.80.65.34]) by smtp.googlemail.com with ESMTPSA id f18sm874995lfj.56.2021.12.24.10.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Dec 2021 10:23:41 -0800 (PST) From: Ivan Mikhaylov To: Simon Glass , Jan Kiszka Cc: u-boot@lists.denx.de, Ivan Mikhaylov , Ivan Mikhaylov Subject: [PATCH 1/1] binman: add sign option for binman Date: Fri, 24 Dec 2021 21:23:34 +0000 Message-Id: <20211224212334.7146-2-fr0st61te@gmail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211224212334.7146-1-fr0st61te@gmail.com> References: <20211224212334.7146-1-fr0st61te@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 25 Dec 2021 02:53:23 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Introduce prototype for binman's new option which provides sign and replace sections in binary images. Usage as example: from: mkimage -G privateky -r -o sha256,rsa4096 -F fit@0x280000.fit binman replace -i flash.bin -f fit@0x280000.fit fit@0x280000 to: binman sign -i flash.bin -k privatekey -a sha256,rsa4096 -f fit@0x280000.fit fit@0x280000 Signed-off-by: Ivan Mikhaylov --- tools/binman/cmdline.py | 13 +++++++++++++ tools/binman/control.py | 27 ++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index e73ff78095..c3cfd17d1c 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -113,6 +113,19 @@ controlled by a description in the board device tree.''' replace_parser.add_argument('paths', type=str, nargs='*', help='Paths within file to replace (wildcard)') + sign_parser = subparsers.add_parser('sign', + help='Sign entries in image') + sign_parser.add_argument('-i', '--image', type=str, required=True, + help='Image filename to update') + sign_parser.add_argument('-k', '--key', type=str, required=True, + help='Private key file for sign') + sign_parser.add_argument('-a', '--algo', type=str, required=True, + help='Hash algorithm') + sign_parser.add_argument('-f', '--file', type=str, required=True, + help='Input filename to sign') + sign_parser.add_argument('paths', type=str, nargs='*', + help='Paths within file to sign (wildcard)') + test_parser = subparsers.add_parser('test', help='Run tests') test_parser.add_argument('-P', '--processes', type=int, help='set number of processes to use for running tests') diff --git a/tools/binman/control.py b/tools/binman/control.py index 7da69ba38d..ec0e55f7c3 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -18,6 +18,7 @@ from binman import cbfs_util from binman import elf from patman import command from patman import tout +from patman import tools # List of images we plan to create # Make this global so that it can be referenced from tests @@ -401,6 +402,26 @@ def ReplaceEntries(image_fname, input_fname, indir, entry_paths, AfterReplace(image, allow_resize=allow_resize, write_map=write_map) return image +def MkimageSign(privatekey_fname, algo, input_fname): + tools.Run('mkimage', '-G', privatekey_fname, '-r', '-o', algo, '-F', input_fname) + +def SignEntries(image_fname, input_fname, privatekey_fname, algo, entry_paths): + """Sign and replace the data from one or more entries from input files + + Args: + image_fname: Image filename to process + input_fname: Single input filename to use if replacing one file, None + otherwise + algo: Hashing algorithm + privatekey_fname: Private key filename + + Returns: + List of EntryInfo records that were signed and replaced + """ + + MkimageSign(privatekey_fname, algo, input_fname) + + return ReplaceEntries(image_fname, input_fname, None, entry_paths) def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): """Prepare the images to be processed and select the device tree @@ -575,7 +596,7 @@ def Binman(args): from binman.image import Image from binman import state - if args.cmd in ['ls', 'extract', 'replace']: + if args.cmd in ['ls', 'extract', 'replace', 'sign']: try: tout.Init(args.verbosity) tools.PrepareOutputDir(None) @@ -590,6 +611,10 @@ def Binman(args): ReplaceEntries(args.image, args.filename, args.indir, args.paths, do_compress=not args.compressed, allow_resize=not args.fix_size, write_map=args.map) + + if args.cmd == 'sign': + SignEntries(args.image, args.file, args.key, args.algo, args.paths) + except: raise finally: -- 2.31.1