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 B2C15C433F5 for ; Fri, 25 Feb 2022 15:00:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7870883CF3; Fri, 25 Feb 2022 15:59:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.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=softathome1.onmicrosoft.com header.i=@softathome1.onmicrosoft.com header.b="dyytXXUA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DC52483C55; Fri, 25 Feb 2022 15:58:19 +0100 (CET) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on0623.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e18::623]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3371B83C55 for ; Fri, 25 Feb 2022 15:58:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=philippe.reynes@softathome.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G29UVTFfHYwF2pT4N2fCRo2tgDQCXKsdrQFKorNloKiXkQlnCP0vmigkf9VRCgwaYaOx6iNU8a4p5WGvsuaJSwLsPjTfC/DPvkMsbkfNKJol1N7SQGpuuKsPezGFwmUo+R7LFcndtzl8iVnjFdapJFZG47c/o87KFiy0XHd1IYAWgl1Y5kFcc8f2Yqhi8Q3er25cB3Utr14iswmKFGfqej0M3/wUwDYV4YRpr43Z7RvYpjfPG2p1W0sPiOp+CbtQ5Xv1LryD4gvxfjBYuG/uQhIDAVK9txBO26LJJg0w2mBpA3w4GBydyCE0zf+omppBJBMmWQ924MZfYiS4OClRFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=px6x9OCM03yjhg5xzmpcfBwg10D+CEqOZb7O/IK88ZQ=; b=eZoSwCHW4axMYrWGPWOulT6U9zlJ8ABmrXuNa1AEfUArk8pM1OspbNdqsWO6ZXRPxL4NtWlwKkH5LlADqs/h4uzMT9vQmySSGyh9ougsOZ0d2luTP6ICgx+pz+n1cy1JYfBpHQSA0FrTHduQXPlo05RLAUoJVFx/Uca3W7XkWwvXA3VpHWnG5f41aHd6z0QJFo6eFUaXLdodJUoJ5/0JI+sA8NZ/kxscHw5nnlcbg6aB+m3luts/BOwqwnl0rqinilBax7/Q7uPqxOG+kPJh824zLuq2Ae2BG23BOJ8QGqQFVz0GA4oZeAFbDea3x+yr4JMbdez3sIvs+9azSv7iZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.6.166.170) smtp.rcpttodomain=chromium.org smtp.mailfrom=softathome.com; dmarc=bestguesspass action=none header.from=softathome.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=softathome1.onmicrosoft.com; s=selector1-softathome1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=px6x9OCM03yjhg5xzmpcfBwg10D+CEqOZb7O/IK88ZQ=; b=dyytXXUAobMdlviZEOzZQXGyWR6B523r9fdQ/sGat7jzhhKhF28dFAwO77l12xAm1zUVJfHouyFqCpacccJ6lmC/X95NZJjoaZWH5MIFSKNYxgfP3SP3rPdYIrR84Yzwp7krJuxPPrWcR1e1O2gQA+li7nURSl4TYE4BVje+/NEJYFH+AvDRhFvAwx+ygLcpts3CMibFteTQcq36zGaC+8VGl75EbaKNsVivo1Q/jEYOtmGD/0BJ4ikHZGU9VuonGRV2uQko+tD0S/hbsGRAeSA4CQz7vGsKYEnM35YRDOt+HxpzBjSYjLZkSZJHoCLSLQqewXh72IJ5ds3CySDlSQ== Received: from PR0P264CA0228.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1e::24) by PR1P264MB3712.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:142::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Fri, 25 Feb 2022 14:58:00 +0000 Received: from PR2FRA01FT007.eop-fra01.prod.protection.outlook.com (2603:10a6:100:1e::4) by PR0P264CA0228.outlook.office365.com (2603:10a6:100:1e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Fri, 25 Feb 2022 14:57:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.6.166.170) smtp.mailfrom=softathome.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=softathome.com; Received-SPF: Pass (protection.outlook.com: domain of softathome.com designates 149.6.166.170 as permitted sender) receiver=protection.outlook.com; client-ip=149.6.166.170; helo=proxy.softathome.com; Received: from proxy.softathome.com (149.6.166.170) by PR2FRA01FT007.mail.protection.outlook.com (10.152.48.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Fri, 25 Feb 2022 14:57:59 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id 97DDF1FF30; Fri, 25 Feb 2022 15:57:59 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v6 15/16] cmd: verify: initial import Date: Fri, 25 Feb 2022 15:57:53 +0100 Message-Id: <20220225145754.30217-16-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220225145754.30217-1-philippe.reynes@softathome.com> References: <20220225145754.30217-1-philippe.reynes@softathome.com> X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: b4e50cad-69bb-44d3-0898-08d9f86f3712 X-MS-TrafficTypeDiagnostic: PR1P264MB3712:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 97yuAp3rs4ari4oUKMOk8RZ1ZdCBeMSmp51WZdF6rTn59BLLvq+eMYwDFBv0CYGaC7oMQUSETpxH8aMFb0lqDxeo6bA8VRpKwdllV+CWiAnDhjuMInHfDnfzPCLDRAPJc9peoBlGYEJSpdmTz5NDNzO7dKzfcaVLRsOzZB3jgYE/9ImPDzcXY0UwS4U5h8z0X3EwIgIfRyTFn3SVMkis8J8neg1Fd9BUaVMikVPzrbdZb//SLIYgMgBDI2+s2Z2+vkITNhQEzzhj+xyvaqeVnjJaF5AGAN7v+EJtsRJGDC2fU8D4J8+Vv8VtJTmAJQsEDblPoy4bDUf3A6mzpuebqrs/wpzoOtjn5RIITyOwmtOzWKRI9VCkXaVse3a9mLygmSXlP1EWGTS1aRxFrRhngWV4HoEC34BooxiOv+8U3HOhWd5Y6JhvKFI7sepqnTqeCu3UkA3mG+9Wq6BT7sE/SbAdzoQYTHeGpVpkDnSZXLOvDl5C828G9/I/lj+T7bc71bbWCyByeLfsfzrp5F6AtYlQSwH6x0FKy1f5cMh0dpheqZmreTDAiRnKYpa/jTRCqBWL6iWhWLOvQux03shcjF6R/zlqwFUIBF4fl5NNdLx8CP+rl2es9v3USjUr6RLg15WKiu+IOOMVf4OSWs/8lQrMzW+Muq7ARE5otXtits6biMXbmErfIyMtZ0nhkKmTqc4duAMJ32s7Bdl5CmjGJg== X-Forefront-Antispam-Report: CIP:149.6.166.170; CTRY:FR; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:proxy.softathome.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(82960400001)(426003)(1076003)(6266002)(336012)(107886003)(70206006)(82310400004)(4326008)(26005)(2906002)(2616005)(6966003)(186003)(316002)(86362001)(47076005)(36860700001)(70586007)(8676002)(81166007)(83380400001)(8936002)(44832011)(40460700003)(15650500001)(508600001)(356005)(5660300002)(36756003)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2022 14:57:59.8153 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4e50cad-69bb-44d3-0898-08d9f86f3712 X-MS-Exchange-CrossTenant-Id: aa10e044-e405-4c10-8353-36b4d0cce511 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=aa10e044-e405-4c10-8353-36b4d0cce511; Ip=[149.6.166.170]; Helo=[proxy.softathome.com] X-MS-Exchange-CrossTenant-AuthSource: PR2FRA01FT007.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB3712 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 command verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/verify.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 cmd/verify.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..0460d5c3a0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,13 @@ config CMD_THOR_DOWNLOAD There is no documentation about this within the U-Boot source code but you should be able to find something on the interwebs. +config CMD_VERIFY + bool "verify the global signature" + depends on CMD_BOOTM_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..80e054e806 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -177,6 +177,7 @@ obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_XIMG) += ximg.o obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o +obj-$(CONFIG_CMD_VERIFY) += verify.o obj-$(CONFIG_CMD_W1) += w1.o obj-$(CONFIG_CMD_ZIP) += zip.o obj-$(CONFIG_CMD_ZFS) += zfs.o diff --git a/cmd/verify.c b/cmd/verify.c new file mode 100644 index 0000000000..4d055e0790 --- /dev/null +++ b/cmd/verify.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + */ + +#include +#include +#include +#include + +static ulong verify_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int do_verify(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong addr = verify_get_addr(argc, argv); + int ret = 0; + + argc--; argv++; + + addr = verify_get_addr(argc, argv); + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) { + ret = image_pre_load(addr); + + if (ret) { + ret = CMD_RET_FAILURE; + goto out; + } + + env_set_hex("loadaddr_verified", addr + image_load_offset); + } + + out: + return ret; +} + +U_BOOT_CMD(verify, 2, 1, do_verify, + "verify the global signature provided in the pre-load header,\n" + "\tif the check succeed, the u-boot env variable loadaddr_verified\n" + "\tis set to the address of the image (without the header)", + "" +); -- 2.17.1