KORTHVEILSecurity firewall
Guides

Secure Boot and the TPM-sealed state key

Download as PDF All guides

Secure Boot makes the firewall's firmware check every boot file before it starts it: the boot loader, the system, and the small add-on that says which system slot (A or B) to start. A boot file that was changed, or that Korthveil did not sign, does not start. The TPM-sealed state key keeps a key inside the firewall's TPM chip that only comes out when the firewall starts the way it did when the key was sealed, from a boot file Korthveil signed; the firewall encrypts the passwords and keys in its configuration with it.

Both are off until you turn them on, and turning them on never changes how updates work: the A/B update, going back to the previous version, the boot menu's recovery entry and the failsafe copy (C) all work the same with Secure Boot on.

You need a firewall that starts in UEFI mode (every Korthveil install does) and, for the state key, a TPM 2.0 (most boards from the last ten years have one; on Intel it is often called PTT, on AMD fTPM).

Which way to trust Korthveil

The firmware only starts what its own key lists allow. There are two ways to add Korthveil:

  • Firmware keys (db): you add the Korthveil certificate to the firmware's list of allowed keys (db). The firmware then checks the Korthveil boot loader itself. Choose this when the firmware setup lets you add a key from a file, which most servers and many mini PCs do.
  • Shim (Microsoft keys): the firmware keeps only the keys it came with (Microsoft's). The shim, signed by Microsoft, starts first and checks Korthveil against a Machine Owner Key (MOK) you enroll once at the console. Choose this when the firmware has no way to add a key, or when you must keep the factory keys.

The Korthveil installer starts through shim, so it boots on most machines with Secure Boot on: the USB image from 1.5.4, and from 1.5.5 also the DVD and a USB stick written from the ISO. If the installer itself started with Secure Boot on, the firewall is prepared for Secure Boot during the install, in shim mode.

Prepare the firewall

  1. Install a signed Korthveil version (1.5.4 or newer) with an A/B update or the installer. A firewall updated only with small layer updates keeps its older, unsigned boot files: the page says so and asks for a full update.
  2. Open System › Certificates & encryption › Secure Boot. Before it is prepared, the panel says so and names the next step.
System › Certificates & encryption › Secure Boot on a test firewall that was never prepared: Secure Boot is off, the boot files are already signed, the Korthveil certificate is not enrolled, and the panel suggests Prepare.
System › Certificates & encryption › Secure Boot on a test firewall that was never prepared: Secure Boot is off, the boot files are already signed, the Korthveil certificate is not enrolled, and the panel suggests Prepare.
  1. In the Secure Boot panel, choose Prepare: firmware keys (db) or Prepare: shim (Microsoft keys).
  2. The panel shows what was done, for example "the boot loader is the Korthveil-signed systemd-boot" and "EFI/korthveil/slot-a.efi names slot A".

Preparing only changes the firewall's own boot partition: it puts the signed boot loader in place, adds the slot add-ons next to each slot's boot file, and copies the Korthveil certificate (korthveil-secureboot.der) to the top of the boot partition. It never changes the firmware's keys; that stays your step, below.

After Prepare (firmware keys) and an update to slot B on a test firewall with Secure Boot on: the badge says On and verified (firmware keys); the firewall started through systemd-boot from EFI/korthveil/slot-b.efi, signed with the Korthveil key, the Korthveil certificate is in the firmware's db, and the slot add-ons name slot A and slot B next to their boot files.
After Prepare (firmware keys) and an update to slot B on a test firewall with Secure Boot on: the badge says On and verified (firmware keys); the firewall started through systemd-boot from EFI/korthveil/slot-b.efi, signed with the Korthveil key, the Korthveil certificate is in the firmware's db, and the slot add-ons name slot A and slot B next to their boot files.

To have the certificate on your computer, use Certificate (.der) (or Signature list (.esl) for firmware that wants that format). Check its fingerprint against the one on the page before you enroll it. Example of what the page shows: 1b21 a69a d6c6 2302.

Enroll the key in the firmware (firmware keys)

The menu names differ between boards. The steps are usually:

  1. Restart the firewall and open the firmware setup (often Del, F2 or F10 while the board logo shows).
  2. Find Security › Secure Boot (or Boot › Secure Boot).
  3. Set Secure Boot Mode to Custom (some boards call it Expert Key Management).
  4. Choose db (or Authorized Signatures), then Append or Enroll from file, and pick korthveil-secureboot.der from the boot partition (named ESP or EFI) or from a USB stick. Keep the keys already there: many add-in cards need them.
  5. Set Secure Boot to Enabled, save and exit.

The pictures show one firmware, a virtual machine's (OVMF); your board's menus look different but have the same steps.

Device Manager › Secure Boot Configuration: Secure Boot enabled, Secure Boot Mode Standard. Choose Custom Mode to see the key options.
Device Manager › Secure Boot Configuration: Secure Boot enabled, Secure Boot Mode Standard. Choose Custom Mode to see the key options.
Custom Secure Boot Options: choose DB Options (the allowed keys).
Custom Secure Boot Options: choose DB Options (the allowed keys).
DB Options › Enroll Signature: choose Enroll Signature Using File, then Commit Changes and Exit after picking the file.
DB Options › Enroll Signature: choose Enroll Signature Using File, then Commit Changes and Exit after picking the file.
The file explorer on the boot partition: korthveil-secureboot.der is at its top level.
The file explorer on the boot partition: korthveil-secureboot.der is at its top level.

If the firmware is in setup mode (no platform key), the page says so. Let the firmware restore its default keys first, then append the Korthveil certificate to db.

Enroll the key with MokManager (shim)

  1. In the firmware setup, set Secure Boot to Enabled (keep the factory keys), save and exit.
  2. The first start after that stops at Verification failed: (0x1A) Security Violation, because Korthveil is not trusted yet. Press Enter (OK).
  3. A blue screen follows, Shim UEFI key management (MokManager). Press a key within 10 seconds.
  4. Choose Enroll key from disk, open the boot partition if it asks, and select korthveil-secureboot.der.
  5. Choose Continue, then Yes, then Reboot.
  6. The firewall starts Korthveil. MokManager only appears again if the key is removed.
The first start through shim before the key is enrolled: Verification failed. Press Enter.
The first start through shim before the key is enrolled: Verification failed. Press Enter.
Shim UEFI key management: press any key before the countdown ends.
Shim UEFI key management: press any key before the countdown ends.
Perform MOK management: choose Enroll key from disk.
Perform MOK management: choose Enroll key from disk.
Select Key: korthveil-secureboot.der at the top level of the boot partition.
Select Key: korthveil-secureboot.der at the top level of the boot partition.
Enroll MOK: View key 0 shows the certificate before you enroll it; choose Continue.
Enroll MOK: View key 0 shows the certificate before you enroll it; choose Continue.
Enroll the key(s)?: choose Yes.
Enroll the key(s)?: choose Yes.
Back in the menu: choose Reboot. The next start goes on into Korthveil.
Back in the menu: choose Reboot. The next start goes on into Korthveil.

You need a keyboard and a screen (or the server's remote console) for these steps, once per firewall.

Check that it works

Open System › Certificates & encryption › Secure Boot after the restart:

  • The badge says On and verified (firmware keys) or On and verified (shim, Machine Owner Key).
  • Running boot file names the slot in use, for example EFI/korthveil/slot-a.efi (slot A), signed with the Korthveil key. On and verified the shim way: started through shim and systemd-boot, the Korthveil certificate enrolled as a Machine Owner Key.

  • Firmware keys lists the platform key, the key exchange keys, db (with Korthveil next to the Korthveil certificate in the firmware-keys way) and the Machine Owner Keys (in the shim way).

Firmware keys opened: the platform key and key exchange keys of this test firmware, db with Microsoft's keys and the Korthveil certificate (marked Korthveil), no Machine Owner Keys, and the revoked list (dbx).
Firmware keys opened: the platform key and key exchange keys of this test firmware, db with Microsoft's keys and the Korthveil certificate (marked Korthveil), no Machine Owner Keys, and the revoked list (dbx).

If the firmware has Secure Boot on but the firewall was never prepared, Korthveil prepares it at the next start by itself, so the next update starts the right slot.

Updates, going back and the failsafe copy

  • Every signed image signs its own boot files. An A/B update writes the new boot file and keeps the slot add-ons next to both slots. If Secure Boot is on and an update's boot file is not signed with the Korthveil key, the update stops before anything changes and System › Updates says why.
  • Going back works as before. A version that does not finish starting is left by itself, and the previous slot starts again, checked by Secure Boot like any other start.
  • The failsafe copy (C) carries its own add-on for the slot it restores onto. Its boot menu entry works with Secure Boot on.
  • The boot menu's recovery entry (last good configuration) works with Secure Boot on.
  • A remote reinstall through SentinelOps works with Secure Boot on from 1.5.5. Secure Boot ignores the options of the one-time boot entry, so the firewall also writes the installer's settings to its boot partition (EFI/korthveil-reinstall/installer.options), and the installer reads them from there. The installer must be 1.5.5 or newer and signed with the Korthveil key: otherwise the firewall refuses the reinstall before it restarts, changes nothing, and SentinelOps shows why. Use an A/B update in that case.

Seal the state key to the TPM

The TPM-sealed state key panel on the same page starts with a pre-check: the TPM's version, its PCR banks (SHA-256 is needed), and PCR 7, the measurement of the Secure Boot state and the keys that checked this start.

The pre-check on a test firewall with a TPM 2.0: four PCR banks including SHA-256, PCR 7, Ready for sealing Yes, and Turn on sealing.
The pre-check on a test firewall with a TPM 2.0: four PCR banks including SHA-256, PCR 7, Ready for sealing Yes, and Turn on sealing.
  1. Choose Turn on sealing. The TPM seals a new state key, and the firewall encrypts the passwords and keys in its configuration with it.
  2. The page shows the recovery key, once. It looks like this example (not a real key): 0a1b2c3d-4e5f6a7b-8c9d0e1f-2a3b4c5d-6e7f8a9b-0c1d2e3f-4a5b6c7d-8e9f0a1b.
  3. Write it down, or store it in your password manager, away from the firewall. Then choose I have stored it. The firewall never stores the recovery key, never logs it, and can't show it again.
The recovery key, shown once after Turn on sealing. The key in this picture is an example, not a real key.
The recovery key, shown once after Turn on sealing. The key in this picture is an example, not a real key.

From now on, every start unlocks the state key by itself, and the panel says what the key is sealed to and what it encrypts:

The panel on a test firewall with sealing on, after a restart: sealed to PCR 7 and the Korthveil-signed PCR 11 policy, unlocked at this start, and the configuration's passwords and keys stored encrypted with the state key, in every revision of its history too.
The panel on a test firewall with sealing on, after a restart: sealed to PCR 7 and the Korthveil-signed PCR 11 policy, unlocked at this start, and the configuration's passwords and keys stored encrypted with the state key, in every revision of its history too.

What the key is sealed to

  • PCR 7: the Secure Boot state and the keys that checked this start.
  • PCR 11, signed by Korthveil: the Korthveil boot file that started (its system, start-up files and built-in command line). Every Korthveil boot file carries a prediction of its own PCR 11, signed with the Korthveil PCR key; the TPM accepts any start Korthveil signed a prediction for. A boot file that was changed does not unlock the key.

An A/B update or going back unlocks by itself: the new boot file brings its own signed prediction, and PCR 7 stays the same, so nothing is sealed again. An update that only restarts the programs (the kernel keeps running) keeps the key unlocked too.

A firewall that had sealing on before Korthveil 1.5.5 keeps its seal on PCR 7 alone until every system on it (both slots and the failsafe copy C) is Korthveil 1.5.5 or later; the panel says which one is older. At the first start after that, the firewall seals the key to PCR 7 and the signed PCR 11 by itself.

What the key encrypts

  • The passwords and keys in the configuration: every setting the configuration keeps as a secret (for example the e-mail server password, RADIUS and LDAP secrets, SNMPv3 passwords, Wi-Fi passphrases, network storage secrets, API tokens, and the passwords and keys of add-ins). They are encrypted in the running configuration, in the pending changes, and in every revision of the history. The rest of the configuration (interfaces, zones, rules) is stored as before, so the firewall always starts with its rules.
  • When sealing is turned on, the passwords and keys already stored are encrypted at once, the history included, and the firewall's copies of its database (the failsafe copy C and the copy an update keeps) follow.
  • While another system on the firewall is older than Korthveil 1.5.5 (the other slot after an update from 1.5.4), the passwords and keys are stored as before, so going back to it keeps working; the panel says so. They are encrypted at the first start where every system is 1.5.5 or later.
  • An update to a version older than 1.5.5 is refused while the passwords and keys are encrypted: turn sealing off first.
  • Backups carry the passwords and keys encrypted with the backup's own passphrase, not with the state key, so a backup restores on any firewall. While the state key is locked (safe mode), a backup with the configuration's history can't be made: unlock first.

The recovery key is what opens the state key when the TPM refuses it. Without the recovery key, a firewall in safe mode can't open its passwords and keys again.

When the TPM refuses: safe mode

A firmware update, Secure Boot turned off or on, or new keys in the firmware change PCR 7, and the TPM refuses to release the state key. The firewall still starts: the network and the last ruleset come up as always, and the state key stays locked (safe mode). The console prints why, and asks for the recovery key.

In safe mode:

  • The passwords and keys in the configuration stay encrypted. Add-ins whose settings hold them wait (the panel lists them), and features that need a stored password can't use it (for example notifications by e-mail, sign-ins through RADIUS or LDAP, network storage, the Wi-Fi passphrase).
  • Nothing can be committed: changes you make are kept as pending changes, but new passwords or keys can't be saved until you unlock.

To unlock:

  • At the console: type the recovery key when asked, or
  • In System › Certificates & encryption › Secure Boot: type the recovery key in the TPM-sealed state key panel and choose Unlock and seal again.
Locked after a key was added to the firmware's db (PCR 7 changed): the reason, safe mode, the passwords and keys staying encrypted until the recovery key is given, and the recovery key typed in the box (an example key) before Unlock and seal again.
Locked after a key was added to the firmware's db (PCR 7 changed): the reason, safe mode, the passwords and keys staying encrypted until the recovery key is given, and the recovery key typed in the box (an example key) before Unlock and seal again.

The TPM then seals the key again to the new PCR 7 (and the signed PCR 11), so the next start unlocks by itself. The waiting add-ins start at once, without a restart. A wrong key changes nothing.

Planning a firmware update? A firmware update changes PCR 7, so the first start after it is in safe mode. Have the recovery key at hand before you start it, and type it at the console or in System › Certificates & encryption › Secure Boot after the update.

Turn it off

  • Sealing: type TURN OFF and choose Turn off sealing. The passwords and keys are first stored as before again (the history and the database copies too), then the sealed key and its recovery copy are removed.
  • Sealing, without the recovery key (safe mode, key lost): type TURN OFF AND FORGET and choose Turn off sealing. The encrypted passwords and keys can then never be opened: they still show as set, but you must enter each one again.
  • Secure Boot: turn it off in the firmware setup. The prepared boot files keep working with Secure Boot off; nothing else needs to change.

What is not done yet

  • The state key encrypts the configuration's passwords and keys only. The administrators' password hashes, the certificates' private keys, the SSH host keys, the network storage keys and the add-ins' own data are stored as before (readable by the firewall's system account only).
  • With Secure Boot off, a changed boot menu entry can still change the system's command line without changing PCR 7 or PCR 11 (the change is measured in PCR 12, which differs between the slots and is not used). Seal with Secure Boot on.

Download as PDF All guides