zupt/tests/test_f10_kdf_default.sh
Cristian Cezar Moisés 544a2cd647
Some checks failed
CI / build-and-test (clang) (push) Has been cancelled
CI / build-and-test (gcc) (push) Has been cancelled
CI / strict-warnings (clang, -Wall -Wextra -Wpedantic -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -O2 -std=c11 -Werror) (push) Has been cancelled
CI / strict-warnings (gcc, -Wall -Wextra -Wpedantic -Wshadow -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -Wformat-security -Wlogical-op -Wjump-misses-init -Wdouble-promotion -O2 -std=c11 -Werror) (push) Has been cancelled
CI / sanitizers (push) Has been cancelled
CI / pie-hardening (push) Has been cancelled
CI / cross-aarch64 (push) Has been cancelled
CI / dist-reproducibility (push) Has been cancelled
CI / packaging-syntax (push) Has been cancelled
CI / release (push) Has been cancelled
v4.0.0: codec 2.60.4 security release, --pq-box sealed-box mode, F-16 fix
Major release. Highlights:

- Codec: vendored VaptVupt codec moves to canonical 2.60.4 security
  release. Fixes a high-severity OOB heap write in the AVX2 decode fast
  path (reachable on a valid stream sized to exactly content_size, both
  tail variants). Brings CBMC-formally-verified BCJ filters with
  automatic ELF/PE/Mach-O detection. Compressed output stays
  byte-identical (ratio gate Δ 0.00%); wire format unchanged at v1.6.
- New --pq-box sealed-box recipient mode (vendored libpqvaptvupt 0.6.0):
  ML-KEM-768 + X25519 combined via HKDF-SHA256 with domain separation,
  AES-256-CTR + HMAC-SHA256 EtM. Legacy --pq and --pq-sdk stay readable.
- F-16: discloses and fixes a pre-existing data-loss defect in the
  <= 3.8.0 in-tree BCJ encoder. Full back-compat matrix decodes
  byte-exact under 4.0.0; every readable pre-4.0 archive remains readable.

Repository hygiene:
- Sync full 4.0.0 source tree (codec, crypto, SDK, GUI, packaging, tests).
- Remove internal scratch files (PROMPT.md, FORMAL_AUDIT_PROMPT.md)
  and superseded version-specific docs (INTEGRATION_PROTOCOL_2.60.4.md,
  docs/FINDINGS-2.x.md) and a stray test binary.
- Refresh README download/install section to real 4.0.0 release assets;
  bump version badge to 4.0.0.
- Add .gitignore for build outputs (keeps vendored prebuilt libraries).
2026-06-10 18:48:58 -03:00

140 lines
4.2 KiB
Shell
Executable file

#!/bin/bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) 2025-2026 Cristian Cezar Moisés
#
# F-10 regression test (Zupt 2.4.1).
#
# F-10: default password-mode KDF flipped from PBKDF2-SHA256 to Argon2id.
# PBKDF2 remains available via --kdf pbkdf2 for compatibility with
# v2.4.0-and-older readers.
#
# Three assertions:
# 1. `zupt c -p PW out.zupt input` writes an enc-header with type byte
# 0x04 (ZUPT_ENC_PW_ARGON2), and the stderr message says Argon2id.
# 2. `zupt c -p PW --kdf pbkdf2 out.zupt input` writes type byte 0x01
# (ZUPT_ENC_PBKDF2), and the stderr message says PBKDF2.
# 3. Both archive types roundtrip byte-exact via `zupt x -p PW`.
# 4. Wrong password is rejected for both archive types.
set -u
ZUPT="${ZUPT_BIN:-./zupt}"
case "$ZUPT" in
/*) ;;
*) ZUPT="$PWD/$ZUPT" ;;
esac
if [ ! -x "$ZUPT" ]; then
echo "$ZUPT not found — run 'make' first" >&2
exit 1
fi
PASS=0
FAIL=0
P() { PASS=$((PASS+1)); echo "$1"; }
F() { FAIL=$((FAIL+1)); echo "$1"; }
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
cd "$TMPDIR"
echo "F-10 regression: password-mode KDF default"
# Helper: read the enc_type byte (payload[0] of the enc-header block).
enc_type_of() {
python3 -c "
import sys
b = open('$1','rb').read()
off = int.from_bytes(b[36:44],'little')
def vread(buf,o):
v=0;s=0
while True:
x=buf[o]; o+=1; v|=(x&0x7f)<<s
if not (x&0x80): break
s+=7
return v,o
v1,p = vread(b, off+7); v2,p2 = vread(b, p)
print(f'{b[p2+8]:02x}')
"
}
echo "secret payload for KDF test" > input.txt
# 1. Default → Argon2id (0x04)
STDERR_DEFAULT=$("$ZUPT" c -p secret default.zupt input.txt 2>&1)
ETYPE=$(enc_type_of default.zupt)
if [ "$ETYPE" = "04" ]; then
P "default: enc_type = 0x04 (ZUPT_ENC_PW_ARGON2)"
else
F "default: enc_type = 0x$ETYPE (expected 0x04)"
fi
if echo "$STDERR_DEFAULT" | grep -qi "Argon2id"; then
P "default: stderr message names Argon2id"
else
F "default: stderr message doesn't name Argon2id"
fi
# 2. --kdf pbkdf2 → PBKDF2 (0x01)
STDERR_PB=$("$ZUPT" c -p secret --kdf pbkdf2 legacy.zupt input.txt 2>&1)
ETYPE2=$(enc_type_of legacy.zupt)
if [ "$ETYPE2" = "01" ]; then
P "--kdf pbkdf2: enc_type = 0x01 (ZUPT_ENC_PBKDF2)"
else
F "--kdf pbkdf2: enc_type = 0x$ETYPE2 (expected 0x01)"
fi
if echo "$STDERR_PB" | grep -qi "PBKDF2"; then
P "--kdf pbkdf2: stderr message names PBKDF2"
else
F "--kdf pbkdf2: stderr message doesn't name PBKDF2"
fi
# 3. Roundtrips
mkdir out_a && (cd out_a && "$ZUPT" x -p secret ../default.zupt >/dev/null 2>&1)
if [ -f out_a/input.txt ] && diff -q input.txt out_a/input.txt >/dev/null 2>&1; then
P "Argon2id archive roundtrips byte-exact"
else
F "Argon2id roundtrip"
fi
mkdir out_p && (cd out_p && "$ZUPT" x -p secret ../legacy.zupt >/dev/null 2>&1)
if [ -f out_p/input.txt ] && diff -q input.txt out_p/input.txt >/dev/null 2>&1; then
P "PBKDF2 archive roundtrips byte-exact"
else
F "PBKDF2 roundtrip"
fi
# 4. Wrong password rejected (both)
mkdir out_wa && (cd out_wa && "$ZUPT" x -p wrong ../default.zupt >/dev/null 2>&1)
if [ ! -f out_wa/input.txt ]; then
P "Argon2id: wrong password rejected"
else
F "Argon2id: wrong password accepted"
fi
mkdir out_wp && (cd out_wp && "$ZUPT" x -p wrong ../legacy.zupt >/dev/null 2>&1)
if [ ! -f out_wp/input.txt ]; then
P "PBKDF2: wrong password rejected"
else
F "PBKDF2: wrong password accepted"
fi
# 5. --kdf argon2id (explicit form) → same as default
STDERR_E=$("$ZUPT" c -p secret --kdf argon2id explicit.zupt input.txt 2>&1)
ETYPE3=$(enc_type_of explicit.zupt)
if [ "$ETYPE3" = "04" ]; then
P "--kdf argon2id (explicit): enc_type = 0x04"
else
F "--kdf argon2id (explicit): enc_type = 0x$ETYPE3"
fi
# 6. --kdf garbage → reject
if "$ZUPT" c -p secret --kdf garbage garbage.zupt input.txt >/dev/null 2>&1; then
F "--kdf garbage was accepted (should reject)"
else
P "--kdf garbage rejected"
fi
echo ""
echo " ───────────────────────────────────────"
echo " F-10 regression: $PASS passed, $FAIL failed"
echo " ───────────────────────────────────────"
[ "$FAIL" = 0 ] || exit 1