Skip to content

Commit e5a0c74

Browse files
committed
Add support for HSM-based signing
Add rudimentary support for using a PKCS11 engine to provide the private key for the signed boot component. This does not impact the device-unique key that is generated as part of provisioning. Where the PKCS11_NAME and FILE_PEM are both supplied, favour the PKCS11 name.
1 parent 71f03cf commit e5a0c74

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

README.adoc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,27 @@ Once you have followed all those steps, `rpi-sb-provisioner` should be correctly
9494
Configure `rpi-sb-provisioner` by using the following fields in `/etc/rpi-sb-provisioner/config`
9595

9696
=== CUSTOMER_KEY_FILE_PEM
97-
*Mandatory*
97+
*Optional, mandatory if CUSTOMER_KEY_PKCS11_NAME is not set*
9898

9999
The fully qualified path to your signing key, encoded in PEM format. This file is expected to contain an RSA 2048-bit Private Key.
100100

101101
WARNING: This file should be considered key material, and should be protected while at rest and in use according to your threat model.
102102

103+
=== CUSTOMER_KEY_PKCS11_NAME
104+
*Optional, mandatory if CUSTOMER_KEY_FILE_PEM is not set*
105+
106+
The keypair alias for a PKCS11 keypair, typically stored on a Hardware Security Module (HSM) and provided through a helper tool. This is expected to act in place of the RSA 2048-bit Private key specified with CUSTOMER_KEY_FILE_PEM, and will be used as the signing device for all future pre-boot authentication images.
107+
108+
The value should take the format:
109+
110+
----
111+
"pkcs11:object=<keypair-alias>;type=private"
112+
----
113+
114+
WARNING: You must use double quotes to enclose the value.
115+
116+
WARNING: The PKCS11 provider, and it's associated HSM, should be considered key material and should be protected while at rest and in use according to your threat model.
117+
103118
=== GOLD_MASTER_OS_FILE
104119
*Mandatory*
105120

device-triage/triage.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ if [ -z "${RPI_DEVICE_BOOTLOADER_CONFIG_FILE}" ]; then
2121
RPI_DEVICE_BOOTLOADER_CONFIG_FILE=/var/lib/rpi-sb-provisioner/bootloader.default
2222
fi
2323

24-
if [ -z "${CUSTOMER_KEY_FILE_PEM}" ]; then
25-
echo "You must provide a customer key file in the environment via CUSTOMER_KEY_FILE_PEM"
24+
if [ -z "${CUSTOMER_KEY_FILE_PEM}" ] || [ -z "${CUSTOMER_KEY_PKCS11_NAME}" ]; then
25+
echo "You must provide a key in the environment via CUSTOMER_KEY_FILE_PEM, or a key name via CUSTOMER_KEY_PKCS11_NAME"
2626
exit 1
2727
fi
2828

host-support/terminal-functions.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,21 @@ get_fastboot_config_file() {
130130
else
131131
echo "/var/lib/rpi-sb-provisioner/boot_ramdisk_config.txt"
132132
fi
133+
}
134+
135+
get_signing_directives() {
136+
if [ -n "${CUSTOMER_KEY_PKCS11_NAME}" ]; then
137+
echo "${CUSTOMER_KEY_PKCS11_NAME} -engine pkcs11 -keyform engine"
138+
else
139+
if [ -n "${CUSTOMER_KEY_FILE_PEM}" ]; then
140+
if [ -f "${CUSTOMER_KEY_FILE_PEM}" ]; then
141+
echo "RSA private key \"${CUSTOMER_KEY_FILE_PEM}\" not a file. Aborting." >&2
142+
exit 1
143+
fi
144+
echo "${CUSTOMER_KEY_FILE_PEM} -keyform PEM"
145+
else
146+
echo "Neither PKCS11 key name, or PEM key file specified. Aborting." >&2
147+
exit 1
148+
fi
149+
fi
133150
}

key-writer/keywriter.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ writeSig() {
3131
# Include the update-timestamp
3232
echo "ts: $(date -u +%s)" >> "${OUTPUT}"
3333

34-
if [ -n "${CUSTOMER_KEY_FILE_PEM}" ]; then
35-
[ -f "${CUSTOMER_KEY_FILE_PEM}" ] || die "RSA private key \"${CUSTOMER_KEY_FILE_PEM}\" not found"
36-
"${OPENSSL}" dgst -sign "${CUSTOMER_KEY_FILE_PEM}" -keyform PEM -sha256 -out "${SIG_TMP}" "${IMAGE}"
34+
if [ -n "$(get_signing_directives)" ]; then
35+
"${OPENSSL}" dgst -sign "$(get_signing_directives)" -sha256 -out "${SIG_TMP}" "${IMAGE}"
3736
echo "rsa2048: $(xxd -c 4096 -p < "${SIG_TMP}")" >> "${OUTPUT}"
3837
fi
3938
rm "${SIG_TMP}"

0 commit comments

Comments
 (0)