Skip to content

Commit 381da58

Browse files
committed
flatcar-postinst: In addition to SHA1, also check SHA256 hash for OEMs
The newer Omaha 3.1 hash_sha256 attribute is now supported by Nebraska and should be used for OEM payloads. Up to now we only checked the regular "hash" attribute for download integrity. It's not really security critical because the payload has its own signature but it's good to migrate all hashsum usage away from SHA1. Find the hash and hash_sha256 attributes and require at least one to be set for the OEM packages. Check the found hash attributes.
1 parent b3cdd63 commit 381da58

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

flatcar-postinst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,28 @@ sysext_download() {
7171
entries=$(grep -m 1 -o "<package name=\"${name}\"[^>]*" "${from}")
7272
url="${base}/${name}"
7373
size=$(echo "${entries}" | grep -o 'size="[0-9]*' | cut -d '"' -f 2)
74-
hash=$(echo "${entries}" | grep -o -P 'hash="[^"]*' | cut -d '"' -f 2) # openssl dgst -binary -sha1 < "$PAYLOAD" | base64
74+
hash=$(echo "${entries}" | { grep -o -P 'hash="[^"]*' || true ; } | cut -d '"' -f 2) # openssl dgst -binary -sha1 < "$PAYLOAD" | base64
75+
hash_sha256=$(echo "${entries}" | { grep -o -P 'hash_sha256="[^"]*' || true ; } | cut -d '"' -f 2) # sha256sum -b "$PAYLOAD" | cut -d " " -f 1
7576
fi
7677
rm -f "${target}.tmp"
7778
curl -fsSL --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 -o "${target}.tmp" "${url}"
78-
if [ "${size}" != "" ] && [ "${hash}" != "" ]; then
79+
if [ "${base}" != "" ]; then
7980
if [ "$(stat --printf='%s' "${target}.tmp")" != "${size}" ]; then
8081
echo "Size mismatch for ${name}" >&2
8182
return 1 # jump to ret=
8283
fi
83-
if [ "$(openssl dgst -binary -sha1 < "${target}.tmp" | base64)" != "${hash}" ]; then
84+
if [ "${hash}" = "" ] && [ "${hash_sha256}" = "" ]; then
85+
echo "At least one hash is expected, found none in Omaha package for ${name}" >&2
86+
return 1 # jump to ret=
87+
fi
88+
if [ "${hash}" != "" ] && [ "$(openssl dgst -binary -sha1 < "${target}.tmp" | base64)" != "${hash}" ]; then
8489
echo "Hash mismatch for ${name}" >&2
8590
return 1 # jump to ret=
8691
fi
92+
if [ "${hash_sha256}" != "" ] && [ "$(sha256sum -b "${target}.tmp" | cut -d " " -f 1)" != "${hash_sha256}" ]; then
93+
echo "Hash SHA256 mismatch for ${name}" >&2
94+
return 1 # jump to ret=
95+
fi
8796
fi
8897
# Using "${INSTALL_MNT}" here is ok because it was verified first by update-engine
8998
PROTOPATH="${INSTALL_MNT}"/share/update_engine/ "${INSTALL_MNT}"/share/update_engine/decode_payload /usr/share/update_engine/update-payload-key.pub.pem "${target}.tmp" "${target}"

0 commit comments

Comments
 (0)