diff options
| author | Johannes Schneider <johannes.schneider@leica-geosystems.com> | 2025-06-27 14:18:18 +0200 |
|---|---|---|
| committer | Khem Raj <raj.khem@gmail.com> | 2025-06-28 11:04:24 -0700 |
| commit | 5b315e2fc4884d9644b13474934ae006b530720e (patch) | |
| tree | cc348c7d9ead81b65b0069ac51a5182b67edfa1b | |
| parent | 855c956fbdb581d12de770548003deb8c1f81d49 (diff) | |
| download | meta-openembedded-5b315e2fc4884d9644b13474934ae006b530720e.tar.gz | |
signing.bbclass: add set|get|has_ca functions
Add a mechanism to establish a (metadata) link between roles and signer
certificates, in the form of a new 'ca' variable. It must point from one
role or cert to the signer certificate to preserve the leaf->intermediary->
root certificate relation.
With this additional mechanism, it would be now possible to import a
complex PKI tree of certificates and then later during usage of one
role, reconstruct the certificate chain from the leaf, through
multiple intermediary, and up to the root certificate.
Reviewed-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
| -rw-r--r-- | meta-oe/classes/signing.bbclass | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/meta-oe/classes/signing.bbclass b/meta-oe/classes/signing.bbclass index c768371151..04bd92bc03 100644 --- a/meta-oe/classes/signing.bbclass +++ b/meta-oe/classes/signing.bbclass | |||
| @@ -87,6 +87,11 @@ def signing_class_prepare(d): | |||
| 87 | export(role, "SIGNING_PKCS11_URI_%s_", pkcs11_uri) | 87 | export(role, "SIGNING_PKCS11_URI_%s_", pkcs11_uri) |
| 88 | export(role, "SIGNING_PKCS11_MODULE_%s_", pkcs11_module) | 88 | export(role, "SIGNING_PKCS11_MODULE_%s_", pkcs11_module) |
| 89 | 89 | ||
| 90 | # there can be an optional CA associated with this role | ||
| 91 | ca_cert_name = d.getVarFlag("SIGNING_CA", role) or d.getVar("SIGNING_CA") | ||
| 92 | if ca_cert_name: | ||
| 93 | export(role, "SIGNING_CA_%s_", ca_cert_name) | ||
| 94 | |||
| 90 | signing_pkcs11_tool() { | 95 | signing_pkcs11_tool() { |
| 91 | pkcs11-tool --module "${STAGING_LIBDIR_NATIVE}/softhsm/libsofthsm2.so" --login --pin 1111 $* | 96 | pkcs11-tool --module "${STAGING_LIBDIR_NATIVE}/softhsm/libsofthsm2.so" --login --pin 1111 $* |
| 92 | } | 97 | } |
| @@ -145,9 +150,52 @@ signing_import_cert_from_der() { | |||
| 145 | signing_pkcs11_tool --type cert --write-object "${der}" --label "${cert_name}" | 150 | signing_pkcs11_tool --type cert --write-object "${der}" --label "${cert_name}" |
| 146 | } | 151 | } |
| 147 | 152 | ||
| 148 | # signing_import_cert_chain_from_pem <role> <pem> | 153 | # signing_import_set_ca <cert_name> <ca_cert_name> |
| 149 | # | 154 | # |
| 155 | # Link the certificate from <cert_name> to its issuer stored in | ||
| 156 | # <ca_cert_name> By walking this linked list a CA-chain can later be | ||
| 157 | # reconstructed from the involed roles. | ||
| 158 | signing_import_set_ca() { | ||
| 159 | local cert_name="${1}" | ||
| 160 | local ca_cert_name="${2}" | ||
| 150 | 161 | ||
| 162 | echo "_SIGNING_CA_${cert_name}_=\"${ca_cert_name}\"" >> $_SIGNING_ENV_FILE_ | ||
| 163 | echo "added link from ${cert_name} to ${ca_cert_name}" | ||
| 164 | } | ||
| 165 | |||
| 166 | # signing_get_ca <cert_name> | ||
| 167 | # | ||
| 168 | # returns the <ca_cert_name> that has been set previously through | ||
| 169 | # either signing_import_set_ca; | ||
| 170 | # or a local.conf override SIGNING_CA[role] = ... | ||
| 171 | # If none was set, the empty string is returned. | ||
| 172 | signing_get_ca() { | ||
| 173 | local cert_name="${1}" | ||
| 174 | |||
| 175 | # prefer local configuration | ||
| 176 | eval local ca="\$SIGNING_CA_${cert_name}_" | ||
| 177 | if [ -n "$ca" ]; then | ||
| 178 | echo "$ca" | ||
| 179 | return | ||
| 180 | fi | ||
| 181 | |||
| 182 | # fall back to softhsm | ||
| 183 | eval echo "\$_SIGNING_CA_${cert_name}_" | ||
| 184 | } | ||
| 185 | |||
| 186 | # signing_has_ca <cert_name> | ||
| 187 | # | ||
| 188 | # check if the cert_name links to another cert_name that is its | ||
| 189 | # certificate authority/issuer. | ||
| 190 | signing_has_ca() { | ||
| 191 | local ca_cert_name="$(signing_get_ca ${1})" | ||
| 192 | |||
| 193 | test -n "$ca_cert_name" | ||
| 194 | return $? | ||
| 195 | } | ||
| 196 | |||
| 197 | # signing_import_cert_chain_from_pem <role> <pem> | ||
| 198 | # | ||
| 151 | # Import a certificate *chain* from a PEM file to a role. | 199 | # Import a certificate *chain* from a PEM file to a role. |
| 152 | # (e.g. multiple ones concatenated in one file) | 200 | # (e.g. multiple ones concatenated in one file) |
| 153 | # | 201 | # |
