From: Marc Kleine-Budde <[email protected]>

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 <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
Signed-off-by: Roland Hieber <[email protected]>
---
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/[email protected]
 - 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/[email protected]
 - 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/[email protected]

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}"
 }
 export -f cs_get_ca
 
-- 
2.30.2


_______________________________________________
ptxdist mailing list
[email protected]
To unsubscribe, send a mail with subject "unsubscribe" to 
[email protected]

Reply via email to