aboutsummaryrefslogtreecommitdiffstats
path: root/classes/uefi-sign.bbclass
diff options
context:
space:
mode:
authorCalifornia Sullivan <california.l.sullivan@intel.com>2017-07-18 16:56:18 -0700
committerSaul Wold <sgw@linux.intel.com>2017-07-19 08:30:08 -0700
commit625a588f70785cf777ec9fb072b127b126aba781 (patch)
tree89711df42d09a572c40d27300e40a6061497bf40 /classes/uefi-sign.bbclass
parent21086869beba0c6e38275be97af2e689e17820ec (diff)
downloadmeta-intel-625a588f70785cf777ec9fb072b127b126aba781.tar.gz
meta-intel-625a588f70785cf777ec9fb072b127b126aba781.tar.bz2
meta-intel-625a588f70785cf777ec9fb072b127b126aba781.zip
uefi-comboapp.bbclass: Split signing functionality into its own bbclass
In the future more secure boot implementations will be offered, with each one needing the signing method. Instead of repeating a forty line block of code across several recipes, just use a configurable bbclass. Signed-off-by: California Sullivan <california.l.sullivan@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'classes/uefi-sign.bbclass')
-rw-r--r--classes/uefi-sign.bbclass50
1 files changed, 50 insertions, 0 deletions
diff --git a/classes/uefi-sign.bbclass b/classes/uefi-sign.bbclass
new file mode 100644
index 00000000..e8f203b9
--- /dev/null
+++ b/classes/uefi-sign.bbclass
@@ -0,0 +1,50 @@
+# By default, sign all .efi binaries in ${B} after compiling and before deploying
+SIGNING_DIR ?= "${B}"
+SIGNING_BINARIES ?= "*.efi"
+SIGN_AFTER ?= "do_compile"
+SIGN_BEFORE ?= "do_deploy"
+
+python () {
+ import os
+ import hashlib
+
+ # Ensure that if the signing key or cert change, we rerun the uefiapp process
+ if bb.utils.contains('IMAGE_FEATURES', 'secureboot', True, False, d):
+ for varname in ('SECURE_BOOT_SIGNING_CERT', 'SECURE_BOOT_SIGNING_KEY'):
+ filename = d.getVar(varname)
+ if filename is None:
+ bb.fatal('%s is not set.' % varname)
+ if not os.path.isfile(filename):
+ bb.fatal('%s=%s is not a file.' % (varname, filename))
+ with open(filename, 'rb') as f:
+ data = f.read()
+ hash = hashlib.sha256(data).hexdigest()
+ d.setVar('%s_HASH' % varname, hash)
+
+ # Must reparse and thus rehash on file changes.
+ bb.parse.mark_dependency(d, filename)
+
+ bb.build.addtask('uefi_sign', d.getVar('SIGN_BEFORE'), d.getVar('SIGN_AFTER'), d)
+
+ # Original binary needs to be regenerated if the hash changes since we overwrite it
+ # SIGN_AFTER isn't necessarily when it gets generated, but its our best guess
+ d.appendVarFlag(d.getVar('SIGN_AFTER'), 'vardeps', 'SECURE_BOOT_SIGNING_CERT_HASH SECURE_BOOT_SIGNING_KEY_HASH')
+}
+
+do_uefi_sign() {
+ if [ -f ${SECURE_BOOT_SIGNING_KEY} ] && [ -f ${SECURE_BOOT_SIGNING_CERT} ]; then
+ for i in `find ${SIGNING_DIR}/ -name '${SIGNING_BINARIES}'`; do
+ sbsign --key ${SECURE_BOOT_SIGNING_KEY} --cert ${SECURE_BOOT_SIGNING_CERT} $i
+ sbverify --cert ${SECURE_BOOT_SIGNING_CERT} $i.signed
+ mv $i.signed $i
+ done
+ fi
+}
+
+do_uefi_sign[depends] += "sbsigntool-native:do_populate_sysroot"
+
+do_uefi_sign[vardeps] += "SECURE_BOOT_SIGNING_CERT_HASH \
+ SECURE_BOOT_SIGNING_KEY_HASH \
+ SIGNING_BINARIES SIGNING_DIR \
+ SIGN_BEFORE SIGN_AFTER \
+ "