Commit b7814bf4 authored by Ophélie Gagnard's avatar Ophélie Gagnard

uefi-keys/: Initial commit.

parent c06241c5
......@@ -18,3 +18,6 @@ apt -y install dracut-core dracut dracut-network
wget https://download.opensuse.org/repositories/home:/fg.nxd/Debian_11/amd64/dep--mca-static_1-1_amd64.deb
apt -y install ./dep--mca-static_1-1_amd64.deb
apt -y install ./fluent-bit_1-1_amd64.deb
# signing initramfs
apt -y install sbsigntool efitools
# To perform the following instructions, some packages are needed.
# They are all installed with apt at the begining of install.sh.
## Create the keys:
# run the script mkkeys.sh (better in a dedicated directory)
mkdir -p generate_keys && cd generate_keys && cp ../mkkeys.sh . && ./mkkeys.sh
## Signing a UEFI application:
# before running the following line (from install.sh)
dracut --force -c ./dracut.module/dracut.conf --confdir dracut_tmp
# put the following from the signing key in /etc/uefi-key/
# db.cer db.crt db.key
## Add keys to the firmware:
# run
efi-readvar
# if PK, KEK or db is not empty then
# reboot and, in the BIOS, disable Secure Boot (SB) and remove every keys
# then if we assume the keys have the name mkkeys.sh gives them:
# Add the Platform Key (the authority key for the machine).
efi-updatevar -f PK.auth PK
# Add the Key Exchange Key (the authority key for the db and dbx certificates and hashes)
efi-updatevar -a -c KEK.crt -k PK.key KEK
# Replace the current whitelist certificate
efi-updatevar -f -c DB.crt -k KEK.key db
# (replace -f with -a to append another whitelist certificate instead of replacing the old one)
### Troubleshooting
# Some general informations:
# 1) As a general matter, with Secure Boot (SB) disabled and no key, every key should addable.
# 2) A Platform Key is needed for Secure Boot (SB) to be enabled.
# 3) To add or modify a key, you need the private key of the upper level (the Platform Key is its own upper level key).
## Common errors:
# error: "Failed to update <var>: Operation not permitted"
# when trying to delete or replace a key, may be resolved by making it mutable:
lsattr /sys/firmware/efi/efivars/{db,dbx,KEK,PK}*
# "----i--------------" before the key means it is set as immutable
# to make it mutable
chattr -i /sys/firmware/efi/efivars/<key>
# (example:)
chattr -i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
# recommanded: make everything immutable after your operation
# to do so, perform the same command with +i instead of -i (same example:)
chattr +i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
# error: "Cannot write to db, wrong filesystem permissions"
# may be resolved providing the upper level private key
# (note that it can happen even with root mode, as keys are stored on a separate filesystem)
-----BEGIN CERTIFICATE-----
MIIDHTCCAgWgAwIBAgIUCXcXOU0UPEBomolNyuOYcJfJoRkwDQYJKoZIhvcNAQEL
BQAwHjEcMBoGA1UEAwwTU3RvcmVkIG9uIGdpdGxhYiBEQjAeFw0yMjA0MDQwOTEz
NDlaFw0zMjA0MDEwOTEzNDlaMB4xHDAaBgNVBAMME1N0b3JlZCBvbiBnaXRsYWIg
REIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDHiUc+MyP+TQDM4s8c
SP1p/luYT1pgfS0H8SBQxy0bhjjCu3YTv38FdXR1pxLVLuwJfK0TYzrsL0DAUjNV
FO45AaC0zbH7eMy4UA6prSEcaqcPgqcyD3Nfg4B/DpwCkdEQVwwT75aR4raG2+QD
/JRe+n/4tY9PhzxsAexOazISEfMigvjWUg3lDWZyo21orObV6YWMYeX5xN+SregU
TwE5W7LANhFTzInnaQJ9lmA7q2d+D3FQ/HM6vNmb1a/TlMlnzbGaWOEbWOaIGpku
ZpTHM+piwm5K5oA7X0rO8Mf5c1X/zuGwLCDj44kFaQlTSV5UMdU5CclvMDK96qcS
ypMrAgMBAAGjUzBRMB0GA1UdDgQWBBTIHsJW7yF4GMQNU4vxilfX56PMSDAfBgNV
HSMEGDAWgBTIHsJW7yF4GMQNU4vxilfX56PMSDAPBgNVHRMBAf8EBTADAQH/MA0G
CSqGSIb3DQEBCwUAA4IBAQAOPzJCyld6PMbuosnwVS0tbv+up157rgGtUB7e4r1O
b8DKxVSMXA5q7ydj0SP6VWExr192n9omxGYolyBHq1OpxT09khjXor1ebyzBWUoD
HDrJfHn+VZECTwKlpyR7US1cab1SACstaQomwa2AfAQ6JgBr25Lo8hCc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7OGYFswAy5tQrQjPfsSGh454dAl+xJHVtScHFD6W4atz/65DZ
mtjhn4POnzVBlPMEL7CY0UGl/ocn/uLolbxFJ9AIHpYg5NPA6HeMt8x9+fUbHmNS
lzXqNJOi4f9O35tRAmORABHHHXIocdLxpFNH5SmZ++rbbueLVl4llGUS++taniKn
URIPcYmCHnP8RLyvm73djct86h0qeBFbRrVHTgu6+mGdzqMizqsXRgK9tWcj5Sh5
GvzkzwPo7TVsMPWZYd/jB4UM1GJyCv/0Eqgs+P5DkvIa
-----END CERTIFICATE-----
# UEFI keys enrollment
To perform the following instructions, some packages are needed. They are installed by `dependencies.sh` of this directory. By default, the command listed below require to be logged as root. It will be pointed out otherwise.
## Create the keys
WARNING: A set of keys is already created here. So the following instruction is probably NOT what you want to do. This section is simply for documentation and you should proceed to the next section.
Run the script `mkkeys.sh` (no root access needed):
```bash
mkdir -p generate_keys && cd generate_keys && cp ../mkkeys.sh . && ./mkkeys.sh
```
## Sign a UEFI application
You have nothing special to do in this section. This is performed by dracut right after creating the (unsigned) image. Dracut is called in `installation/install.sh` with parameters according to `dracut.conf` and the command line. Tip: `dracut.conf` if generated by `installation/install.sh` from `dracut.conf.in`.
## Add keys to the firmware
Run `efi-readvar` (no root access needed).
If the field `PK`, `KEK` or `db` is not empty, then reboot. Enter the BIOS, disable Secure Boot (SB) and remove every keys.
If it is empty or after the previous stage, add the keys to UEFI as follow. We assume the keys have the name `mkkeys.sh` gave them:
* Add the Platform Key (the authority key for the machine):
`efi-updatevar -f PK.auth PK`
* Add the Key Exchange Key (the authority key for the db and dbx certificates and hashes):
`efi-updatevar -a -c KEK.crt -k PK.key KEK`
* Replace the current whitelist certificate:
`efi-updatevar -f -c DB.crt -k KEK.key db`
(replace -f with -a to append another whitelist certificate instead of replacing the old one)
### Troubleshooting
Some general informations:
* As a general matter, with Secure Boot (SB) disabled and no key, every key should be addable.
* A Platform Key is needed for Secure Boot (SB) to be enabled.
* To add or modify a key, you need the private key of the upper level (the Platform Key is its own upper level key).
##### Common errors
* Error: `Failed to update <var>: Operation not permitted`
It happens when trying to delete or replace a key. It may be resolved by making it mutable:
```bash
lsattr /sys/firmware/efi/efivars/{db,dbx,KEK,PK}*
```
"----i--------------" before the key means it is set as immutable. To make it mutable:
```bash
chattr -i /sys/firmware/efi/efivars/<key>
```
Example:
```bash
chattr -i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
```
Recommanded: make everything immutable after your operation. To do so, perform the same command with `+i` instead of `-i`. Same example:
```bash
chattr +i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
```
* Error: `Cannot write to db, wrong filesystem permissions`
It may be resolved by providing the upper level private key (after the `-k` option of `efi-updatevar`). Note that it can happen even in root mode, as the keys are stored on a separate filesystem.
# generate efi certificates
apt -y install sbsigntool efitool python3
89da4706-b3f7-11ec-92f8-00224ddacaa7
To perform the following instructions, some packages are needed.
They are installed by `dependencies.sh` of this directory.
## Create the keys
WARNING: This is probably NOT what you want to do.
Run the script `mkkeys.sh`:
```bash
mkdir -p generate_keys && cd generate_keys && cp ../mkkeys.sh . && ./mkkeys.sh
```
## Signing a UEFI application
You have nothing special to do. This is performed by dracut (called in `installation/install.sh`) according to `dracut.conf` (generated by `installation/install.sh` from `dracut.conf.in`).
## Add keys to the firmware:
Run `efi-readvar`
### if PK, KEK or db is not empty
1. Reboot and, in the BIOS, disable Secure Boot (SB) and remove every keys.
2. Then if we assume the keys have the name mkkeys.sh gives them:
* Add the Platform Key (the authority key for the machine).
```bash
efi-updatevar -f PK.auth PK
```
* Add the Key Exchange Key (the authority key for the db and dbx certificates and hashes)
```bash
efi-updatevar -a -c KEK.crt -k PK.key KEK
```
* Replace the current whitelist certificate
````bash
efi-updatevar -f -c DB.crt -k KEK.key db
````
(replace -f with -a to append another whitelist certificate instead of replacing the old one)
### Troubleshooting
Some general informations:
1. As a general matter, with Secure Boot (SB) disabled and no key, every key should be addable.
2. A Platform Key is needed for Secure Boot (SB) to be enabled.
3. To add or modify a key, you need the private key of the upper level (the Platform Key is its own upper level key).
#### Common errors
* Error: `Failed to update <var>: Operation not permitted`
It happens when trying to delete or replace a key. It may be resolved by making it mutable:
```bash
lsattr /sys/firmware/efi/efivars/{db,dbx,KEK,PK}*
```
"----i--------------" before the key means it is set as immutable. To make it mutable:
```bash
chattr -i /sys/firmware/efi/efivars/<key>
```
Example:
```bash
chattr -i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
```
Recommanded: make everything immutable after your operation. To do so, perform the same command with `+i` instead of `-i`. Same example:
```bash
chattr +i /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
```
* Error: `Cannot write to db, wrong filesystem permissions`
It may be resolved by providing the upper level private key (after the `-k` option of `efi-updatevar`). Note that it can happen even in root mode, as the keys are stored on a separate filesystem.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment