Skip to content

Commit 0232fdb

Browse files
authored
fix(install): verify release checksum before extracting in install-cli.sh (#880)
The Linux install script piped the downloaded archive straight into tar with no integrity check. Download the archive and the release's checksums.txt, verify the archive's SHA-256 against the published checksum (failing closed on mismatch), then extract. Guards against corrupted/partial downloads; not a substitute for signature verification against an out-of-band key. Fixes #647 Co-authored-by: gavin mcdonough <mcdgavin@users.noreply.github.com>
1 parent 634d3c9 commit 0232fdb

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

install-cli.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ abort() { printf "%s\n" "$@" >&2; exit 1; }
3434
[ -n "${BASH_VERSION:-}" ] || abort "This script requires bash"
3535
[ -d "$INSTALL_PATH" ] || abort "Could not install, $INSTALL_PATH doesn't exist"
3636
command -v curl >/dev/null || abort "cURL is required and is not found"
37+
command -v sha256sum >/dev/null || abort "sha256sum is required and is not found"
3738

3839
OS="$(uname)"
3940
case "$OS" in
@@ -59,15 +60,31 @@ VERSION=$(curl -fsSL https://api.github.com/repos/livekit/$REPO/releases/latest
5960

6061
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || abort "Invalid version: $VERSION"
6162

62-
ARCHIVE_URL="https://github.com/livekit/$REPO/releases/download/v${VERSION}/${BIN_NAME}_${VERSION}_linux_${ARCH}.tar.gz"
63+
ARCHIVE_NAME="${BIN_NAME}_${VERSION}_linux_${ARCH}.tar.gz"
64+
ARCHIVE_URL="https://github.com/livekit/$REPO/releases/download/v${VERSION}/${ARCHIVE_NAME}"
65+
CHECKSUMS_URL="https://github.com/livekit/$REPO/releases/download/v${VERSION}/checksums.txt"
6366

6467
log "Installing $REPO $VERSION"
6568
log "Downloading from $ARCHIVE_URL..."
6669

6770
TEMP_DIR=$(mktemp -d)
6871
trap 'rm -rf "$TEMP_DIR"' EXIT
6972

70-
curl -fsSL "$ARCHIVE_URL" | tar xzf - -C "$TEMP_DIR"
73+
curl -fsSL "$ARCHIVE_URL" -o "$TEMP_DIR/$ARCHIVE_NAME"
74+
curl -fsSL "$CHECKSUMS_URL" -o "$TEMP_DIR/checksums.txt"
75+
76+
# Verify the archive against the release's checksums.txt before extracting. The checksums
77+
# file is fetched from the same release over HTTPS, so this guards against corrupted/partial
78+
# downloads and accidental mismatches; it is not a substitute for signature verification
79+
# against an out-of-band key.
80+
log "Verifying checksum..."
81+
expected_sum=$(awk -v f="$ARCHIVE_NAME" '$2 == f {print $1}' "$TEMP_DIR/checksums.txt")
82+
[ -n "$expected_sum" ] || abort "Could not find a checksum for $ARCHIVE_NAME in checksums.txt"
83+
actual_sum=$(sha256sum "$TEMP_DIR/$ARCHIVE_NAME" | awk '{print $1}')
84+
[ "$expected_sum" = "$actual_sum" ] || \
85+
abort "Checksum verification failed for $ARCHIVE_NAME (expected $expected_sum, got $actual_sum)"
86+
87+
tar xzf "$TEMP_DIR/$ARCHIVE_NAME" -C "$TEMP_DIR"
7188

7289
$SUDO_PREFIX mv "$TEMP_DIR/$BIN_NAME" "$INSTALL_PATH/$BIN_NAME"
7390
$SUDO_PREFIX ln -sf "$INSTALL_PATH/$BIN_NAME" "$INSTALL_PATH/livekit-cli"

0 commit comments

Comments
 (0)