Skip to content

Commit b883078

Browse files
committed
decode_payload: Process all signatures
Since there can be multiple signatures, we should look at all and not only the first two.
1 parent 7b59d69 commit b883078

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

decode_payload

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ if [ "${DEBUG}" = 1 ]; then
129129
echo "${SIGDESC}" >&2
130130
fi
131131

132-
VERSION=2 # Init for the single-signature case, in the many-signature case the first signature ("version 1" but better would be "number 1") is,
133-
# at least for Flatcar production, a dummy and parsing it overwrites this variable with 1 and it will be ignored,
134-
# the second signature is "version 2" and the one we want to check. Even if only one signature is there it becomes "version 2",
135-
# see https://github.com/flatcar/update_engine/blob/c6f566d47d8949632f7f43871eb8d5c625af3209/src/update_engine/payload_signer.cc#L33
132+
# The signal "version" is actually the numbering of multiple signatures, it starts at 2 if there is one signature but
133+
# otherwise it starts at 1. We accept the payload if we find a valid signature that we have a pub key for.
134+
# See https://github.com/flatcar/update_engine/blob/c6f566d47d8949632f7f43871eb8d5c625af3209/src/update_engine/payload_signer.cc#L33
135+
# Note that Flatcar production also has a dummy signature with a random key,
136+
# see https://github.com/flatcar/flatcar-build-scripts/blob/821d8da19567e3d1a29dc24f8c822f67df6a5e02/generate_payload#L384
137+
FOUND=false
136138
while IFS= read -r LINE; do
137139
LINE=$(echo "${LINE}" | sed 's/^ *//g')
138140
case "${LINE}" in
@@ -144,17 +146,19 @@ while IFS= read -r LINE; do
144146
# The raw output instead of asn1parse is used to easily extract the sha256 checksum (done by tail -c 32)
145147
# We also calculate the payload hash that the signature was done for, note that it's of course not the whole file but only up to the attached signature itself
146148
PAYLOADHASH=$(head -c "$((20 + MLEN + SIGOFFSET))" "${FILE}" | sha256sum | cut -d ' ' -f 1)
147-
if [ "${VERSION}" = 2 ] && [ "${SIGHEX}" != "${PAYLOADHASH}" ]; then
148-
echo "Signature error" >&2
149-
exit 1
150-
elif [ "${VERSION}" != 2 ]; then
151-
# For Flatcar production this is a dummy signature with a random key,
152-
# see https://github.com/flatcar/flatcar-build-scripts/blob/821d8da19567e3d1a29dc24f8c822f67df6a5e02/generate_payload#L384
153-
echo "Unprocessed 'version ${VERSION}' signature (Payload hash: ${PAYLOADHASH}, SIGDATA: ${SIGDATA})" >&2
149+
if [ "${SIGHEX}" = "${PAYLOADHASH}" ]; then
150+
FOUND=true
151+
echo "Valid signature found (Version: ${VERSION}, Payload Hash: ${PAYLOADHASH})" >&2
152+
else
153+
echo "Signature error (Version: ${VERSION}, Payload Hash: ${PAYLOADHASH}, SIGDATA: ${SIGDATA})" >&2
154154
fi
155155
;;
156156
*) ;;
157157
esac
158158
done <<< "${SIGDESC}"
159159

160+
if [ "${FOUND}" != true ]; then
161+
echo "No valid signature found" >&2
162+
exit 1
163+
fi
160164
echo "Success" >&2

0 commit comments

Comments
 (0)