Skip to content

Commit d2fa19b

Browse files
Domenico PanellaDomenico Panella
authored andcommitted
New feature: bootloader signing
1 parent e9dea2d commit d2fa19b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

mklive.sh.in

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ directory if unset).
8282
-C "cmdline args" Add additional kernel command line arguments.
8383
-T "title" Modify the bootloader title.
8484
-v linux<version> Install a custom Linux version on ISO image (linux meta-package if unset).
85+
-d <key-file> Set a key file to sign bootloader.
86+
-t <cert-file> Set a certificate file to sign bootloader.
8587
-K Do not remove builddir.
8688
8789
The $PROGNAME script generates a live image of the Void Linux distribution.
@@ -233,6 +235,13 @@ generate_grub_efi_boot() {
233235
fi
234236
mkdir -p "${GRUB_EFI_TMPDIR}"/EFI/BOOT
235237
cp -f "$VOIDHOSTDIR"/tmp/bootia32.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTIA32.EFI
238+
239+
#Bootloader signing
240+
if ([ $toSign ] && [ -f "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX32.EFI ]);then
241+
print_step "Signing BOOTX32.EFI..."
242+
sbsign --key $DBKEY --cert $DBCRT --output "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX32-signed.EFI "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX32.EFI
243+
fi
244+
236245
xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \
237246
--directory="/usr/lib/grub/x86_64-efi" \
238247
--format="x86_64-efi" \
@@ -244,6 +253,13 @@ generate_grub_efi_boot() {
244253
die "Failed to generate EFI loader"
245254
fi
246255
cp -f "$VOIDHOSTDIR"/tmp/bootx64.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI
256+
257+
#Bootloader signing
258+
if ([ $toSign ] && [ -f "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI ]);then
259+
print_step "Signing BOOTX64.EFI..."
260+
sbsign --key $DBKEY --cert $DBCRT --output "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64-signed.EFI "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI
261+
fi
262+
247263
umount "$GRUB_EFI_TMPDIR"
248264
losetup --detach "${LOOP_DEVICE}"
249265
rm -rf "$GRUB_EFI_TMPDIR"
@@ -289,7 +305,7 @@ generate_iso_image() {
289305
#
290306
# main()
291307
#
292-
while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:v:h" opt; do
308+
while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:v:d:t:h" opt; do
293309
case $opt in
294310
a) BASE_ARCH="$OPTARG";;
295311
b) BASE_SYSTEM_PKG="$OPTARG";;
@@ -307,6 +323,8 @@ while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:v:h" opt; do
307323
C) BOOT_CMDLINE="$OPTARG";;
308324
T) BOOT_TITLE="$OPTARG";;
309325
v) LINUX_VERSION="$OPTARG";;
326+
d) DBKEY="$OPTARG";;
327+
t) DBCRT="$OPTARG";;
310328
h) usage;;
311329
*) usage;;
312330
esac
@@ -337,6 +355,22 @@ if [ "$(id -u)" -ne 0 ]; then
337355
die "Must be run as root, exiting..."
338356
fi
339357

358+
#The -d and -t options are complementary. If one exists, the other must also exist.
359+
#If these options are set, I also check sbsign command.
360+
if ([ -z $DBKEY ] && [ ! -z $DBCRT ]) || ([ ! -z $DBKEY ] && [ -z $DBCRT ]); then
361+
die "Must be set a key and certificate via -d and -t option, exiting..."
362+
elif ([ $DBKEY ] && [ $DBCRT ]); then
363+
if [ $DBKEY ] && [ ! -f $DBKEY ]; then
364+
die "$DBKEY does not exist, exiting..."
365+
elif [ $DBCRT ] && [ ! -f $DBCRT ]; then
366+
die "$DBCRT does not exist, exiting..."
367+
elif ! [ -x "$(command -v sbsign)" ]; then
368+
die "sbsign command does not exist, exiting..."
369+
else
370+
toSign=true
371+
fi
372+
fi
373+
340374
if [ -n "$ROOTDIR" ]; then
341375
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d)
342376
else

0 commit comments

Comments
 (0)