LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Installer: install a root-owned copy of the verified package, never skip the signature, refuse downgrades; deploy and signing check the key and file names
Federico Pereira683dcb94f931
diff --git a/tools/install/install.sh b/tools/install/install.shindex 31e29aa..1761a35 100755--- a/tools/install/install.sh+++ b/tools/install/install.sh@@ -245,6 +245,13 @@ pick_user() {# ---------------------------------------------------------------- download and verification+cleanup_tmp() {+ rm -rf "$TMP"+ if [ -n "$ROOT_TMP" ]; then+ if [ "$(id -u)" -eq 0 ]; then rm -rf "$ROOT_TMP"; else sudo -n rm -rf "$ROOT_TMP" 2>/dev/null || true; fi+ fi+}+resolve_tag() {if [ -n "$WANT_VERSION" ]; thenTAG="v${WANT_VERSION#v}"@@ -278,11 +285,11 @@ verify_signature() {pem=$(cat "$LORDOS_PUBKEY_FILE")warn "using the release key from LORDOS_PUBKEY_FILE (testing)"fi- if [ -z "$pem" ]; then- SIG_NOTE="not checked: LordOS has no release-signing key yet, so only the SHA-256 checksum is verified (it protects against corrupted downloads, not against a compromised release page)"- warn "signature $SIG_NOTE."- return- fi+ # never skip the check: an empty or non-PEM key (e.g. a test override) is an error+ case "$pem" in+ "-----BEGIN PUBLIC KEY-----"*"-----END PUBLIC KEY-----"*) ;;+ *) die "the release-signing key is missing or not a PEM public key: refusing to install" ;;+ esac[ -s "$2" ] || die "the release has no SHA256SUMS.sig signature: refusing to install"if ! command -v openssl >/dev/null 2>&1; thensay " Installing openssl to check the signature..."@@ -310,6 +317,7 @@ check_deb_file() {get_package() {SIG_NOTE=""+ EXPECT_SHA=""# apt reads the file as the _apt user: a world-readable copy in our private-but-traversable dirchmod 755 "$TMP"if [ -n "$LOCAL_DEB" ]; then@@ -322,6 +330,7 @@ get_package() {want=$(sum_for "$sums" "$base")[ -n "$want" ] || die "$sums has no entry for $base"[ "$(sha256_of "$DEB_PATH")" = "$want" ] || die "SHA-256 mismatch for $base: the file is corrupted or not the released one"+ EXPECT_SHA=$wantok "SHA-256 matches $sums"verify_signature "$sums" "$sums.sig"else@@ -344,11 +353,25 @@ get_package() {say " Downloading $base..."fetch "$base_url/$base" "$TMP/$base" || die "could not download $base"DEB_PATH="$TMP/$base"- [ "$(sha256_of "$DEB_PATH")" = "$(sum_for "$TMP/SHA256SUMS" "$base")" ] \+ EXPECT_SHA=$(sum_for "$TMP/SHA256SUMS" "$base")+ [ "$(sha256_of "$DEB_PATH")" = "$EXPECT_SHA" ] \|| die "SHA-256 mismatch for $base: the download is corrupted. Nothing was installed."ok "SHA-256 of $base matches SHA256SUMS"fichmod 644 "$DEB_PATH"+ # Everything above ran on a file this user owns: any other process of the user could swap+ # it between the checks and apt (root would then run its maintainer scripts). Give root its+ # own copy in a root-owned folder and check that copy again; apt installs only that one.+ if [ "$(id -u)" -ne 0 ]; then+ ROOT_TMP=$(as_root mktemp -d) || die "could not create a temporary folder as root"+ as_root chmod 755 "$ROOT_TMP" || die "could not prepare $ROOT_TMP"+ as_root install -m 644 "$DEB_PATH" "$ROOT_TMP/$base" || die "could not copy $base for installation"+ DEB_PATH="$ROOT_TMP/$base"+ fi+ if [ -n "$EXPECT_SHA" ]; then+ [ "$(sha256_of "$DEB_PATH")" = "$EXPECT_SHA" ] \+ || die "SHA-256 mismatch for $base after copying it: refusing to install"+ ficheck_deb_file "$DEB_PATH"ok "package: lordos $DEB_VERSION ($ARCH)"}@@ -371,6 +394,11 @@ install_package() {donefiwas=$(dpkg-query -W -f '${Version}' lordos 2>/dev/null || true)+ # an old (validly signed) release served as "latest" must not downgrade a newer install+ if [ -n "$was" ] && [ -z "$WANT_VERSION" ] && [ -z "$LOCAL_DEB" ] \+ && dpkg --compare-versions "$DEB_VERSION" lt "$was"; then+ die "the release offered ($DEB_VERSION) is older than the installed LordOS ($was): refusing to downgrade (use --version X to choose a version)"+ fi# shellcheck disable=SC2086 # $extras is a list of package namesapt_install "$DEB_PATH" $extras || die "apt-get could not install LordOS (see the messages above). Nothing else was changed."if [ -n "$was" ]; then changed "package lordos $was replaced by $DEB_VERSION"@@ -645,7 +673,8 @@ do_install() {ask "Continue?" 0 || die "cancelled; nothing was changed"TMP=$(mktemp -d)- trap 'rm -rf "$TMP"' EXIT INT TERM+ ROOT_TMP=""+ trap cleanup_tmp EXIT INT TERMstep "Getting the package"get_packageinstall_packagediff --git a/tools/release/sign-release.sh b/tools/release/sign-release.shindex 47f2e12..0fcac86 100755--- a/tools/release/sign-release.sh+++ b/tools/release/sign-release.sh@@ -18,6 +18,10 @@ cd "$dir"rm -f SHA256SUMS SHA256SUMS.sigfiles=$(find . -maxdepth 1 -type f ! -name 'SHA256SUMS*' ! -name '.*' | sed 's|^\./||' | LC_ALL=C sort)[ -n "$files" ] || { echo "no files in $dir" >&2; exit 1; }+# the list is word-split below: only plain release file names (no spaces, globs or leading '-')+for f in $files; do+ case "$f" in -*|*[!A-Za-z0-9._+~-]*) echo "unexpected file name in $dir: $f" >&2; exit 1 ;; esac+doneif command -v sha256sum >/dev/null; then sum() { sha256sum "$@"; }; else sum() { shasum -a 256 "$@"; }; fi# shellcheck disable=SC2086sum $files > SHA256SUMSdiff --git a/tools/web/deploy.sh b/tools/web/deploy.shindex a0fd053..652ba61 100755--- a/tools/web/deploy.sh+++ b/tools/web/deploy.sh@@ -19,6 +19,8 @@ DISTRIBUTION=E35DXDFJ83X7Z8[ -f "$DIST/index.html" ] || { echo "no build in $DIST: run node web/build.mjs" >&2; exit 1; }[ -f "$DIST/install.sh" ] || { echo "missing $DIST/install.sh" >&2; exit 1; }cmp -s "$ROOT/tools/install/install.sh" "$DIST/install.sh" || { echo "dist/install.sh differs from tools/install/install.sh" >&2; exit 1; }+[ -f "$DIST/lordos-release.pub.pem" ] || { echo "missing $DIST/lordos-release.pub.pem" >&2; exit 1; }+cmp -s "$ROOT/tools/release/lordos-release.pub.pem" "$DIST/lordos-release.pub.pem" || { echo "dist/lordos-release.pub.pem differs from tools/release/lordos-release.pub.pem" >&2; exit 1; }if find "$DIST" -name '*.map' | grep -q .; then echo "source maps in $DIST" >&2; exit 1; fiaws() { command aws --profile "$PROFILE" "$@"; }