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 62E71C433EF for ; Mon, 21 Mar 2022 19:28:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3846F83B20; Mon, 21 Mar 2022 20:27:38 +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="mFpOuDNS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4444C81B5B; Mon, 21 Mar 2022 19:44:07 +0100 (CET) Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (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 E889983A2B for ; Mon, 21 Mar 2022 19:43:59 +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-x129.google.com with SMTP id w7so26077785lfd.6 for ; Mon, 21 Mar 2022 11:43:59 -0700 (PDT) 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=UsW21P8VVDSZQE4gUIg4E+R+dk1lWY0WEfHksbiEByY=; b=mFpOuDNSAsOeiTZnhTLqtyHeCYCKCGKi1CN9c/mP6f7pSPqIyf867HsCRMuXd7aG3d WEB6iJLiFxkZDNqd/EoEm95NGgWC5/zK7Z+WGawbyLtfen8oF3pvjWv7xK91gtf0DnMf Pi9jSo9+NBYIubnDvQfkTxZ+cYzr2YdMYrBaKCoPmpsFhUinsR4cnuQdk3Sn+CoNZkvu ErDUVvSTCpaj+j5pcyO9tOrpQGZDWYRsGpEZIq3mYm2CfwO0iQF/jhXGuTFrdlwYkpNV PhydXfdzGA9Ea1U/pVBuv9+xGrquxR7COyopTaABYDVAvW0TgCElEZp5w3QwHSN7fhrn mkog== 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=UsW21P8VVDSZQE4gUIg4E+R+dk1lWY0WEfHksbiEByY=; b=Op/ld+4IAvWHr77Pi5CiaSdz2jE1kN6+7WHmRGR3Qrp1TExLdhyUVak1nzh9LKFLn5 iGhunKLmktNfpbIXPcR1f8mFplkYxFMApCLDwjoNkkwwJC9ccp2Xaj13zxLqo7uG+bbP or+NRrv/wEq7XIk4cmXK0JvgJVZQSRx56fOBuYP1URsxB9uEUu//DFaMatFZBOktzAXR 4VyFP5DWyYyIdHHreb2HE/uX8PunQvu4/qilJ1eQfBfukFviFNZsPqO4dbuMlpH1Csji Zf0vvqcDPGTK1qlowZPrYLAC2Fc3K+0nj3lcSRsqkvFnRk+EAWI18cebD8+T8T/JqwQq uliA== X-Gm-Message-State: AOAM531PULS57Ieo588dL+Z/JIRB4EzmM3gZywRXNX9AEx9r3z0vjYOQ Soid79y6C4Ulvu5X32L8K4e46k72Tg4U3llfr0I= X-Google-Smtp-Source: ABdhPJxz5YbN0oNmEAA6pC79sYK0DereeGZdoOHxObe8C/IIzrHgJFrMSwDGGYcFxHdq943wqDz2gg== X-Received: by 2002:a05:6512:b19:b0:446:f1c6:81bd with SMTP id w25-20020a0565120b1900b00446f1c681bdmr15811134lfu.320.1647888239255; Mon, 21 Mar 2022 11:43:59 -0700 (PDT) Received: from localhost.localdomain (93-80-66-251.broadband.corbina.ru. [93.80.66.251]) by smtp.googlemail.com with ESMTPSA id m17-20020ac24251000000b00439fe142a0esm1875041lfl.162.2022.03.21.11.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 11:43:58 -0700 (PDT) From: Ivan Mikhaylov To: Simon Glass , Jan Kiszka Cc: u-boot@lists.denx.de, Ivan Mikhaylov , Ivan Mikhaylov Subject: [PATCH 3/3] binman: add test for sign option Date: Mon, 21 Mar 2022 21:43:19 +0000 Message-Id: <20220321214319.33254-4-fr0st61te@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321214319.33254-1-fr0st61te@gmail.com> References: <20220321214319.33254-1-fr0st61te@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 21 Mar 2022 20:27:26 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Add the test which provides sequence of actions: 1. create the image from binman dts 2. create public and private keys 3. add public key into dtb with fdt_add_pubkey 4. sign image with new sign option 5. check with fit_check_sign Signed-off-by: Ivan Mikhaylov --- tools/binman/ftest.py | 42 +++++++++++++++++++ tools/binman/test/225_fit_sign.dts | 67 ++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tools/binman/test/225_fit_sign.dts diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 8f00db6945..8a3d3720c4 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -3088,6 +3088,48 @@ class TestFunctional(unittest.TestCase): self.assertEqual(len(U_BOOT_DATA), entry.contents_size) self.assertEqual(len(U_BOOT_DATA), entry.size) + def testSignSimple(self): + """Test signing a single file""" + + data = self._DoReadFileRealDtb('225_fit_sign.dts') + + updated_fname = tools.GetOutputFilename('image-updated.bin') + tools.WriteFile(updated_fname, data) + + outdir = os.path.join(self._indir, 'extract') + einfos = control.ExtractEntries(updated_fname, None, outdir, []) + + dtb = tools.GetOutputFilename('source.dtb') + private_key = tools.GetOutputFilename('test_key.key') + public_key = tools.GetOutputFilename('test_key.crt') + fit = tools.GetOutputFilename('fit.fit') + key_dir = tools.GetOutputDir() + + def check_sign(fit, key): + try: + tools.Run('fit_check_sign', '-k', key, '-f', fit) + except: + return False + return True + + is_signed = False + try: + tools.Run('openssl', 'req', '-batch' , '-newkey', 'rsa:4096', + '-sha256', '-new', '-nodes', '-x509', '-keyout', + private_key, '-out', public_key) + tools.Run('fdt_add_pubkey', '-a', 'sha256,rsa4096', '-k', key_dir, + '-n', 'test_key', dtb) + with test_util.capture_sys_output() as (stdout, stderr): + # do sign with private key + self._DoBinman('sign', '-i', updated_fname, '-k', private_key, + '-a', 'sha256,rsa4096', '-f', fit, 'fit') + is_signed = check_sign(fit, dtb) + finally: + shutil.rmtree(key_dir) + + self.assertEqual(is_signed, True) + + def _RunReplaceCmd(self, entry_name, data, decomp=True, allow_resize=True, dts='132_replace.dts'): """Replace an entry in an image diff --git a/tools/binman/test/225_fit_sign.dts b/tools/binman/test/225_fit_sign.dts new file mode 100644 index 0000000000..2bfa826106 --- /dev/null +++ b/tools/binman/test/225_fit_sign.dts @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0x100000>; + allow-repack; + + u-boot { + }; + + fit { + description = "U-Boot"; + offset = <0x10000>; + images { + u-boot-1 { + description = "U-Boot"; + type = "standalone"; + arch = "arm64"; + os = "u-boot"; + compression = "none"; + hash-1 { + algo = "sha256"; + }; + }; + + fdt-1 { + description = "test.dtb"; + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + hash-1 { + algo = "sha256"; + }; + u-boot-spl-dtb { + }; + }; + + }; + + configurations { + default = "conf-1"; + conf-1 { + description = "u-boot with fdt"; + firmware = "u-boot-1"; + fdt = "fdt-1"; + signature-1 { + algo = "sha256,rsa4096"; + key-name-hint = "test_key"; + sign-images = "firmware", "fdt"; + }; + + }; + }; + }; + + u-boot-nodtb { + }; + + fdtmap { + }; + }; +}; -- 2.35.1