Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
uefi_secure_boot [2017/11/08 08:23] – brot | uefi_secure_boot [2017/11/08 10:14] – [Getting there] brot | ||
---|---|---|---|
Line 31: | Line 31: | ||
==== Getting there ==== | ==== Getting there ==== | ||
- | < | + | === first steps: new bootloader and EFI-stub-kernel === |
- | #installing systemd-boot | + | |
+ | First we will change the bootloader and ensure that we can load an unsigned EFI-Stub-kernel, | ||
+ | |||
+ | == installing systemd-boot | ||
+ | |||
+ | The EFI System Partition (ESP) needs to be mounted, and the efivars need to be readable | ||
+ | |||
+ | <code bash> | ||
bootctl --path=/ | bootctl --path=/ | ||
+ | </ | ||
+ | |||
+ | == New EFI-bootable kernel image == | ||
+ | <code bash> | ||
+ | cd / | ||
+ | make menuconfig | ||
+ | |||
+ | # set CONFIG_EFI_STUB=y | ||
- | #new efi-stub kernel | ||
- | cd / | ||
- | (set efi-stub to y) | ||
make -j6 && make modules_install | make -j6 && make modules_install | ||
cp ./ | cp ./ | ||
+ | |||
+ | #also, new initrd | ||
dracut / | dracut / | ||
+ | </ | ||
+ | |||
+ | == Add the new kernel to the systemd-boot list == | ||
- | brot-thinkpad-t470s linux # cat / | + | <file bash / |
timeout 3 | timeout 3 | ||
default gentoo | default gentoo | ||
- | + | </ | |
- | brot-thinkpad-t470s linux # cat / | + | <file bash / |
title Gentoo | title Gentoo | ||
linux /kernel.efi | linux /kernel.efi | ||
initrd | initrd | ||
options | options | ||
+ | </ | ||
+ | == test the new bootloader and EFI-kernel == | ||
+ | Try to boot the new kernel with systemd-boot. If something goes wrong, you can just use the previous bootloader (in most cases GRUB2) by selecting it in the UEFI boot menu. | ||
+ | |||
+ | === preparing for secure boot: creating keys === | ||
+ | I got most of the commands for the keygeneration and the key-entry from the wonderful [[https:// | ||
+ | |||
+ | == key and signature list generation == | ||
+ | |||
+ | We generate the PK (Plattform Key), KEK (Key Exchange Key) and a DB (Signature Database) certs and keys. The DB will be used to sign our kernel, however, the PK needs to sign the KEK and the KEK will sign the DB key. Also, we get the current keys from EFI and create merged signature lists - so that we can keep the Microsoft Keys if we want to. | ||
+ | |||
+ | <code bash> | ||
+ | mkdir / | ||
+ | |||
+ | #create new keys - save the passwords somewhere save, and create a backup of the keys. | ||
+ | openssl req -new -x509 -newkey rsa:2048 -subj "/ | ||
+ | openssl req -new -x509 -newkey rsa:2048 -subj "/ | ||
+ | openssl req -new -x509 -newkey rsa:2048 -subj "/ | ||
+ | |||
+ | #get current state of the key-databases | ||
+ | efi-readvar -v PK -o old_PK.esl | ||
+ | efi-readvar -v KEK -o old_KEK.esl | ||
+ | efi-readvar -v db -o old_db.esl | ||
+ | |||
+ | #for insertion into the UEFI we need siglists | ||
+ | cert-to-efi-sig-list -g " | ||
+ | sign-efi-sig-list -k PK.key -c PK.crt PK PK.esl PK.auth | ||
+ | cert-to-efi-sig-list -g " | ||
+ | sign-efi-sig-list -a -k PK.key -c PK.crt KEK KEK.esl KEK.auth | ||
+ | cert-to-efi-sig-list -g " | ||
+ | sign-efi-sig-list -a -k KEK.key -c KEK.crt db db.esl db.auth | ||
+ | |||
+ | #create compound-signature-lists - so that we preserve the Microsoft and OEM Keys. | ||
+ | cat old_KEK.esl KEK.esl > compound_KEK.esl | ||
+ | cat old_db.esl db.esl > compound_db.esl | ||
+ | sign-efi-sig-list -k PK.key -c PK.crt KEK compound_KEK.esl compound_KEK.auth | ||
+ | sign-efi-sig-list -k KEK.key -c KEK.crt db compound_db.esl compound_db.auth | ||
</ | </ | ||
- | -> Funktioniert! | + | == changing to setup mode/ |
- | < | + | Go in the UEFI-Setup, navigate to the Secure Boot settings. There should be a option to either enter "Setup Mode" |
- | mkdir /root/efi-keys-try1 | + | |
- | cd / | + | |
- | openssl req -new -x509 -newkey rsa:2048 -subj "/CN=brot platform key/" | + | |
- | openssl req -new -x509 -newkey rsa:2048 -subj "/CN=brot key-exchange-key/ | + | |
- | openssl req -new -x509 -newkey rsa:2048 -subj "/ | + | |
+ | <code bash> | ||
+ | # Variant: Keep OEM and Microsoft keys | ||
+ | efi-updatevar -e -f compound_db.esl db | ||
+ | efi-updatevar -e -f compound_KEK.esl KEK | ||
+ | efi-updatevar -f PK.auth PK | ||
+ | </ | ||
+ | <code bash> | ||
+ | # Variant: Only own keys | ||
+ | efi-updatevar -e -f db.esl db | ||
+ | efi-updatevar -e -f KEK.esl KEK | ||
+ | efi-updatevar -f PK.auth PK | ||
+ | </ | ||
- | dracut / | + | After the PK has been set, the system should switch to "User Mode" |
+ | |||
+ | == building a new kernel and signing it == | ||
+ | Thanks to [[https:// | ||
+ | |||
+ | <code bash> | ||
+ | cd / | ||
+ | dracut ./ | ||
cat / | cat / | ||
+ | objcopy --add-section .osrel=/ | ||
+ | sbsign --key db.key --cert db.crt --output / | ||
+ | </ | ||
+ | We need to add this new kernel as a new boot-entry in systemd-boot | ||
- | objcopy --add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 --add-section .cmdline=" | + | < |
+ | title Kernel signed | ||
+ | linux /kernel-signed.efi | ||
+ | </file> | ||
- | sbsign | + | Also, we need to sign the systemd-boot bootloader |
- | sbsign --key db.key --cert db.crt --output systemd-bootx64.efi / | + | <code bash> |
+ | #sign the bootloader | ||
+ | cp / | ||
+ | sbsign --key db.key --cert db.crt --output | ||
</ | </ | ||
- | === Dependencies (on gentoo) === | + | Everything should be prepared for the first Secure boot :) |
- | < | + | |
- | emerge -av pesign efitools | + | |
- | </ | + | |
+ | === First secure boot === | ||
+ | Even after the "User Mode" has been enabled, Secure Boot itself should still be disabled. We should change that in the UEFI setup, and try to boot the signed bootloader and the signed kernel-initramfs-blob. If everything works now, good job, you can now secure boot. | ||
+ | |||
+ | :!: **If you have no password for the UEFI setup, Secure Boot can just be disabled. So, for Secure Boot to be effective, set a reasonable safe password for the UEFI Setup.** :!: | ||
+ | |||
+ | === Creating new kernel === | ||
+ | Now, with Secure Boot working, we want a faster method of creating new kernels and signing those. I use the following command line to generate new kernels. | ||
+ | |||
+ | <code bash> | ||
+ | export KVER=`make kernelversion` && make -j6 && make modules_install && dracut ./ | ||
+ | </ | ||
==== Helpful Information ==== | ==== Helpful Information ==== |