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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDD26C433EF for ; Fri, 12 Nov 2021 19:36:43 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 30B2160C49 for ; Fri, 12 Nov 2021 19:36:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 30B2160C49 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7D49C82FF1; Fri, 12 Nov 2021 20:36:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="GuI8X2+G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 972888302B; Fri, 12 Nov 2021 20:28:33 +0100 (CET) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 8C41E83023 for ; Fri, 12 Nov 2021 20:28:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x331.google.com with SMTP id h19-20020a9d3e53000000b0056547b797b2so14499219otg.4 for ; Fri, 12 Nov 2021 11:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F7B7s6ydxZb7c+6BVCUk06jLK/d2BzeUxfp8ycFB0+c=; b=GuI8X2+G2nzTZ8z7oBz/YSEXux6KL/w74FiSJzOtKqZOpuYjEGbg5vZt25my8bGJuX cHGQApjNp/l9kD5FanuONyEd+otyh8Sal3Si/izRy6wRJNAUVT7ebtFh/pye4+oPWxOK XFYU0Jo33d8PNG7xU9gJDzORxMkYJZEJP6kLw= 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:mime-version :content-transfer-encoding; bh=F7B7s6ydxZb7c+6BVCUk06jLK/d2BzeUxfp8ycFB0+c=; b=kZj342GVe+dqGVDjjbkeokHtjdC/yUSuTD/9nnObE67LsLJuFj1kXvMzb5jXxLI2Fk fb/OeY+v/o6Brzoa8AsrOEyWfs7CmhxN+jJ0PQmQrKVo7+xwXWJYx/zA5VHmpclYtAAu 7iDMrzSckECd5bn4FX1AgNVrKYXa6LBS29rNN0rX7IpX+300sI76jI60VU+HqV7x9Nsz 8YQMa3kOjEcAJ3QrYR0i59XhGlfXnqXMd8SMHHxnmzuFbSQMF2qEW3zZdAfhtu038BxV csegUlU2mtWP0uEwBi0mUU2Y1PQ4/qVLomds6HI0dyqBIHn/tIdMbQwwjaiC412I9g/R G41A== X-Gm-Message-State: AOAM533PpOYE+ODaX+nYFemW7azRzCidPa3octT5As6QgilbNSGiAaEv tiWSa6RqS8kScrNP5SSMl3o/Y7Ag4y+QHw== X-Google-Smtp-Source: ABdhPJyQCgJWrEFDnhOG1sqQkNURUqK185tJuKlHTldP5emIH8PAI96VHgkoJCE3BLhi8KBOHXtWUA== X-Received: by 2002:a05:6830:270c:: with SMTP id j12mr9905312otu.231.1636745302710; Fri, 12 Nov 2021 11:28:22 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id n20sm1283527ooe.7.2021.11.12.11.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 11:28:21 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Rob Herring , Tom Rini , Bill Mills , Simon Glass , AKASHI Takahiro , Alexandru Gagniuc , Artem Lapkin , "Chan, Donald" , Chris Packham , Hannu Lounento , Heiko Schocher , Heinrich Schuchardt , Ilies CHERGUI , Jessica Clarke , Joe Hershberger , Joel Stanley , John Keeping , Marc Kleine-Budde , Marek Vasut , Martyn Welch , Ming Liu , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Philippe Reynes , Sean Anderson , Sebastian Reichel , Stefan Roese , Stefano Babic , Sven Roederer , Thomas Hebb , Thomas Perrot , Tyler Hicks , Vagrant Cascadian , Yann Dirson Subject: [PATCH 00/16] tools: Add support for signing devicetree blobs Date: Fri, 12 Nov 2021 12:28:01 -0700 Message-Id: <20211112192817.199075-1-sjg@chromium.org> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 12 Nov 2021 20:36:40 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 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 At present mkimage supports signing FITs, the standard U-Boot image type. Various people are opposed to using FIT since: a) it requires adding support for FIT into other bootloaders, notably UEFI b) it requires packaging a kernel in this standard U-Boot format, meaning that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT The kernel and initrd can be dealt with in other ways. But without FIT, we have no standard way of signing and grouping FDT files. Instead we must include them in the distro as separate files. In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format, it is possible to embed a signature inside the FDT itself, which is very convenient. This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT, other than in permitted nodes (e.g. /chosen). This series also provides a fdt_check_sign tool, used to check signatures. Both of these tools are stand-alone do not require mkimage or FIT. As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign. Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs to be determined. For now there is absolutely no configurability in the signature mechanism. It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the /chosen node is implemented in h_exclude_nodes() like this: if (type == FDT_IS_NODE) { /* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10)) return 0; } Man pages are provided with example usage of the tools. Use this to view them: man -l doc/fdt_check_sign.1 This series also includes various clean-ups noticed along the way, as well as refactoring to avoid code duplication with the new tools. The last four patches are the new code. This series is available at u-boot-dm/fdt-sign-working : https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working Simon Glass (16): rsa: Add debugging for failure cases fit_check_sign: Update help to mention the key is in a dtb tools: Move copyfile() into a common file tools: Avoid leaving extra data at the end of copied files tools: Improve comments in signing functions tools: Drop unused name in image-host tools: Avoid confusion between keys and signatures tools: Tidy up argument order in fit_config_check_sig() tools: Pass the key blob around image: Return destination node for add_verify_data() method tools: Pass public-key node through to caller tools: mkimage: Show where signatures/keys are written tools: Add a new tool to sign FDT blobs tools: Add a new tool to check FDT-blob signatures test: Add a test for FDT signing tools: Add man pages for fdt_sign and fdt_check_sign MAINTAINERS | 7 + boot/image-fit-sig.c | 151 +++++++++---- boot/image-fit.c | 12 +- common/spl/spl_fit.c | 3 +- doc/fdt_check_sign.1 | 74 +++++++ doc/fdt_sign.1 | 111 ++++++++++ include/image.h | 80 ++++++- include/u-boot/ecdsa.h | 5 +- include/u-boot/rsa.h | 5 +- lib/ecdsa/ecdsa-libcrypto.c | 4 +- lib/rsa/rsa-sign.c | 5 +- lib/rsa/rsa-verify.c | 13 +- test/py/tests/test_fdt_sign.py | 83 ++++++++ test/py/tests/test_vboot.py | 21 +- test/py/tests/vboot/sign-fdt.dts | 23 ++ test/py/tests/vboot_comm.py | 22 ++ tools/Makefile | 10 +- tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++ tools/fdt_check_sign.c | 85 ++++++++ tools/fdt_host.h | 46 ++++ tools/fdt_sign.c | 210 ++++++++++++++++++ tools/fit_check_sign.c | 4 +- tools/fit_common.c | 69 ++++++ tools/fit_common.h | 23 ++ tools/fit_image.c | 59 +----- tools/image-fdt-sig.c | 254 ++++++++++++++++++++++ tools/image-host.c | 155 +++++++++++--- tools/imagetool.h | 4 + tools/mkimage.c | 4 + 29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1 create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c create mode 100644 tools/image-fdt-sig.c -- 2.34.0.rc1.387.gb447b232ab-goog