summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe
diff options
context:
space:
mode:
authorAdrian Freihofer <adrian.freihofer@siemens.com>2025-06-03 10:23:17 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-05 11:02:21 +0100
commit29a931bfbfdef89855f264d414c4d006639acfd3 (patch)
tree80f87cb82177ef6d343d5371f1530a7fb9a916b3 /meta/classes-recipe
parent8b8bdc4a199408e78c8814c82f98e74d17571294 (diff)
downloadpoky-29a931bfbfdef89855f264d414c4d006639acfd3.tar.gz
kernel-signing-keys-native: refactor key generation into a new recipe
The do_kernel_generate_rsa_keys function from kernel-fitimage.bbclass is moved to a new recipe, kernel-signing-keys-native.bb. This refactoring introduces no functional changes. Intention this change: - Remove the dependency of uboot-sign.bbclass on kernel-fitimage.bbclass. - Simplify the use of custom key generation implementations by isolating the functionality into a separate recipe. Known limitations of this (and also the previous) implementation: - When generating from an existing TMPDIR, the existing key is reused. However, when generating from an empty TMPDIR or an SDK using the sstate-cache, a new key is generated, which may lead to inconsistencies. - The use of random keys (via FIT_GENERATE_KEYS) is convenient for experiments but unsuitable for production environments requiring deterministic and secure key management. Future improvements to consider: - Ensure reproducibility, even when using the sstate-cache. However, simply storing the private key in a potentially shared sstate artifact may not always be ideal from a security perspective. - Support encrypted keys via `SRC_URI` for reliable key updates. - Enable signing with an HSM (Hardware Security Module) through mechanisms like PKCS#11 or post-processing scripts. (From OE-Core rev: 88736bb53fd2f0ffa1d249fc1a37897d10c8be18) Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe')
-rw-r--r--meta/classes-recipe/kernel-fitimage.bbclass52
-rw-r--r--meta/classes-recipe/uboot-sign.bbclass5
2 files changed, 7 insertions, 50 deletions
diff --git a/meta/classes-recipe/kernel-fitimage.bbclass b/meta/classes-recipe/kernel-fitimage.bbclass
index 07786647e1..f5f02f30f0 100644
--- a/meta/classes-recipe/kernel-fitimage.bbclass
+++ b/meta/classes-recipe/kernel-fitimage.bbclass
@@ -27,7 +27,10 @@ def get_fit_replacement_type(d):
27 return replacementtype 27 return replacementtype
28 28
29KERNEL_IMAGETYPE_REPLACEMENT ?= "${@get_fit_replacement_type(d)}" 29KERNEL_IMAGETYPE_REPLACEMENT ?= "${@get_fit_replacement_type(d)}"
30DEPENDS:append = " ${@'u-boot-tools-native dtc-native' if 'fitImage' in (d.getVar('KERNEL_IMAGETYPES') or '').split() else ''}" 30DEPENDS:append = " \
31 ${@'u-boot-tools-native dtc-native' if 'fitImage' in (d.getVar('KERNEL_IMAGETYPES') or '').split() else ''} \
32 ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''} \
33"
31 34
32python __anonymous () { 35python __anonymous () {
33 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal 36 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
@@ -754,53 +757,6 @@ do_assemble_fitimage_initramfs() {
754 757
755addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs 758addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
756 759
757do_kernel_generate_rsa_keys() {
758 if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
759 bbwarn "FIT_GENERATE_KEYS is set to 1 even though UBOOT_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used."
760 fi
761
762 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
763
764 # Generate keys to sign configuration nodes, only if they don't already exist
765 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \
766 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt ]; then
767
768 # make directory if it does not already exist
769 mkdir -p "${UBOOT_SIGN_KEYDIR}"
770
771 bbnote "Generating RSA private key for signing fitImage"
772 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
773 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
774 "${FIT_SIGN_NUMBITS}"
775
776 bbnote "Generating certificate for signing fitImage"
777 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
778 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
779 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt
780 fi
781
782 # Generate keys to sign image nodes, only if they don't already exist
783 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key ] || \
784 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".crt ]; then
785
786 # make directory if it does not already exist
787 mkdir -p "${UBOOT_SIGN_KEYDIR}"
788
789 bbnote "Generating RSA private key for signing fitImage"
790 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
791 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key \
792 "${FIT_SIGN_NUMBITS}"
793
794 bbnote "Generating certificate for signing fitImage"
795 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
796 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key \
797 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".crt
798 fi
799 fi
800}
801
802addtask kernel_generate_rsa_keys before do_assemble_fitimage after do_compile
803
804kernel_do_deploy[vardepsexclude] = "DATETIME" 760kernel_do_deploy[vardepsexclude] = "DATETIME"
805kernel_do_deploy:append() { 761kernel_do_deploy:append() {
806 # Update deploy directory 762 # Update deploy directory
diff --git a/meta/classes-recipe/uboot-sign.bbclass b/meta/classes-recipe/uboot-sign.bbclass
index 796c040e8b..73e9ce3f11 100644
--- a/meta/classes-recipe/uboot-sign.bbclass
+++ b/meta/classes-recipe/uboot-sign.bbclass
@@ -112,13 +112,14 @@ UBOOT_FIT_CONF_USER_LOADABLES ?= ''
112UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}" 112UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}"
113UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}" 113UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}"
114 114
115
116DEPENDS:append = " ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''}"
117
115python() { 118python() {
116 # We need u-boot-tools-native if we're creating a U-Boot fitImage 119 # We need u-boot-tools-native if we're creating a U-Boot fitImage
117 sign = d.getVar('UBOOT_SIGN_ENABLE') == '1' 120 sign = d.getVar('UBOOT_SIGN_ENABLE') == '1'
118 if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' or sign: 121 if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' or sign:
119 d.appendVar('DEPENDS', " u-boot-tools-native dtc-native") 122 d.appendVar('DEPENDS', " u-boot-tools-native dtc-native")
120 if d.getVar('FIT_GENERATE_KEYS') == '1' and sign:
121 d.appendVarFlag('do_uboot_assemble_fitimage', 'depends', ' virtual/kernel:do_kernel_generate_rsa_keys')
122} 123}
123 124
124concat_dtb() { 125concat_dtb() {