Skip to content

Commit 4b985ad

Browse files
committed
ci: verify Hysteria2 binary SHA256 against official hashes.txt
1 parent 9702a56 commit 4b985ad

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

buildScript/lib/hysteria2.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,31 @@ BASE="https://github.com/apernet/hysteria/releases/download/app/${HYSTERIA_VERSI
1616

1717
OUT="$(pwd)/app/executableSo"
1818

19+
# Fetch the official checksums once for integrity verification.
20+
HASHES="$(curl -fsSL "$BASE/hashes.txt")"
21+
22+
sha256_tool() {
23+
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
24+
else shasum -a 256 "$1" | awk '{print $1}'; fi
25+
}
26+
1927
dl() {
2028
local abi="$1" asset="$2"
2129
echo ">> downloading libhysteria2.so for $abi ($asset)"
2230
mkdir -p "$OUT/$abi"
2331
curl -fL "$BASE/$asset" -o "$OUT/$abi/libhysteria2.so"
32+
# Verify against the official SHA256 (hashes.txt lines: "<sha> build/<asset>").
33+
local expected actual
34+
expected="$(printf '%s\n' "$HASHES" | awk -v a="build/$asset" '$2==a {print $1}')"
35+
if [ -z "$expected" ]; then
36+
echo "Error: no checksum for $asset in hashes.txt" >&2
37+
exit 1
38+
fi
39+
actual="$(sha256_tool "$OUT/$abi/libhysteria2.so")"
40+
if [ "$expected" != "$actual" ]; then
41+
echo "Error: checksum mismatch for $asset (expected $expected, got $actual)" >&2
42+
exit 1
43+
fi
2444
chmod +x "$OUT/$abi/libhysteria2.so"
2545
}
2646

0 commit comments

Comments
 (0)