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

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