Skip to content

Commit 2187307

Browse files
bradh352bhouse-nexthop
authored andcommitted
share code rather than duplicate
Signed-off-by: Travis Brown <[email protected]>
1 parent f65b7b2 commit 2187307

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

scripts/verify_image_sign_common.sh

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

18-
# This command verifies the signing as a complete certificate chain root of trust and requires the DB Key to
19-
# be a self-signed root, but the image signed with an intermediate embedded into the certificate.
2018
EFI_CERTS_DIR=/tmp/efi_certs
2119
RESULT="CMS Verification Failure"
22-
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 )
23-
VALIDATION_RES=$?
24-
if [ $VALIDATION_RES -eq 0 ]; then
25-
RESULT="CMS Verified OK"
26-
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
27-
echo "verification ok:$RESULT"
28-
# No need to continue.
29-
# Exit without error if any success signature verification.
30-
return 0
31-
fi
3220

33-
# This is a backup signature verification method which does NOT trust the certificate embedded into the pkcs7
34-
# signature (via the -nointern flag) and assumes the DB key directly signed the image (via the -certfile flag).
35-
# Since the DB key is trusted, it doesn't need to be a root CA so we turn off root CA verification with the
36-
# -noverify flag.
37-
LOG=$(openssl cms -verify $no_check_time -noout -certfile $EFI_CERTS_DIR/cert.pem -binary -nointern -noverify -in ${CMS_SIG_FILE} -content ${DATA_FILE} -inform pem 2>&1 > /dev/null )
38-
VALIDATION_RES=$?
39-
if [ $VALIDATION_RES -eq 0 ]; then
40-
RESULT="CMS Verified OK"
41-
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
42-
echo "verification ok:$RESULT"
43-
# No need to continue.
44-
# Exit without error if any success signature verification.
45-
return 0
46-
fi
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
4739

4840
if [ -d "${TMP_DIR}" ]; then rm -rf ${TMP_DIR}; fi
4941
return 1

0 commit comments

Comments
 (0)