Verifying Secure Boot
Prerequisites
- Restore BIOS to defaults.
-
Attached USB drive prepared in USB drive section
- If using QEMU
tests.img
can be attached directly e.g. via adding-drive if=ide,file=tests.img
argument toqemu
command
- If using QEMU
-
Before starting tests please boot to OS on machine to be tested, mount USB drive and run
add-boot-options.sh
script. It should add all.efi
files to boot options
USB drive
- Download generate-image.sh
- Build LockDown.efi file
- Build hello.efi file
- Run
generate-image.sh
script. It'll generatetests.img
file containing needed files and certificates - Flash this file to USB drive
LockDown.efi
Dependencies
Steps
-
Clone and checkout tag
v1.2.23
git clone --depth 1 --branch v1.2.23 https://github.com/Dasharo/meta-dts.git
-
Build
efitools
recipe which will buildLockDown.efi
with sample keysSHELL=/bin/bash kas-container shell meta-dts/kas-uefi-sb.yml -c "bitbake efitools"`
-
Copy
LockDown.efi
to directory containinggenerate-image.sh
script. File should be insidebuild/tmp/deploy/images/genericx86_64
directory. Sample keys and certificates used inLockDown.efi
can be viewed inbuild/tmp/deploy/images/genericx86_64/sample-keys/uefi_sb_keys
hello.efi
Dependencies
Steps
-
Pull docker image that'll contain tools needed to build
hello.efi
https://github.com/tianocore/containers?tab=readme-ov-file#Current-Status.docker pull ghcr.io/tianocore/containers/fedora-39-build:46802aa
-
Get source code for EDK2
git clone --depth 1 --recurse-submodules --shallow-submodules --branch edk2-stable202408 https://github.com/tianocore/edk2.git
-
Add sleep (in this case 2 seconds) to
HelloWorld.c
otherwise output will disappear too fast for human to seecd edk2 git apply <<EOF diff --git a/MdeModulePkg/Application/HelloWorld/HelloWorld.c b/MdeModulePkg/Application/HelloWorld/HelloWorld.c index 9b77046e561c..ebd4ad9d6a79 100644 --- a/MdeModulePkg/Application/HelloWorld/HelloWorld.c +++ b/MdeModulePkg/Application/HelloWorld/HelloWorld.c @@ -56,5 +56,6 @@ UefiMain ( } } + SystemTable->BootServices->Stall(2000000); return EFI_SUCCESS; } EOF
-
Build
HelloWorld.efi
docker run -v $(pwd):/edk2 -w /edk2 --entrypoint bash --rm \ ghcr.io/tianocore/containers/fedora-39-build:46802aa -c ' \ source edksetup.sh && make -C BaseTools && build -a X64 -t GCC5 \ -p MdeModulePkg/MdeModulePkg.dsc \ -m MdeModulePkg/Application/HelloWorld/HelloWorld.inf -b RELEASE'
Build should complete with
(...) - Done - Build end time: 12:51:06, Oct.04 2024 Build total time: 00:00:06
-
Copy built
HelloWorld.efi
file to directory withgenerate-image.sh
and rename it tohello.efi
cp Build/MdeModule/RELEASE_GCC5/X64/HelloWorld.efi <replace/this/path/>hello.efi
USB directory layout
.
├── add-boot-options.sh
├── SBO003.001
│ ├── cert.der
│ └── hello.efi
├── SBO004.001
│ ├── cert.der
│ └── hello.efi
├── SBO008.001
│ ├── cert.der
│ └── hello.efi
├── SBO009.001
│ ├── cert.der
│ └── hello.efi
├── SBO010.001
│ ├── cert.der
│ └── hello.efi
├── SBO010.002
│ ├── cert.der
│ └── hello.efi
├── SBO010.003
│ ├── cert.der
│ └── hello.efi
├── SBO010.004
│ ├── cert.der
│ └── hello.efi
├── SBO010.005
│ ├── cert.der
│ └── hello.efi
├── SBO010.006
│ ├── cert.der
│ └── hello.efi
├── SBO011.001
│ ├── cert.der
│ └── hello.efi
├── SBO013.001
│ ├── hello.efi
│ └── LockDown.efi
└── SBO013.002
└── KEK.crt
14 directories, 26 files
Tests
On ODROID-H4, BIOS version ADLN-H4 1.05 there is a weird quirk in when you can edit SB settings (e.g. state, adding certificates or restoring to default). It's described in more details on ODROID forum. Due to that you should reboot platform before each test.
SBO002.001 Secure Boot can be enabled from boot menu and is seen from OS
Description
This test verifies that Secure Boot can be enabled from the boot menu and, after the platform reset, it is seen from the OS.
Steps
- Enable Secure Boot
- Save changes and reboot platform
- Boot and log into OS
-
Enter the following command and note the output
dmesg | grep "Secure boot"
Expected result:
secureboot: Secure boot enabled
SBO003.001 Attempt to boot file signed with the correct key
Description
This test verifies that Secure Boot allows booting a signed file with a correct key.
Prerequisites
Steps
- Add SBO003.001/cert.der to DB
- Save changes and reboot platform
- Boot SBO003.001/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO004.001 Attempt to boot unsigned file
Description
This test verifies that Secure Boot blocks booting unsigned file.
Prerequisites
Steps
Expected result
Booting file should fail with Secure Boot error e.g.:
/---------- Secure Boot Violation ----------\
| |
| Invalid signature detected. Check Secure |
| Boot Policy in Setup |
| |
|-------------------------------------------|
| Ok |
\-------------------------------------------/
SBO006.001 Reset Secure Boot Keys option availability
Description
This test aims to verify, that the Reset Secure Boot Keys option is available
Prerequisites
Steps
Expected result
Option to restore SB keys should be available e.g.
Restore Factory Keys
SBO007.001 Attempt to boot the file after restoring keys to default
Description
This test verifies that the Reset Secure Boot Keys option works correctly.
Prerequisites
- SBO003.001 succeeded
- SBO006.001 succeeded
- Enabled Secure Boot
Steps
- Enter Secure Boot key management menu
- Select option to restore Secure Boot keys e.g.
Restore Factory Keys
and accept - Save changes and reboot platform
- Boot SBO003.001/hello.efi file
Expected result
Booting file should fail with Secure Boot error e.g.:
/---------- Secure Boot Violation ----------\
| |
| Invalid signature detected. Check Secure |
| Boot Policy in Setup |
| |
|-------------------------------------------|
| Ok |
\-------------------------------------------/
SBO008.001 Attempt to enroll the key in the incorrect format
Description
This test verifies that Secure Boot doesn't allow enrolling keys in the incorrect format
Prerequisites
Steps
Expected result
Adding certificate should end in failure e.g.
┌── Append ───┐
│ │
│ Failed │
│ │
├──────────────┤
│ Ok │
└──────────────┘
SBO009.001 Attempt to boot file signed for intermediate certificate
Description
This test verifies that a file signed with an intermediate certificate can be executed.
Prerequisites
Steps
- Add SBO009.001/cert.der to DB
- Save changes and reboot platform
- Boot SBO009.001/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.001 Check support for rsa2k signed certificates
Description
This test verifies that a Secure Boot supports RSA2048 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.001/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.001/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.002 Check support for rsa3k signed certificates
Description
This test verifies that a Secure Boot supports RSA3072 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.002/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.002/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.003 Check support for rsa4k signed certificates
Description
This test verifies that a Secure Boot supports RSA4096 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.003/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.003/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.004 Check support for ecdsa256 signed certificates
Description
This test verifies that a Secure Boot supports ESCDA256 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.004/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.004/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.005 Check support for ecdsa384 signed certificates
Description
This test verifies that a Secure Boot supports ESCDA384 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.005/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.005/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO010.006 Check support for ecdsa521 signed certificates
Description
This test verifies that a Secure Boot supports ESCDA521 signed certificate and can boot file signed with this certificate.
Prerequisites
Steps
- Add SBO010.006/cert.der to DB
- Save changes and reboot platform
- Boot SBO010.006/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO011.001 Attempt to enroll expired certificate and boot signed image
Description
This test verifies that an expired certificate cannot be used to boot image
Prerequisites
Steps
- Add SBO011.001/cert.der to DB
- Save changes and reboot
- Boot SBO011.001/hello.efi file
Expected result
Booting file should fail with Secure Boot error e.g.:
/---------- Secure Boot Violation ----------\
| |
| Invalid signature detected. Check Secure |
| Boot Policy in Setup |
| |
|-------------------------------------------|
| Ok |
\-------------------------------------------/
SBO014.001 Enroll certificates using sbctl
Description
This test erases Secure Boot keys from the BIOS menu and verifies if new keys can be enrolled from the operating system using sbctl.
Prerequisites
Steps
- Disable Secure Boot
- If applicable disable key provisioning (e.g. AMI BIOS)
- Remove Secure Boot keys
- Save changes and restart platform
- Boot and log into OS
-
Remove old Secure Boot keys
rm -rf /usr/share/secureboot
-
Generate new Secure Boot keys
$ sbctl create-keys Created Owner UUID 2a602183-aee8-4998-a313-25635405d554 Creating secure boot keys...✓ Secure boot keys created!
-
Enroll generated Secure Boot keys
$ sbctl enroll-keys --yes-this-might-brick-my-machine Enrolling keys to EFI variables...✓ Enrolled keys to the EFI variables!
-
Reboot platform
- Enter Secure Boot key management menu
- Check enrolled KEK GUID
- Check enrolled DB GUID
Expected result
KEK and DB keys should have the same GUID as returned by sbctl create-keys
command e.g. 2a602183-aee8-4998-a313-25635405d554
SBO012.001 Boot OS Signed And Enrolled From Inside System
Description
This test verifies that OS boots after enrolling keys and signing system from inside OS.
Prerequisites
- SBO014.001 succeeded
Steps
- Boot and log into OS
-
Sign all components
$ sbctl verify | awk -F ' ' '{print $2}' | tail -n+2 | xargs -I @ sbctl sign "@" ✓ Signed /boot/efi/EFI/BOOT/BOOTX64.EFI ✓ Signed /boot/efi/EFI/BOOT/fbx64.efi ✓ Signed /boot/efi/EFI/BOOT/mmx64.efi ✓ Signed /boot/efi/EFI/ubuntu/grubx64.efi ✓ Signed /boot/efi/EFI/ubuntu/mmx64.efi ✓ Signed /boot/efi/EFI/ubuntu/shimx64.efi
-
Reboot platform
- Enable Secure Boot
- Save changes and restart platform
- Boot and log into OS
-
Verify that Secure Boot is enabled
dmesg | grep "Secure boot"
Expected result
secureboot: Secure boot enabled
SBO015.001 Attempt to enroll the key in the incorrect format with sbctl
Description
This test verifies that it is impossible to load a certificate in the wrong file format from the operating system while using sbctl.
Prerequisites
Steps
- Disable Secure Boot
- If applicable disable key provisioning (e.g. AMI BIOS)
- Remove Secure Boot keys
- Save changes and restart platform
- Boot and log into OS
-
Remove old Secure Boot keys
rm -rf /usr/share/secureboot
-
Generate new Secure Boot keys
$ sbctl create-keys Created Owner UUID 2a602183-aee8-4998-a313-25635405d554 Creating secure boot keys...✓ Secure boot keys created!
-
Generate keys with wrong format and move them to correct location
openssl ecparam -genkey -name secp384r1 -out db.key && openssl req -new -x509 -key db.key -out db.pem -days 365 -subj "/CN=test" openssl ecparam -genkey -name secp384r1 -out PK.key && openssl req -new -x509 -key PK.key -out PK.pem -days 365 -subj "/CN=test" openssl ecparam -genkey -name secp384r1 -out KEK.key && openssl req -new -x509 -key KEK.key -out KEK.pem -days 365 -subj "/CN=test" mv db.key /usr/share/secureboot/keys/db/ mv PK.key /usr/share/secureboot/keys/PK/ mv KEK.key /usr/share/secureboot/keys/KEK/
-
Enroll generated Secure Boot keys
$ sbctl enroll-keys --yes-this-might-brick-my-machine
Expected result
sbctl
should fail to enroll keys
couldn't sync keys
SBO013.001 Check automatic certificate provisioning
Description
This test verifies that the automatic certificate provisioning will install
custom keys which will allow booting signed hello.efi
file
Prerequisites
Steps
- Disable Secure Boot
- If applicable disable key provisioning (e.g. AMI BIOS)
- Remove Secure Boot keys
- Save changes and restart platform
- Boot SBO013.001/LockDown.efi file
- Wait until platform reboots automatically
- Enable Secure Boot
- Save changes and restart
- Boot SBO013.001/hello.efi file
Expected result
Screen should show:
Hello, world!
SBO013.002 Check automatic certificate provisioning KEK certificate
Description
This test verifies that automatic certificate provisioning installed expected KEK certificate
Prerequisites
- SBO013.001 succeeded
Steps
- Disable Secure Boot
- Save changes and restart platform.
- Boot and log into OS
- Mount USB drive with tests if it wasn't mounted automatically
-
Export currently enrolled certificate
mokutil --kek > current_certificate.crt
-
Compare current KEK certificate with one that should be enrolled. Replace
<usb/mount>
with path to where USB drive is mounted.diff <usb/mount>/SBO013.002/KEK.crt current_certificate.crt --color=always
Expected result
No output or slight format differences e.g.
1c1,2
< SHA1 Fingerprint=EA:EF:F4:8A:C2:38:CB:31:98:FD:45:81:6D:64:99:78:61:BB:B7:0C
---
> [key 1]
> SHA1 Fingerprint: ea:ef:f4:8a:c2:38:cb:31:98:fd:45:81:6d:64:99:78:61:bb:b7:0c
8c9
< Issuer: CN = KEK Certificate
---
> Issuer: CN=KEK Certificate
12c13
< Subject: CN = KEK Certificate
---
> Subject: CN=KEK Certificate