From patchwork Wed Jun 20 20:10:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Kiernan X-Patchwork-Id: 932377 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vPeV+z71"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 419wvc1D6tz9s31 for ; Thu, 21 Jun 2018 06:11:22 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 46848C21FB1; Wed, 20 Jun 2018 20:11:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1F60BC21D74; Wed, 20 Jun 2018 20:11:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A02FEC21D74; Wed, 20 Jun 2018 20:11:10 +0000 (UTC) Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by lists.denx.de (Postfix) with ESMTPS id 4F768C21D72 for ; Wed, 20 Jun 2018 20:11:10 +0000 (UTC) Received: by mail-wm0-f49.google.com with SMTP id v131-v6so1724364wma.1 for ; Wed, 20 Jun 2018 13:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bQYvEXAOmI46M2ws2Kkz+5SYDT21AXpJF5nQFZ124O0=; b=vPeV+z71EnXE9rZ1KPLwZ5bbxJd39sXBfvprTscw/6xaTFwQYwlQTOdYW88S3So4Wd VUDYyepz6SWE0g739IjyOxEPTX2J3gceNqPeO+9C/y+PDQQ2nPFQRma+5jv84SuswuhX 2YroDv63G5O67L+3YEN3+VdnL2LnZB0BqCmXK6gk0xjg2knjQ62r6Z6N08humJbkq73T 4GKdO8FG5YvqnxSzmP3B7qEUjOrjgMODPxBnsN6QWXrATIPQWkbNrJB2izNf03kdMFb4 N+f/JOj8vUL6oA0iaLzRgxWYIKFSzguRPBSslcASZpzj+C4TIiKm00rSe5PUSgyaxDFo RVJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bQYvEXAOmI46M2ws2Kkz+5SYDT21AXpJF5nQFZ124O0=; b=PnH1R0Vmk5/wNtAXthLp2XfJAXgrWapIPCq6DLaTaoy75iJWBOez2qlnDYUH05CZPN khH4e+58SXmtCDqDZfcSC0A+GaTyoJR7kQoVTZf7S3nGRK9FhkwyYdkO68Q1M7XasCMH RUE6KhCIj9g+qkCcoEB9xWU2CqY7sUVJWg11aih9F4ERYIHBwiPpKj+QmeOskfIXbyaJ jdLiEjDOKbrTf8DY2cQHx2fWobzoJNDdU45UFjzgr/GSQBzV8M6TBLyAL3Y9l6LMioY/ 3uqQGFn8X1K1y7vVwOZbcKK+0xr/81voDUQ19MED5ET+mXaRTBr7K5+XEbHTYQ8GjHzd 4ihg== X-Gm-Message-State: APt69E2W1KJMdcLXfk2tHPVr4MPvTgoi/jmMkk9F9Iil2e4iHWS3YomU C4WJEaLQ8cWUU5iidzNz4+N1vbTA X-Google-Smtp-Source: ADUXVKJyWY0ryjwkREH5TujiFCG5LoPHg8nWz4R/eOUcnmXjh/jkCzmndbU5PHKpI8uLNjGAvgIEEA== X-Received: by 2002:a1c:c90:: with SMTP id 138-v6mr2647939wmm.110.1529525469699; Wed, 20 Jun 2018 13:11:09 -0700 (PDT) Received: from localhost.localdomain (cust246-dsl91-135-6.idnet.net. [91.135.6.246]) by smtp.gmail.com with ESMTPSA id c18-v6sm4561759wrq.17.2018.06.20.13.11.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 13:11:08 -0700 (PDT) From: Alex Kiernan To: u-boot@lists.denx.de Date: Wed, 20 Jun 2018 20:10:51 +0000 Message-Id: <20180620201052.15428-1-alex.kiernan@gmail.com> X-Mailer: git-send-email 2.17.1 Cc: Stefan Theil , Joe Hershberger , Andre Przywara , Alexander Graf , Michal Simek Subject: [U-Boot] [PATCH 1/2] mkimage: Refactor imagetool_get_source_date to take command name X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" So we can use imagetool_get_source_date() from callers who do not have the image tool params struct, just pass in the command name for the error message. Signed-off-by: Alex Kiernan Reviewed-by: Simon Glass --- tools/default_image.c | 2 +- tools/fit_image.c | 3 ++- tools/imagetool.c | 4 ++-- tools/imagetool.h | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/default_image.c b/tools/default_image.c index 4abff4543a..4b7d1ed4a1 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -100,7 +100,7 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, sizeof(image_header_t)), sbuf->st_size - sizeof(image_header_t)); - time = imagetool_get_source_date(params, sbuf->st_mtime); + time = imagetool_get_source_date(params->cmdname, sbuf->st_mtime); ep = params->ep; addr = params->addr; diff --git a/tools/fit_image.c b/tools/fit_image.c index e55a8943e7..6f09a66106 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -51,7 +51,8 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, /* for first image creation, add a timestamp at offset 0 i.e., root */ if (params->datafile) { - time_t time = imagetool_get_source_date(params, sbuf.st_mtime); + time_t time = imagetool_get_source_date(params->cmdname, + sbuf.st_mtime); ret = fit_set_timestamp(ptr, 0, time); } diff --git a/tools/imagetool.c b/tools/imagetool.c index a4e39b24bc..b3e628f612 100644 --- a/tools/imagetool.c +++ b/tools/imagetool.c @@ -116,7 +116,7 @@ int imagetool_get_filesize(struct image_tool_params *params, const char *fname) } time_t imagetool_get_source_date( - struct image_tool_params *params, + const char *cmdname, time_t fallback) { char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); @@ -128,7 +128,7 @@ time_t imagetool_get_source_date( if (gmtime(&time) == NULL) { fprintf(stderr, "%s: SOURCE_DATE_EPOCH is not valid\n", - params->cmdname); + cmdname); time = 0; } diff --git a/tools/imagetool.h b/tools/imagetool.h index d191b9cfe7..63c08ebc09 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -216,12 +216,12 @@ int imagetool_get_filesize(struct image_tool_params *params, const char *fname); * an error message if SOURCE_DATE_EPOCH contains an invalid value and returns * 0. * - * @params: mkimage parameters + * @cmdname: command name * @fallback: timestamp to use if SOURCE_DATE_EPOCH isn't set * @return timestamp based on SOURCE_DATE_EPOCH */ time_t imagetool_get_source_date( - struct image_tool_params *params, + const char *cmdname, time_t fallback); /* From patchwork Wed Jun 20 20:10:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Kiernan X-Patchwork-Id: 932379 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="r5zJ9Rky"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 419ww93MHVz9s2L for ; Thu, 21 Jun 2018 06:11:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C5032C21D74; Wed, 20 Jun 2018 20:11:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 40F88C21FBA; Wed, 20 Jun 2018 20:11:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A63E8C21D56; Wed, 20 Jun 2018 20:11:16 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 436CFC21F2B for ; Wed, 20 Jun 2018 20:11:13 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id r15-v6so1486565wmc.1 for ; Wed, 20 Jun 2018 13:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7E/2Iwet2H6izVKRg+I2+JYGcx4NxE7oEcIwNIF2tqQ=; b=r5zJ9RkyJguYXDrQr9mOjhwarmnexTIQqsvWUyjGjPb59kwha3PoIfmfiZf+4hSRKl kat0+kl7XxNBOLu34nvD2OrJMBVAm8o5z7Zc4jCzvdjtsXL5kvf+o3PMTnIv9tUVefbg TiuYIt56oFjv+oNGqXSnk9EmAkkXjUADJEUXld+6i0S4JSD+09Cs2MT+h4LYRT/eeOUF fUR71Icpd2ajQ2SKLq7Go2jB//4yfdpaPYsyFwg8len/ncxH8brdnopCTV3odPb2WE+g KPPQObjpPwseWzYc1Zs0cIA9gDHC5ItDwHjX/ioQUVPWL4c6PYKp/RN8VGaDZQ9N70Qz pg1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7E/2Iwet2H6izVKRg+I2+JYGcx4NxE7oEcIwNIF2tqQ=; b=LKQKWlRWbzw5pzCiZlT59WYNwzBRbltM8rw+gUYXz9C2sZ+NNSCjJkwGzG9lL9mJk2 xAPFidIjzp75QZmrP4IiIqnQ127YZgkCgQfi/7qqQUTIeHOFp6WYAi+Rpmd/eTDZdh+Q usYbrc3E/tTcE2rce+X+PXNqDJdQ3QsRZqojQiwULS9a28MWOlhAS4QtETgV3/6AX9Mn VYtPXckLw88sPlBJrfaLW7i3K7cWsafWCIhPkvte8pFyITiNos1X+GvjMGO/PMOO2ZCh K/ToAuaAC6EalH6wZFhMaljerDLsOhqmj8L7PGl+oY1xqRwVrOyKvbcIGmh7529coRZt U8Lg== X-Gm-Message-State: APt69E0IzCmu+LAFfSdE1NSmTprKHsIXuPagEqEHObLusStNTMxJZiM6 YoetjN1kauOAs0Tj+4835BWHusRH X-Google-Smtp-Source: ADUXVKK17QqMuZiBhYGZBSVLZymuoSY1UE2icYe1K+22Drw+v/riWtlQBHeAvFwX1pxxfoxiH9vz5w== X-Received: by 2002:a1c:3705:: with SMTP id e5-v6mr2741019wma.20.1529525472704; Wed, 20 Jun 2018 13:11:12 -0700 (PDT) Received: from localhost.localdomain (cust246-dsl91-135-6.idnet.net. [91.135.6.246]) by smtp.gmail.com with ESMTPSA id c18-v6sm4561759wrq.17.2018.06.20.13.11.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 13:11:12 -0700 (PDT) From: Alex Kiernan To: u-boot@lists.denx.de Date: Wed, 20 Jun 2018 20:10:52 +0000 Message-Id: <20180620201052.15428-2-alex.kiernan@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180620201052.15428-1-alex.kiernan@gmail.com> References: <20180620201052.15428-1-alex.kiernan@gmail.com> Cc: Stefan Theil , Andre Przywara , Pantelis Antoniou Subject: [U-Boot] [PATCH 2/2] mkimage: fit_image: Add support for SOURCE_DATE_EPOCH in signatures X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When generating timestamps in signatures, use imagetool_get_source_date() so we can be overridden by SOURCE_DATE_EPOCH to generate reproducible images. Signed-off-by: Alex Kiernan Reviewed-by: Simon Glass --- include/image.h | 3 ++- tools/fit_image.c | 3 ++- tools/image-host.c | 34 ++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/image.h b/include/image.h index 420b8ff576..3bb7d29ef2 100644 --- a/include/image.h +++ b/include/image.h @@ -1009,6 +1009,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp); * @comment: Comment to add to signature nodes * @require_keys: Mark all keys as 'required' * @engine_id: Engine to use for signing + * @cmdname: Command name used when reporting errors * * Adds hash values for all component images in the FIT blob. * Hashes are calculated for all component images which have hash subnodes @@ -1022,7 +1023,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp); */ int fit_add_verification_data(const char *keydir, void *keydest, void *fit, const char *comment, int require_keys, - const char *engine_id); + const char *engine_id, const char *cmdname); int fit_image_verify_with_data(const void *fit, int image_noffset, const void *data, size_t size); diff --git a/tools/fit_image.c b/tools/fit_image.c index 6f09a66106..3c265357ae 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -60,7 +60,8 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, ret = fit_add_verification_data(params->keydir, dest_blob, ptr, params->comment, params->require_keys, - params->engine_id); + params->engine_id, + params->cmdname); } if (dest_blob) { diff --git a/tools/image-host.c b/tools/image-host.c index 8e43671714..faa5e23c79 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -106,7 +106,7 @@ static int fit_image_process_hash(void *fit, const char *image_name, */ static int fit_image_write_sig(void *fit, int noffset, uint8_t *value, int value_len, const char *comment, const char *region_prop, - int region_proplen) + int region_proplen, const char *cmdname) { int string_size; int ret; @@ -128,8 +128,12 @@ static int fit_image_write_sig(void *fit, int noffset, uint8_t *value, } if (comment && !ret) ret = fdt_setprop_string(fit, noffset, "comment", comment); - if (!ret) - ret = fit_set_timestamp(fit, noffset, time(NULL)); + if (!ret) { + time_t timestamp = imagetool_get_source_date(cmdname, + time(NULL)); + + ret = fit_set_timestamp(fit, noffset, timestamp); + } if (region_prop && !ret) { uint32_t strdata[2]; @@ -200,7 +204,8 @@ static int fit_image_setup_sig(struct image_sign_info *info, static int fit_image_process_sig(const char *keydir, void *keydest, void *fit, const char *image_name, int noffset, const void *data, size_t size, - const char *comment, int require_keys, const char *engine_id) + const char *comment, int require_keys, const char *engine_id, + const char *cmdname) { struct image_sign_info info; struct image_region region; @@ -228,7 +233,7 @@ static int fit_image_process_sig(const char *keydir, void *keydest, } ret = fit_image_write_sig(fit, noffset, value, value_len, comment, - NULL, 0); + NULL, 0, cmdname); if (ret) { if (ret == -FDT_ERR_NOSPACE) return -ENOSPC; @@ -295,7 +300,7 @@ static int fit_image_process_sig(const char *keydir, void *keydest, */ int fit_image_add_verification_data(const char *keydir, void *keydest, void *fit, int image_noffset, const char *comment, - int require_keys, const char *engine_id) + int require_keys, const char *engine_id, const char *cmdname) { const char *image_name; const void *data; @@ -332,7 +337,7 @@ int fit_image_add_verification_data(const char *keydir, void *keydest, strlen(FIT_SIG_NODENAME))) { ret = fit_image_process_sig(keydir, keydest, fit, image_name, noffset, data, size, - comment, require_keys, engine_id); + comment, require_keys, engine_id, cmdname); } if (ret) return ret; @@ -573,7 +578,7 @@ static int fit_config_get_data(void *fit, int conf_noffset, int noffset, static int fit_config_process_sig(const char *keydir, void *keydest, void *fit, const char *conf_name, int conf_noffset, int noffset, const char *comment, int require_keys, - const char *engine_id) + const char *engine_id, const char *cmdname) { struct image_sign_info info; const char *node_name; @@ -608,7 +613,7 @@ static int fit_config_process_sig(const char *keydir, void *keydest, } ret = fit_image_write_sig(fit, noffset, value, value_len, comment, - region_prop, region_proplen); + region_prop, region_proplen, cmdname); if (ret) { if (ret == -FDT_ERR_NOSPACE) return -ENOSPC; @@ -637,7 +642,7 @@ static int fit_config_process_sig(const char *keydir, void *keydest, static int fit_config_add_verification_data(const char *keydir, void *keydest, void *fit, int conf_noffset, const char *comment, - int require_keys, const char *engine_id) + int require_keys, const char *engine_id, const char *cmdname) { const char *conf_name; int noffset; @@ -656,7 +661,7 @@ static int fit_config_add_verification_data(const char *keydir, void *keydest, strlen(FIT_SIG_NODENAME))) { ret = fit_config_process_sig(keydir, keydest, fit, conf_name, conf_noffset, noffset, comment, - require_keys, engine_id); + require_keys, engine_id, cmdname); } if (ret) return ret; @@ -667,7 +672,7 @@ static int fit_config_add_verification_data(const char *keydir, void *keydest, int fit_add_verification_data(const char *keydir, void *keydest, void *fit, const char *comment, int require_keys, - const char *engine_id) + const char *engine_id, const char *cmdname) { int images_noffset, confs_noffset; int noffset; @@ -690,7 +695,8 @@ int fit_add_verification_data(const char *keydir, void *keydest, void *fit, * i.e. component image node. */ ret = fit_image_add_verification_data(keydir, keydest, - fit, noffset, comment, require_keys, engine_id); + fit, noffset, comment, require_keys, engine_id, + cmdname); if (ret) return ret; } @@ -714,7 +720,7 @@ int fit_add_verification_data(const char *keydir, void *keydest, void *fit, ret = fit_config_add_verification_data(keydir, keydest, fit, noffset, comment, require_keys, - engine_id); + engine_id, cmdname); if (ret) return ret; }