diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 382e4a80..7888abb9 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -186,8 +186,10 @@ upgrade_deno() { ARCH=$(uname -m) if [ "$ARCH" = "aarch64" ]; then DENO_ARCH="aarch64-unknown-linux-gnu" + DENO_SHA256="d4589cc1ffcbf1995c92a0127d932aaf832ac70cfdcc6d5b7bf38043cf303575" elif [ "$ARCH" = "x86_64" ]; then DENO_ARCH="x86_64-unknown-linux-gnu" + DENO_SHA256="30455b845ffa6082209c3590269c910ad3b7efdf28c9879afd4006c47ae54197" else echo "Unsupported architecture for Deno: $ARCH" return 1 @@ -204,6 +206,8 @@ upgrade_deno() { echo "Installing Deno ${DENO_VERSION} for ${ARCH}..." curl -fsSL "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-${DENO_ARCH}.zip" -o /tmp/deno.zip + # `set -e` does not apply inside a function called with `||`, so a mismatch must return explicitly. + echo "${DENO_SHA256} /tmp/deno.zip" | sha256sum -c - || { rm -f /tmp/deno.zip; return 1; } unzip -o /tmp/deno.zip -d /usr/local/bin/ chmod +x /usr/local/bin/deno rm /tmp/deno.zip diff --git a/wrolpi/test/test_trust_store.py b/wrolpi/test/test_trust_store.py index 58623a13..51cbf5b8 100644 --- a/wrolpi/test/test_trust_store.py +++ b/wrolpi/test/test_trust_store.py @@ -28,3 +28,22 @@ def test_certifi_distrusts_root(label): def test_deno_uses_system_trust_store(path, setting): """Deno's bundled roots only change with a Deno upgrade; the system store is patched by apt.""" assert setting in (PROJECT_DIR / path).read_text().splitlines() + + +DENO_DOWNLOAD = 'github.com/denoland/deno/releases/download/' +DENO_INSTALLER_DIRECTORIES = ('scripts', 'docker', 'debian-live-config', 'pi-gen') + + +def test_deno_downloads_are_checksummed(): + """Each script that downloads Deno checks the zip's sha256 before installing it, so the installed runtime does + not depend on TLS alone (a compromised CA can forge a certificate for github.com).""" + installers = {} + for directory in DENO_INSTALLER_DIRECTORIES: + for path in (PROJECT_DIR / directory).rglob('*'): + if path.is_file() and DENO_DOWNLOAD in (text := path.read_text(errors='ignore')): + installers[str(path.relative_to(PROJECT_DIR))] = text + assert len(installers) >= 6, 'expected the install scripts, Dockerfiles, and image builds' + + unchecked = [path for path, text in installers.items() + if text.count(DENO_DOWNLOAD) > text.count('sha256sum -c')] + assert not unchecked, f'Deno is downloaded without a sha256 check in: {unchecked}'