From f642526db57a0cd22879f23c046471ff7c1effb1 Mon Sep 17 00:00:00 2001 From: Johannes Schneider Date: Fri, 27 Jun 2025 14:18:19 +0200 Subject: [PATCH] signing.bbclass: add get_root_cert Add a helper method to retrieve the root CA certificate for a given role, by walking the chain that has been setup with signing_import_set_ca up to the last element - which is the root. Reviewed-by: Jan Luebbe Signed-off-by: Johannes Schneider Signed-off-by: Khem Raj --- meta-oe/classes/signing.bbclass | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/meta-oe/classes/signing.bbclass b/meta-oe/classes/signing.bbclass index 04bd92bc03..2a94f5f5b3 100644 --- a/meta-oe/classes/signing.bbclass +++ b/meta-oe/classes/signing.bbclass @@ -194,6 +194,22 @@ signing_has_ca() { return $? } +# signing_get_root_cert +# +# return the role/name of the CA root certificate for a given +# , by walking the chain setup with signing_import_set_ca +# all the way to the last in line that doesn't have a CA set - which +# would be the root. +# +# To be used with SoftHSM. +signing_get_root_cert() { + local cert_name="${1}" + while signing_has_ca "${cert_name}"; do + cert_name="$(signing_get_ca ${cert_name})" + done + echo "${cert_name}" +} + # signing_import_cert_chain_from_pem # # Import a certificate *chain* from a PEM file to a role.