From 5f8c23365006d689e49d99029ddb3d9713c2c90a Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 29 Oct 2021 09:28:42 +0100 Subject: [PATCH] secure-boot: Add more documentation about the RSA signatures and add optional public key argument --- Readme.md | 19 +++++++++++++++++++ secure-boot-example/README.md | 3 +++ secure-boot-example/example-public.pem | 9 +++++++++ secure-boot-msd/README.md | 14 ++++++++++---- tools/update-pieeprom.sh | 28 ++++++++++++++++++++++++---- 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 secure-boot-example/README.md create mode 100644 secure-boot-example/example-public.pem diff --git a/Readme.md b/Readme.md index e399766..7b2fc7f 100644 --- a/Readme.md +++ b/Readme.md @@ -140,9 +140,28 @@ rmdir boot-mount ``` #### Sign the boot image +For secure-boot, `rpi-eeprom-digest` extends the current `.sig` format of +sha256 + timestamp to include an hex format RSA bit PKCS#1 v1.5 signature. The key length +must be 2048 bits. + ```bash ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" ``` +#### Hardware security modules +`rpi-eeprom-digest` is a shell script that wraps a call to `openssl dgst -sign`. +If the private key is stored withing a hardware security module instead of +a .PEM file the `openssl` command will need to be replaced with the appropriate call to the HSM. + +`rpi-eeprom-digest` called by `update-pieeprom.sh` to sign the EEPROM config file. + +The RSA public key must be stored within the EEPROM so that it can be used by the bootloader. +By default, the RSA public key is automatically extracted from the private key PEM file. Alternatively, +the public key may be specified separately via the `-p` argument to `update-pieeprom.sh` and `rpi-eeprom-config`. + +To extract the public key in PEM format from a private key PEM file run. +```bash +openssl rsa -in private.pem -pubout -out public.pem` +``` #### Copy the secure boot image to the boot partition on the Raspberry Pi. Copy `boot.img` and `boot.sig` to the chosen boot filesystem. Secure boot images can be loaded from any of the normal boot devices (e.g. SD, USB, Network). diff --git a/secure-boot-example/README.md b/secure-boot-example/README.md new file mode 100644 index 0000000..b2709d7 --- /dev/null +++ b/secure-boot-example/README.md @@ -0,0 +1,3 @@ +This directory contains an example secure boot image signed with the example private key in this directory. + +Clearly, product releases should never be signed with `example-private.pem`. diff --git a/secure-boot-example/example-public.pem b/secure-boot-example/example-public.pem new file mode 100644 index 0000000..ea6d4dc --- /dev/null +++ b/secure-boot-example/example-public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+l3E+h/QNjrIR1cG6Npz +P0fBwp2UDpuQAafXDS5yryrfCPDYTO9DvzAfOk9Dz/putDfHV0RTOFXv1tmc4nqO +gU6nKx7tTdsjTiY4CgG3vXRMuAmDGX5ssJFCVmljGuILt1INlCmtun7Ow35VTxOc +RDDfrBDKnSitzOTf6KTR7xJhqFFhdMpIg8hW4bDBKMavyt38pRvDaO1o01qaQT/G +gAPmJm27y5RKNAe6iVTqsm4TMAhKC6P4XyRAbe6OMdFZyEWEk7Asexuc7uZlVHsU +I6pebSW/07O+5l/U7/3k6r//hO/HDFOBUUW55EjzzC1BhTlWHWfZNI+5+NdN8o32 +3QIDAQAB +-----END PUBLIC KEY----- diff --git a/secure-boot-msd/README.md b/secure-boot-msd/README.md index 3480db8..702f6ce 100644 --- a/secure-boot-msd/README.md +++ b/secure-boot-msd/README.md @@ -1,11 +1,17 @@ # USB MSD device mode drivers for signed-boot -If secure-boot has been enabled then this image must be signed with -the customer's RSA private key. Otherwise, the SPI EEPROM bootloader -will refused to load this image. +If secure-boot mode has been locked (via OTP) then both the +bootloader and rpiboot `bootcode4.bin` will only load `boot.img` +files signed with the customer's private key. Therefore, access +to rpiboot mass storage mode is disabled. -To do this run: +Mass storage mode can be re-enabled by signing a boot image +containing the firmware mass storage drivers. +N.B. The signed image should normally be kept secure because can +be used on any device signed with the same customer key. + +To sign the mass storage mode boot image run:- ```bash KEY_FILE=$HOME/private.pem ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" diff --git a/tools/update-pieeprom.sh b/tools/update-pieeprom.sh index bc4146d..3433a9f 100755 --- a/tools/update-pieeprom.sh +++ b/tools/update-pieeprom.sh @@ -16,6 +16,7 @@ SRC_IMAGE="pieeprom.original.bin" CONFIG="boot.conf" DST_IMAGE="pieeprom.bin" PEM_FILE="" +PUBLIC_PEM_FILE="" TMP_CONFIG_SIG="" die() { @@ -43,12 +44,19 @@ cat <