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