Skip to content

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 to qemu command
  • 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

  1. Download generate-image.sh
  2. Build LockDown.efi file
  3. Build hello.efi file
  4. Run generate-image.sh script. It'll generate tests.img file containing needed files and certificates
  5. Flash this file to USB drive

LockDown.efi

Dependencies

Steps

  1. Clone and checkout tag v1.2.23

    git clone --depth 1 --branch v1.2.23 https://github.com/Dasharo/meta-dts.git
    
  2. Build efitools recipe which will build LockDown.efi with sample keys

    SHELL=/bin/bash kas-container shell meta-dts/kas-uefi-sb.yml -c "bitbake efitools"`
    
  3. Copy LockDown.efi to directory containing generate-image.sh script.
    File should be inside build/tmp/deploy/images/genericx86_64 directory.
    Sample keys and certificates used in LockDown.efi can be viewed in build/tmp/deploy/images/genericx86_64/sample-keys/uefi_sb_keys

hello.efi

Dependencies

Steps

  1. 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
    
  2. Get source code for EDK2

    git clone --depth 1 --recurse-submodules --shallow-submodules --branch edk2-stable202408 https://github.com/tianocore/edk2.git
    
  3. Add sleep (in this case 2 seconds) to HelloWorld.c otherwise output will disappear too fast for human to see

    cd 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
    
  4. 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
    
  5. Copy built HelloWorld.efi file to directory with generate-image.sh and rename it to hello.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

  1. Enable Secure Boot
  2. Save changes and reboot platform
  3. Boot and log into OS
  4. 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

  1. Add SBO003.001/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Boot SBO004.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                     |
\-------------------------------------------/

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

  1. Enter Secure Boot key management menu

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

Steps

  1. Enter Secure Boot key management menu
  2. Select option to restore Secure Boot keys e.g. Restore Factory Keys and accept
  3. Save changes and reboot platform
  4. 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

  1. Add SBO008.001/cert.der to DB

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

  1. Add SBO009.001/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.001/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.002/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.003/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.004/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.005/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO010.006/cert.der to DB
  2. Save changes and reboot platform
  3. 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

  1. Add SBO011.001/cert.der to DB
  2. Save changes and reboot
  3. 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

  1. Disable Secure Boot
  2. If applicable disable key provisioning (e.g. AMI BIOS)
  3. Remove Secure Boot keys
  4. Save changes and restart platform
  5. Boot and log into OS
  6. Remove old Secure Boot keys

    rm -rf /usr/share/secureboot
    
  7. Generate new Secure Boot keys

    $ sbctl create-keys
    Created Owner UUID 2a602183-aee8-4998-a313-25635405d554
    Creating secure boot keys...✓
    Secure boot keys created!
    
  8. 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!
    
  9. Reboot platform

  10. Enter Secure Boot key management menu
  11. Check enrolled KEK GUID
  12. 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

Steps

  1. Boot and log into OS
  2. 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
    
  3. Reboot platform

  4. Enable Secure Boot
  5. Save changes and restart platform
  6. Boot and log into OS
  7. 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

  1. Disable Secure Boot
  2. If applicable disable key provisioning (e.g. AMI BIOS)
  3. Remove Secure Boot keys
  4. Save changes and restart platform
  5. Boot and log into OS
  6. Remove old Secure Boot keys

    rm -rf /usr/share/secureboot
    
  7. Generate new Secure Boot keys

    $ sbctl create-keys
    Created Owner UUID 2a602183-aee8-4998-a313-25635405d554
    Creating secure boot keys...✓
    Secure boot keys created!
    
  8. 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/
    
  9. 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

  1. Disable Secure Boot
  2. If applicable disable key provisioning (e.g. AMI BIOS)
  3. Remove Secure Boot keys
  4. Save changes and restart platform
  5. Boot SBO013.001/LockDown.efi file
  6. Wait until platform reboots automatically
  7. Enable Secure Boot
  8. Save changes and restart
  9. 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

Steps

  1. Disable Secure Boot
  2. Save changes and restart platform.
  3. Boot and log into OS
  4. Mount USB drive with tests if it wasn't mounted automatically
  5. Export currently enrolled certificate

    mokutil --kek > current_certificate.crt
    
  6. 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