From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 14 Jul 2021 08:21:55 +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 1m3YHL-0006Nc-IY for lore@lore.pengutronix.de; Wed, 14 Jul 2021 08:21:55 +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 1m3YHL-0001E8-9H; Wed, 14 Jul 2021 08:21:55 +0200 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3YGf-0001D3-G0; Wed, 14 Jul 2021 08:21:13 +0200 Received: from mol by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1m3YGf-0008AT-7G; Wed, 14 Jul 2021 08:21:13 +0200 Date: Wed, 14 Jul 2021 08:21:13 +0200 From: Michael Olbrich To: Roland Hieber , ptxdist@pengutronix.de Message-ID: <20210714062113.GK27936@pengutronix.de> Mail-Followup-To: Roland Hieber , ptxdist@pengutronix.de References: <20210712084247.zvazdqqsffzjotwt@pengutronix.de> <20210713115125.15630-1-rhi@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210713115125.15630-1-rhi@pengutronix.de> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 08:16:34 up 146 days, 9:40, 107 users, load average: 0.06, 0.14, 0.18 User-Agent: Mutt/1.10.1 (2018-07-13) Subject: Re: [ptxdist] [PATCH v4] 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 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 On Tue, Jul 13, 2021 at 01:51:25PM +0200, Roland Hieber wrote: > From: Marc Kleine-Budde > > This patch changes cs_get_ca() to only output the CA if it actually > exists, or print an error and return 1 instead. This makes it possible > to use make's $(if $(filter-out, ERROR_CA_NOT_YET_SET, ...)) > conditional. > > Co-authored-by: Roland Hieber > Signed-off-by: Marc Kleine-Budde > Signed-off-by: Roland Hieber > --- > PATCH v4: > - revert to [ -e "${ca}" ] test (feeback from Michael Olbrich and Marc > Kleine-Budde) > - add documentation too > > PATCH v3: https://lore.ptxdist.org/ptxdist/20210708203941.30212-1-rhi@pengutronix.de > - correctly check for existence of ${keydir} instead of ${ca} (feedback > from Michael Olbrich) > - drop controversial re-indentation patches 6/7 and 7/7 from the series > > PATCH v2 (rhi): https://lore.ptxdist.org/ptxdist/20210627231121.28313-1-rhi@pengutronix.de > - reorder from PATCH 3/n to PATCH 1/n > - echo "ERROR_CA_NOT_YET_SET" in case of error (feedback from Michael > Olbrich) and also return 1 > > PATCH v1 (mkl): https://lore.ptxdist.org/ptxdist/20210412161900.2376802-3-mkl@pengutronix.de > > fixup! ptxd_lib_code_signing: cs_get_ca(): improve error handling > --- > doc/ref_code_signing_helpers.rst | 3 ++- > scripts/lib/ptxd_lib_code_signing.sh | 8 +++++++- > 2 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/doc/ref_code_signing_helpers.rst b/doc/ref_code_signing_helpers.rst > index 99a395b287c9..0fd61219a97a 100644 > --- a/doc/ref_code_signing_helpers.rst > +++ b/doc/ref_code_signing_helpers.rst > @@ -334,4 +334,5 @@ 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`) > + :ref:`cs_append_ca_from_uri`). > + Otherwise, this function will print ``ERROR_CA_NOT_YET_SET``. > diff --git a/scripts/lib/ptxd_lib_code_signing.sh b/scripts/lib/ptxd_lib_code_signing.sh > index 5fa62d8372f9..ca101d635574 100644 > --- a/scripts/lib/ptxd_lib_code_signing.sh > +++ b/scripts/lib/ptxd_lib_code_signing.sh > @@ -288,7 +288,13 @@ cs_get_ca() { > local role="${1}" > cs_init_variables > > - echo "${keydir}/${role}/ca.pem" > + local ca="${keydir}/${role}/ca.pem" > + > + if [ ! -e "${ca}" ]; then > + echo "ERROR_CA_NOT_YET_SET" > + return 1 > + fi > + echo "${ca}" No. Please that's not what I meant. You need _both_! There are three cases that need different output not two: 1. The function is called before the provider initialized the data: if [ ! -d "${keydir}" ]; then echo "ERROR_CA_NOT_YET_SET" return 1 fi 2. The provider created a CA: if [ -e "${ca}" ]; then echo "${ca}" fi 3. The provider did _not_ create a CA: # no output Case 1 is to detect misuse. And case 2 and 3 are needed to make the example that Marc described possible. Michael > } > export -f cs_get_ca > > -- > 2.30.2 > > > _______________________________________________ > ptxdist mailing list > ptxdist@pengutronix.de > To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ ptxdist mailing list ptxdist@pengutronix.de To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de