Blame SOURCES/0351-docs-grub-Document-signing-grub-with-an-appended-sig.patch

3efed6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
3efed6
From: Daniel Axtens <dja@axtens.net>
3efed6
Date: Sat, 15 Aug 2020 02:19:36 +1000
3efed6
Subject: [PATCH] docs/grub: Document signing grub with an appended signature
3efed6
3efed6
Signing grub for firmware that verifies an appended signature is a
3efed6
bit fiddly. I don't want people to have to figure it out from scratch
3efed6
so document it here.
3efed6
3efed6
Signed-off-by: Daniel Axtens <dja@axtens.net>
3efed6
---
3efed6
 docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++
3efed6
 1 file changed, 42 insertions(+)
3efed6
3efed6
diff --git a/docs/grub.texi b/docs/grub.texi
b71686
index acace6c07..61c92a1e0 100644
3efed6
--- a/docs/grub.texi
3efed6
+++ b/docs/grub.texi
3efed6
@@ -5789,6 +5789,48 @@ On UEFI platforms, @file{core.img} is a PE binary. Therefore, it can be signed
3efed6
 with a tool such as @command{pesign} or @command{sbsign}. It will also be
3efed6
 necessary to enrol the public key used into a relevant firmware key database.
3efed6
 
3efed6
+@section Signing GRUB with an appended signature
3efed6
+
3efed6
+The @file{core.img} itself can be signed with a Linux kernel module-style
3efed6
+appended signature.
3efed6
+
3efed6
+To support IEEE1275 platforms where the boot image is often loaded directly
3efed6
+from a disk partition rather than from a file system, the @file{core.img}
3efed6
+can specify the size and location of the appended signature with an ELF
3efed6
+note added by @command{grub-install}.
3efed6
+
3efed6
+An image can be signed this way using the @command{sign-file} command from
3efed6
+the Linux kernel:
3efed6
+
3efed6
+@example
3efed6
+@group
3efed6
+# grub.key is your private key and certificate.der is your public key
3efed6
+
3efed6
+# Determine the size of the appended signature. It depends on the signing
3efed6
+# certificate and the hash algorithm
3efed6
+touch empty
3efed6
+sign-file SHA256 grub.key certificate.der empty empty.sig
3efed6
+SIG_SIZE=`stat -c '%s' empty.sig`
3efed6
+rm empty empty.sig
3efed6
+
3efed6
+# Build a grub image with $SIG_SIZE reserved for the signature
3efed6
+grub-install --appended-signature-size $SIG_SIZE --modules="..." ...
3efed6
+
3efed6
+# Replace the reserved size with a signature:
3efed6
+# cut off the last $SIG_SIZE bytes with truncate's minus modifier
3efed6
+truncate -s -$SIG_SIZE /boot/grub/powerpc-ieee1275/core.elf core.elf.unsigned
3efed6
+# sign the trimmed file with an appended signature, restoring the correct size
3efed6
+sign-file SHA256 grub.key certificate.der core.elf.unsigned core.elf.signed
3efed6
+
3efed6
+# Don't forget to install the signed image as required
3efed6
+# (e.g. on powerpc-ieee1275, to the PReP partition)
3efed6
+@end group
3efed6
+@end example
3efed6
+
3efed6
+As with UEFI secure boot, it is necessary to build in the required modules,
3efed6
+or sign them separately.
3efed6
+
3efed6
+
3efed6
 @node Platform limitations
3efed6
 @chapter Platform limitations
3efed6