Skip to content

Commit 55b665b

Browse files
Secureboot: Image signing verification enhancements (#3989)
#### What I did The current signature verification of sonic images assumes the DB Keys are all Root CAs. The secureboot standard says nothing about this, the DBKeys are explicitly trusted by signing them with the KEK, and that signing method does not follow the standard X.509 PKI architecture. Therefore the DB Key is not guaranteed to be a CA Root (aka not self-signed). It is possible the DB Key was created as an intermediate, but since it is explicitly trusted that is ok. Fixes #23406 #### How I did it This adds this explicit trust of the DB Key as a secondary signing verification if the original verification fails. It disables looking inside the pkcs7 container for any keys at all and assumes the key specified is the exact key for the signature. #### How to verify it Build secureboot image signed with a DB Key that is not self-signed, then run through the sonic-installer install with that image and see the verification succeeds. Signed-off-by: Brad House <bhouse@nexthop.ai> Signed-off-by: Travis Brown <travisb@nexthop.ai>
1 parent e59bbfc commit 55b665b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

scripts/verify_image_sign_common.sh

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ verify_image_sign_common() {
1515
no_check_time="-noattr"
1616
fi
1717

18-
# making sure image verification is supported
1918
EFI_CERTS_DIR=/tmp/efi_certs
2019
RESULT="CMS Verification Failure"
21-
LOG=$(openssl cms -verify $no_check_time -noout -CAfile $EFI_CERTS_DIR/cert.pem -binary -in ${CMS_SIG_FILE} -content ${DATA_FILE} -inform pem 2>&1 > /dev/null )
22-
VALIDATION_RES=$?
23-
if [ $VALIDATION_RES -eq 0 ]; then
24-
RESULT="CMS Verified OK"
25-
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
26-
echo "verification ok:$RESULT"
27-
# No need to continue.
28-
# Exit without error if any success signature verification.
29-
return 0
30-
fi
31-
20+
21+
# Verify the signature in two ways:
22+
# 1. As a complete certificate chain root of trust which requires the DB Key to be a self-signed root, but the image
23+
# signed with an intermediate embedded into the certificate.
24+
# 2. Assuming the DB key directly signed the image without trusting the certificate embedded into the
25+
# pkcs7 signature (-nointern). Since the DB key is trusted, it doesn't need to be a root CA so we turn off root
26+
# CA verification with the -noverify flag.
27+
for variant in "-CAfile" "-nointern -noverify -certfile"; do
28+
LOG=$(openssl cms -verify $no_check_time -noout ${variant} $EFI_CERTS_DIR/cert.pem -binary -in ${CMS_SIG_FILE} -content ${DATA_FILE} -inform pem 2>&1 > /dev/null )
29+
VALIDATION_RES=$?
30+
if [ $VALIDATION_RES -eq 0 ]; then
31+
RESULT="CMS Verified OK"
32+
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
33+
echo "verification ok:$RESULT"
34+
# No need to continue.
35+
# Exit without error if any success signature verification.
36+
return 0
37+
fi
38+
done
39+
3240
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
3341
return 1
3442
}

0 commit comments

Comments
 (0)