From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Tue, 20 Jul 2021 13:51:42 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1m5oHm-0002RH-JI for lore@lore.pengutronix.de; Tue, 20 Jul 2021 13:51:42 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1m5oHm-0006cj-1K; Tue, 20 Jul 2021 13:51:42 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5oFN-0003EA-PD; Tue, 20 Jul 2021 13:49:13 +0200 Received: from [2a0a:edc0:0:1101:1d::39] (helo=dude03.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1m5oFN-0002Wr-8r; Tue, 20 Jul 2021 13:49:13 +0200 Received: from mol by dude03.red.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1m5oFN-00B1p3-8R; Tue, 20 Jul 2021 13:49:13 +0200 From: Michael Olbrich To: ptxdist@pengutronix.de Date: Tue, 20 Jul 2021 13:49:13 +0200 Message-Id: <20210720114913.2628505-1-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715134224.25700-1-rhi@pengutronix.de> References: <20210715134224.25700-1-rhi@pengutronix.de> MIME-Version: 1.0 Subject: Re: [ptxdist] [APPLIED] ptxd_lib_code_signing: cs_get_ca(): improve error handling X-BeenThere: ptxdist@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ptxdist@pengutronix.de Cc: Roland Hieber Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ptxdist" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: ptxdist-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false Thanks, applied as 235332de090655007e6ca808e79c9206d1e075da. Michael [sent from post-receive hook] On Tue, 20 Jul 2021 13:49:13 +0200, Roland Hieber wrote: > This patch changes cs_get_ca() to only output the CA if it actually > exists, so that this function can be used even if a signing provider > does not provide a CA for a role. > > Additionally improve robustness against premature evaluation by printing > an error code if the signing provider was not set up yet. If the error > message is used as part of a URI, the user can at least get a hint about > the fact that an error happened. > > Co-authored-by: Roland Hieber > Signed-off-by: Marc Kleine-Budde > Signed-off-by: Roland Hieber > Message-Id: <20210715134224.25700-1-rhi@pengutronix.de> > Signed-off-by: Michael Olbrich > > diff --git a/doc/ref_code_signing_helpers.rst b/doc/ref_code_signing_helpers.rst > index 99a395b287c9..fd16ca763557 100644 > --- a/doc/ref_code_signing_helpers.rst > +++ b/doc/ref_code_signing_helpers.rst > @@ -330,8 +330,24 @@ Usage: > > Get path to the CA keyring in PEM format for role. > > +If the provider does not set a CA for this role (see :ref:`cs_append_ca_from_pem`, > +:ref:`cs_append_ca_from_der`, :ref:`cs_append_ca_from_uri`), this function will print an empty > +string. > + > Preconditions: > > -- a certificate must have been appended to the CA keyring > - (see :ref:`cs_append_ca_from_pem`, :ref:`cs_append_ca_from_der`, > - :ref:`cs_append_ca_from_uri`) > +- The role must have been defined by the provider (see :ref:`cs_define_role`). > + Otherwise, this function will print ``ERROR_CA_NOT_YET_SET`` and return 1. > + This can happen if the function is evaluated by a variable expansion in make > + with ``:=`` instead of ``=`` before the code signing provider is set up. > + > +Example: > + > +.. code-block:: make > + > + # set up kernel module signing, and add a trusted CA if the provider set one > + KERNEL_SIGN_OPT = > + CONFIG_MODULE_SIG_KEY='"$(shell cs_get_uri kernel-modules)"' \ > + CONFIG_MODULE_SIG_ALL=y \ > + $(if $(shell cs_get_ca kernel-trusted), \ > + CONFIG_SYSTEM_TRUSTED_KEYS=$(shell cs_get_ca kernel-trusted)) > diff --git a/scripts/lib/ptxd_lib_code_signing.sh b/scripts/lib/ptxd_lib_code_signing.sh > index 5fa62d8372f9..5ba1a4666af4 100644 > --- a/scripts/lib/ptxd_lib_code_signing.sh > +++ b/scripts/lib/ptxd_lib_code_signing.sh > @@ -288,7 +288,16 @@ cs_get_ca() { > local role="${1}" > cs_init_variables > > - echo "${keydir}/${role}/ca.pem" > + local ca="${keydir}/${role}/ca.pem" > + > + if [ ! -d "${keydir}" ]; then > + echo "ERROR_CA_NOT_YET_SET" > + return 1 > + fi > + > + if [ -e "${ca}" ]; then > + echo "${ca}" > + fi > } > export -f cs_get_ca > _______________________________________________ ptxdist mailing list ptxdist@pengutronix.de To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de