Skip to content

Commit d552f7f

Browse files
authored
Merge pull request #930 from c-po/T861-secure-boot
T861: minor improvements to secure-boot certificate handling
2 parents 7509516 + 96f1844 commit d552f7f

File tree

9 files changed

+38
-21
lines changed

9 files changed

+38
-21
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
.build/config
12
build/*
3+
config/*
24
*.pyc
35
packer_build/*
46
packer_cache/*
57
key/*
68
packages/*
79
!packages/*/
8-
data/live-build-config/includes.chroot/var/lib/shim-signed/mok/*
910
/testinstall*.img
1011
/testinstall*.efivars
1112
/*.qcow2

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ clean:
7979
rm -f config/binary config/bootstrap config/chroot config/common config/source
8080
rm -f build.log
8181
rm -f vyos-*.iso
82-
rm -f *.img
82+
rm -f *.img *.efivars
8383
rm -f *.xz
8484
rm -f *.vhd
8585
rm -f *.raw

data/certificates/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.key
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
SIGN_FILE=$(find /usr/lib -name sign-file)
3-
MOK_KEY="/var/lib/shim-signed/mok/MOK.key"
4-
MOK_CERT="/var/lib/shim-signed/mok/MOK.pem"
3+
KERNEL_KEY="/var/lib/shim-signed/mok/vyos-dev-2025-linux.key"
4+
KERNEL_CERT="/var/lib/shim-signed/mok/vyos-dev-2025-linux.pem"
55
VMLINUZ=$(readlink /boot/vmlinuz)
66

77
# All Linux Kernel modules need to be cryptographically signed
@@ -13,10 +13,19 @@ find /lib/modules -type f -name \*.ko | while read MODULE; do
1313
fi
1414
done
1515

16-
if [ ! -f ${MOK_KEY} ]; then
16+
if [ ! -f ${KERNEL_KEY} ] && [ ! -f ${KERNEL_CERT} ]; then
1717
echo "I: Signing key for Linux Kernel not found - Secure Boot not possible"
1818
else
1919
echo "I: Signing Linux Kernel for Secure Boot"
20-
sbsign --key ${MOK_KEY} --cert ${MOK_CERT} /boot/${VMLINUZ} --output /boot/${VMLINUZ}
20+
sbsign --key ${KERNEL_KEY} --cert ${KERNEL_CERT} /boot/${VMLINUZ} --output /boot/${VMLINUZ}
2121
sbverify --list /boot/${VMLINUZ}
22+
rm -f ${KERNEL_KEY}
2223
fi
24+
25+
for cert in $(ls /var/lib/shim-signed/mok/); do
26+
if grep -rq "BEGIN PRIVATE KEY" /var/lib/shim-signed/mok/${cert}; then
27+
echo "Found private key - bailing out"
28+
exit 1
29+
fi
30+
done
31+

data/live-build-config/includes.chroot/var/lib/shim-signed/mok/README.md

-11
This file was deleted.

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# This Dockerfile is installable on both x86, x86-64, armhf and arm64 systems
2020
ARG ARCH=
21-
FROM ${ARCH}debian:bookworm
21+
FROM ${ARCH}debian:bookworm-slim
2222

2323
RUN grep "VERSION_ID" /etc/os-release || (echo 'VERSION_ID="12"' >> /etc/os-release)
2424

scripts/check-qemu-install

+11-1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,16 @@ try:
398398

399399
loginVM(c, log)
400400

401+
#################################################
402+
# Check for no private key contents within the image
403+
#################################################
404+
msg = 'Found private key - bailing out'
405+
c.sendline(f'if sudo grep -rq "BEGIN PRIVATE KEY" /var/lib/shim-signed/mok; then echo {msg}; exit 1; fi')
406+
tmp = c.expect([f'\n{msg}', op_mode_prompt])
407+
if tmp == 0:
408+
log.error(msg)
409+
exit(1)
410+
401411
#################################################
402412
# Installing into VyOS system
403413
#################################################
@@ -879,7 +889,7 @@ except pexpect.exceptions.ExceptionPexpect:
879889
EXCEPTION = 1
880890

881891
except Exception:
882-
log.error('Unknown error occured while VyOS!')
892+
log.error('Unknown error occured!')
883893
traceback.print_exc()
884894
EXCEPTION = 1
885895

scripts/image-build/build-vyos-image

+6
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ if __name__ == "__main__":
367367
shutil.copytree("data/live-build-config/", lb_config_dir)
368368
os.makedirs(lb_config_dir, exist_ok=True)
369369

370+
## Secure Boot - Copy public Keys to image
371+
sb_certs = 'data/certificates'
372+
if os.path.isdir(sb_certs):
373+
shutil.copytree(sb_certs, f'{lb_config_dir}/includes.chroot/var/lib/shim-signed/mok')
374+
370375
# Switch to the build directory, this is crucial for the live-build work
371376
# because the efective build config files etc. are there.
372377
#
@@ -611,6 +616,7 @@ DOCUMENTATION_URL="{build_config['documentation_url']}"
611616
## Configure live-build
612617
lb_config_tmpl = jinja2.Template("""
613618
lb config noauto \
619+
--no-color \
614620
--apt-indices false \
615621
--apt-options "--yes -oAPT::Get::allow-downgrades=true" \
616622
--apt-recommends false \

scripts/package-build/linux-kernel/build-kernel.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ do
3636
done
3737

3838
# Change name of Signing Cert
39-
sed -i -e "s/CN =.*/CN=VyOS build time autogenerated kernel key/" certs/default_x509.genkey
39+
sed -i -e "s/CN =.*/CN=VyOS Networks build time autogenerated Kernel key/" certs/default_x509.genkey
4040

4141
TRUSTED_KEYS_FILE=trusted_keys.pem
4242
# start with empty key file
4343
echo -n "" > $TRUSTED_KEYS_FILE
44-
CERTS=$(find ../../../../data/live-build-config/includes.chroot/var/lib/shim-signed/mok -name "*.pem" -type f || true)
44+
GIT_ROOT=$(git rev-parse --show-toplevel)
45+
CERTS=$(find ${GIT_ROOT}/data/certificates -name "*.pem" -type f || true)
4546
if [ ! -z "${CERTS}" ]; then
4647
# add known public keys to Kernel certificate chain
4748
for file in $CERTS; do

0 commit comments

Comments
 (0)