mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Michael Olbrich <m.olbrich@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Roland Hieber <rhi@pengutronix.de>
Subject: Re: [ptxdist] [APPLIED] ptxd_lib_code_signing: cs_get_ca(): improve error handling
Date: Tue, 20 Jul 2021 13:49:13 +0200	[thread overview]
Message-ID: <20210720114913.2628505-1-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <20210715134224.25700-1-rhi@pengutronix.de>

Thanks, applied as 235332de090655007e6ca808e79c9206d1e075da.

Michael

[sent from post-receive hook]

On Tue, 20 Jul 2021 13:49:13 +0200, Roland Hieber <rhi@pengutronix.de> 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 <rhi@pengutronix.de>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> Message-Id: <20210715134224.25700-1-rhi@pengutronix.de>
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> 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


      reply	other threads:[~2021-07-20 11:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 20:39 [ptxdist] [PATCH v3 1/5] " Roland Hieber
2021-07-08 20:39 ` [ptxdist] [PATCH v3 2/5] ptxd_lib_code_signing: introduce role groups Roland Hieber
2021-07-20 11:48   ` [ptxdist] [APPLIED] " Michael Olbrich
2021-07-08 20:39 ` [ptxdist] [PATCH v3 3/5] templates/code-signing-provider: set up the 'imx-habv4-srk' role group Roland Hieber
2021-07-20 11:48   ` [ptxdist] [APPLIED] " Michael Olbrich
2021-07-08 20:39 ` [ptxdist] [PATCH v3 4/5] templates/barebox-imx-habv4: use " Roland Hieber
2021-07-20 11:48   ` [ptxdist] [APPLIED] " Michael Olbrich
2021-07-08 20:39 ` [ptxdist] [PATCH v3 5/5] host-ptx-code-signing-dev: version bump 0.4 -> 0.5 Roland Hieber
2021-07-20 11:48   ` [ptxdist] [APPLIED] " Michael Olbrich
2021-07-09 13:36 ` [ptxdist] [PATCH v3 1/5] ptxd_lib_code_signing: cs_get_ca(): improve error handling Michael Olbrich
2021-07-12  8:42   ` Marc Kleine-Budde
2021-07-13 11:51     ` [ptxdist] [PATCH v4] " Roland Hieber
2021-07-14  6:21       ` Michael Olbrich
2021-07-15 13:42         ` [ptxdist] [PATCH v5] " Roland Hieber
2021-07-20 11:49           ` Michael Olbrich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210720114913.2628505-1-m.olbrich@pengutronix.de \
    --to=m.olbrich@pengutronix.de \
    --cc=ptxdist@pengutronix.de \
    --cc=rhi@pengutronix.de \
    --subject='Re: [ptxdist] [APPLIED] ptxd_lib_code_signing: cs_get_ca(): improve error handling' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox