nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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