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

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