Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2CF5C4338F for ; Wed, 18 Aug 2021 15:37:49 +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 C89DD610CB for ; Wed, 18 Aug 2021 15:37:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C89DD610CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 9AC4782C45; Wed, 18 Aug 2021 17:37:46 +0200 (CEST) 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="TI5/YCWV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5A06682D3C; Wed, 18 Aug 2021 17:37:45 +0200 (CEST) Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) (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 F1C08807F3 for ; Wed, 18 Aug 2021 17:37:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-ot1-x335.google.com with SMTP id v33-20020a0568300921b0290517cd06302dso4518512ott.13 for ; Wed, 18 Aug 2021 08:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=F0J6oVfdjUdRKngvl1/SGeHem+n4+I9xTCDD7e7VMMw=; b=TI5/YCWVc1QM6fxd+RIvGr2SUR7lAZarfO5dlyZEF+1X5zMzxl/Yvr3jqFOAK8G7mc /MvOMWneua/jwZSRb7E2IwkPg9aLPsmLhmrbuaAbCnRcQo+l9YwlFNaiByO9uxfJ66ER lMw0BtgCoOl1flOfBmxfZxbLSt+JCI5CqUNHv3E+49ChWTBLqOLzZ4mmv2I1KypVsXO2 ZWCYmPMPfsFIt8KpVwoxNJY+ecUaLk+YOdIplO4JyyNDoeAkpiu/rrvTB5CI6rHZ9i6m PRv8PZhprMzJrywvewcNlQWEmqzv40ZadIn6oaWyHmpN5IxpgqAazNzsTM3ke9J9NmAt 2Lzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=F0J6oVfdjUdRKngvl1/SGeHem+n4+I9xTCDD7e7VMMw=; b=WtorCzJgr5J3mV+MbH6eHS3ekxJE2wqyUuC77Z5P7VjYL9V8UUboGLE1uDBCgyeQNI YJk0ahgCSZrdtbDcRXLiqa725DjneO14wxAas96u7hm1zUWs05ItDVCUNmZdADnehpTg 3jvauG3CMcEDcYSsWCOWhdF6r7w5+1/9GpLjWeNDnUDR5NtxJBk5Q5lSrJGTtVCYxwWX 5A82+u2cZVRlN7rUqjMxd+YI+HA3Abz/fswkTTdNwjRqIQhmagzlXS7cQzKeB7ng38UZ 9oxz4nZLFEMfmBZJ/bSiukhjXeulwNyzXmuFSK/kAA08Zu7AZ1qWjfAWIQtu5eUHhC31 SdqA== X-Gm-Message-State: AOAM531BTbVDWyW9sUvhuWWb7nABkepmov+cGMizo7E4Jlmm2uJ3z3Si kuUOOsN44AjL+UOK7PU68uuaplDBvTk= X-Google-Smtp-Source: ABdhPJxpUohcKc13xgr48CwGfdAEITVq0I9x/O5GdYPfq3uIV/DLI2O2bGBAeuLhELpZOX4AQbF3Dg== X-Received: by 2002:a05:6830:15d6:: with SMTP id j22mr7526938otr.41.1629301059051; Wed, 18 Aug 2021 08:37:39 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id u127sm92459oib.16.2021.08.18.08.37.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 08:37:38 -0700 (PDT) Subject: Re: [PATCH] mkimage: use environment variable MKIMAGE_SIGN_PIN to set pin for OpenSSL Engine To: u-boot@lists.denx.de References: <20210723201750.423422-1-mkl@pengutronix.de> From: "Alex G." Message-ID: Date: Wed, 18 Aug 2021 10:37:37 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210723201750.423422-1-mkl@pengutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 Hi Marc, On 7/23/21 3:17 PM, Marc Kleine-Budde wrote: > This patch adds the possibility to pass the PIN the OpenSSL Engine > used during signing via the environment variable MKIMAGE_SIGN_PIN. > This follows the approach used during kernel module > signing ("KBUILD_SIGN_PIN") or UBIFS image > signing ("MKIMAGE_SIGN_PIN"). I think the preferred approach would have been to add a flag to mkimage, similar to "-N => openssl engine to use for signing". Environment variables are rarely used to talk to tools, and not very intuitive. I can only really think of NO_SDL=1 being used by u-boot. Since this patch already made it, I hope you have the bandwidth to look at converting this to a mkimage flag. Alex > Signed-off-by: Marc Kleine-Budde > --- > doc/uImage.FIT/signature.txt | 4 ++-- > lib/rsa/rsa-sign.c | 11 +++++++++++ > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt > index 7cb1c15e5e15..61a72db3c74f 100644 > --- a/doc/uImage.FIT/signature.txt > +++ b/doc/uImage.FIT/signature.txt > @@ -533,8 +533,8 @@ Generic engine key ids: > or > "" > > -As mkimage does not at this time support prompting for passwords HSM may need > -key preloading wrapper to be used when invoking mkimage. > +In order to set the pin in the HSM, an environment variable "MKIMAGE_SIGN_PIN" > +can be specified. > > The following examples use the Nitrokey Pro using pkcs11 engine. Instructions > for other devices may vary. > diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c > index f4ed11e74a4a..49abec6c83fb 100644 > --- a/lib/rsa/rsa-sign.c > +++ b/lib/rsa/rsa-sign.c > @@ -338,6 +338,7 @@ static int rsa_init(void) > > static int rsa_engine_init(const char *engine_id, ENGINE **pe) > { > + const char *key_pass; > ENGINE *e; > int ret; > > @@ -362,10 +363,20 @@ static int rsa_engine_init(const char *engine_id, ENGINE **pe) > goto err_set_rsa; > } > > + key_pass = getenv("MKIMAGE_SIGN_PIN"); > + if (key_pass) { > + if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) { > + fprintf(stderr, "Couldn't set PIN\n"); > + ret = -1; > + goto err_set_pin; > + } > + } > + > *pe = e; > > return 0; > > +err_set_pin: > err_set_rsa: > ENGINE_finish(e); > err_engine_init: >