zupt/tests/test_help_consistency.sh
Cristian Cezar Moisés 43d6306a06 GUI rework for source-only builds + CLI security fixes + packaging + cross-platform scaffolding
Fixes the "GUI functions don't work on GNU Guix" report and a batch of
adversarial-audit findings across the CLI, decoder, crypto and packaging.

GUI (gui/src/zupt_gui.py)
- Root cause of the broken GUI: every encryption path defaulted to the
  libzuptsdk "SDK v2" modes, which are absent from the source-only build and
  exit 1. Reworked Keys/Compress/Extract around the native modes with a
  build-aware PQ-mode selector: Hybrid (--pq, default), Full PQ (--pq-only),
  and SDK v2 only when the binary reports WITH_SDK support. Capability is
  detected from `version` ("Build:"/"KDF:" lines) with a `help` fallback.
- Extract/Verify gain a PQ private-key input with auto-detect (reads the
  archive via `info` to pick --pq vs --pq-only). Verify could not verify any
  PQ archive before (password field only).
- run_async now holds a LIST of in-flight (thread, worker) refs; DiskTab's two
  buttons previously shared one slot, so a second op GC'd the first QThread
  mid-run. About tab corrected (codec 2.60.4, PBKDF2 default, --pq-only, URL).

CLI (src/zupt_main.c)
- compress -p <archive> <files> swallowed the archive name as the password and
  truncated the first input file (silent data loss, exit 0). Added a
  data-loss guard: refuse to overwrite an existing non-.zupt file as the output
  archive unless -y/--force; plus a self-overwrite guard.
- compress <archive> <src> -p <pw> wrote an UNENCRYPTED archive (exit 0)
  because options after the first positional were treated as files. Now errors
  on a misplaced option (with a `--` escape for real dashed filenames).
- Removed duplicated dead --pq-box/--pq-sdk branches. version/banner/usage now
  state the build's real KDF (PBKDF2 on source-only) and repo URL; examples
  lead with native --pq / --pq-only.

Security (audit findings)
- vv_decoder.c: the two AVX2 fast-path token decoders read a 2-/3-byte match
  offset after only checking 1 byte remained -> heap over-read on a crafted
  archive. Added the `ip + off_bytes > ip_end` guard the tail path already had.
- zupt_crypto.c: wipe ML-KEM/X25519 secret-key buffers when hybrid decrypt
  init fails on key read (matches the pq-only path).
- zupt_format.c: bound attacker-controlled encryption_header_off before the
  (off_t)+7 arithmetic in the info enc_type reader (avoid signed-overflow UB).

Packaging (would fail source-only)
- debian/rules (staged into debian/zupt, installed vendored .so), aur/PKGBUILD,
  nix/flake.nix, homebrew (vendored .so + nonexistent AUDIT.md, stale /zupt
  URLs) now build source-only. opensuse spec %files ships the shell completions
  make install writes (rpmbuild no longer fails on unpackaged files);
  _service + debian/control point at the vaptvupt repo; KDF claim corrected.

Cross-platform GUI packaging (new)
- packaging/portable/: OS-agnostic GUI package (zupt_gui.py + .bat/.command/.sh
  launchers + README) that runs on Windows/macOS/Linux/BSD with Python+PySide6.
- .github/workflows/cross-platform.yml: builds real native binaries on
  windows-latest + macos-latest runners (CLI, PyInstaller GUI, Inno Setup
  installer, .dmg) and the portable zip, attaching them to the release on tag.
- packaging/windows/vaptvupt-gui.iss: Inno Setup installer script.

Validation: make check 16/16 (all distro-safe checks), GUI imports + command
contracts verified against the fixed CLI. test_help_consistency updated to
assert the truthful (build-aware) default KDF.
2026-07-10 12:45:46 -03:00

145 lines
5.6 KiB
Shell
Executable file

#!/bin/bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) 2025-2026 Cristian Cezar Moisés
#
# Regression test for the `vaptvupt help` output.
#
# History:
# F-13 (v3.0.2): the usage() string literal exceeded C99's 4095-char
# limit (4121 chars), triggering -Woverlength-strings. Also, the
# help text had drifted out of date during the v3.0.0 rename:
# - Examples still said `zupt compress`, `zupt extract`, etc.
# - "Compression: LZ77 (1MB window) + Huffman entropy coding" —
# false; the default codec is now VaptVupt LZ + ANS 2.48.5
# - "License: AGPL-3.0-or-later (Zupt)" — should be (VaptVupt)
#
# This test asserts the help output stays consistent with reality.
# Run from repo root after a build.
set -u
PASS=0; FAIL=0
P() { echo "$1"; PASS=$((PASS+1)); }
F() { echo "$1"; FAIL=$((FAIL+1)); }
BIN=./vaptvupt
[ -x ./vaptvupt ] || BIN=./zupt
[ -x "$BIN" ] || { echo "ERROR: no built binary found"; exit 2; }
HELP=$("$BIN" help 2>&1)
echo "Help consistency"
# ─── F-13 guard: usage() string-literal size ───
# Each fprintf-passed string literal (after adjacent concatenation)
# must be under C99's 4095-char limit. We use a python helper to
# walk fprintf(...) calls and measure the concatenated literal.
python3 > /tmp/usage_size_check.txt <<'PYEOF'
import re
src = open('src/zupt_main.c').read()
pattern = re.compile(r'fprintf\(\s*\w+\s*,\s*((?:"(?:[^"\\]|\\.)*"\s*)+)', re.S)
worst = 0
worst_lineno = 0
for m in pattern.finditer(src):
block = m.group(1)
literals = re.findall(r'"((?:[^"\\]|\\.)*)"', block)
concat = ''.join(literals)
actual = len(re.sub(r'\\.', 'X', concat))
if actual > worst:
worst = actual
worst_lineno = src[:m.start()].count('\n') + 1
if worst >= 4095:
print(f"FAIL:{worst}:{worst_lineno}")
else:
print(f"PASS:{worst}:{worst_lineno}")
PYEOF
RES=$(tail -1 /tmp/usage_size_check.txt)
if [[ "$RES" == PASS:* ]]; then
L=${RES#PASS:}; L=${L%:*}
P "usage() string literals are under C99 4095-char limit (worst: $L chars)"
else
L=${RES#FAIL:}; LINE=${L##*:}; L=${L%:*}
F "usage() has a string literal of $L chars at line $LINE — over C99 4095 limit (F-13 regression)"
fi
# ─── Brand consistency ───
# The help output must use the new binary name in examples, not the old one.
if echo "$HELP" | grep -qE '^\s+vaptvupt (compress|extract|list|test|bench|keygen|info|disk)'; then
P "examples use 'vaptvupt' command name"
else
F "examples don't use 'vaptvupt' — still saying 'zupt'?"
fi
# Conversely, the example lines shouldn't start with `zupt ` (the
# bare legacy name in example commands is the drift we just fixed).
LEGACY_EX=$(echo "$HELP" | grep -cE '^\s{1,4}zupt (compress|extract|list|test|bench|keygen) ')
if [ "$LEGACY_EX" -eq 0 ]; then
P "no examples use the bare legacy 'zupt' command name"
else
F "$LEGACY_EX example lines still use the legacy 'zupt' command name"
fi
# ─── Codec consistency ───
# Help text must mention the actual default codec, not the v2.x one.
if echo "$HELP" | grep -q "VaptVupt LZ + ANS"; then
P "help mentions VaptVupt LZ + ANS as the default codec"
else
F "help doesn't mention VaptVupt LZ + ANS — still claiming LZ77+Huffman?"
fi
# Conversely, the BARE phrase "LZ77 (1MB window) + Huffman" was the v2.x
# default-codec description; if it's still there, the help text is stale.
if echo "$HELP" | grep -q "LZ77 (1MB window) + Huffman entropy coding"; then
F "help still has the stale v2.x 'LZ77 (1MB window) + Huffman' description"
else
P "help doesn't have the stale v2.x default-codec description"
fi
# ─── License consistency ───
if echo "$HELP" | grep -q "AGPL-3.0-or-later (VaptVupt)"; then
P "help shows the correct license attribution (VaptVupt)"
else
F "help has wrong license attribution — should say AGPL-3.0-or-later (VaptVupt)"
fi
# Commercial-licensing contact visible.
if echo "$HELP" | grep -q "sac@securityops.co"; then
P "help shows the commercial-licensing contact (sac@securityops.co)"
else
F "help is missing the commercial-licensing contact"
fi
# ─── KDF consistency ───
# The help must state the ACTUAL default KDF for this build: PBKDF2-SHA256 on
# the source-only build (WITH_SDK=0), Argon2id only when built with WITH_SDK=1.
# A build that advertises Argon2id-by-default but derives PBKDF2 keys overstates
# its GPU/ASIC resistance (regression from v4.2.1).
if echo "$HELP" | grep -qiE "argon2id.*WITH_SDK=1"; then
P "help correctly scopes Argon2id to WITH_SDK=1 (source-only build)"
elif echo "$HELP" | grep -qE "PBKDF2.*[Dd]efault|[Dd]efault.*PBKDF2"; then
P "help correctly identifies PBKDF2-SHA256 as the default KDF"
elif echo "$HELP" | grep -qE "Argon2id.*[Dd]efault"; then
# A WITH_SDK=1 build legitimately defaults to Argon2id.
P "help identifies Argon2id as the default KDF (WITH_SDK=1 build)"
else
F "help does not state the default password KDF"
fi
# ─── Format consistency ───
if echo "$HELP" | grep -qE "Format:\s+v1\.6"; then
P "help reports the correct format version (v1.6)"
else
F "help doesn't report the correct format version"
fi
# ─── Functional check: help command works ───
if "$BIN" help >/dev/null 2>&1; then
P "vaptvupt help exits successfully"
else
F "vaptvupt help exits with non-zero status"
fi
echo ""
echo " ───────────────────────────────────────"
echo " Help consistency: $PASS passed, $FAIL failed"
echo " ───────────────────────────────────────"
[ "$FAIL" = 0 ] || exit 1