Skip to content

Commit e3d47bf

Browse files
authored
Merge pull request #26 from flatcar/kai/oem-sha256
flatcar-postinst: In addition to SHA1, also check SHA256 hash for OEMs
2 parents b3cdd63 + d7d9d52 commit e3d47bf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

flatcar-postinst

Lines changed: 14 additions & 4 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}"
@@ -118,7 +127,8 @@ if [ "${OEMID}" != "" ] && { [ -e "${INSTALL_MNT}/share/flatcar/oems/${OEMID}" ]
118127
fi
119128
done
120129
# Note that in the case of VERSION=NEXT_VERSION we will replace the running sysext and maybe it's better
121-
# to do so than not because it allows to recover from a corrupted file (where the corruption happened on disk)
130+
# to do so than not because it allows to recover from a corrupted file (where the corruption happened on disk).
131+
# However, as soon as update-engine would already download the payload, we should skip the overwriting.
122132
SUCCESS=false
123133
# Preferred is to download from the location given by the Omaha response
124134
# which only works with a new update-engine client that creates "full-response",

0 commit comments

Comments
 (0)