CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tools / extract / audit-selftest.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # audit-selftest.sh: negative control for audit-scan.sh. Plants one fake secret |
| 4 | # per rule in a throwaway repo (one in a deleted file, one in a commit message, |
| 5 | # one in a blob with NUL bytes, one inside a gzip blob) and fails unless every |
| 6 | # planted one is found and the NUL blob is listed as binary. |
| 7 | set -euo pipefail |
| 8 | here=$(cd "$(dirname "$0")" && pwd) |
| 9 | t=$(mktemp -d); trap 'rm -rf "$t"' EXIT |
| 10 | git init -q "$t/r"; cd "$t/r" |
| 11 | git config user.email t@example.invalid; git config user.name t |
| 12 | k=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij0123456789 |
| 13 | # The fakes are put together at run time so no secret-shaped string sits in this file (outside scanners stay quiet). |
| 14 | b=-----BEGIN; jh=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9; ak=api_key |
| 15 | { |
| 16 | echo "$b OPENSSH PRIVATE KEY-----" |
| 17 | echo "AKIA${k:0:16}" |
| 18 | echo "ghp_${k:0:36}" |
| 19 | echo "github_pat_${k}${k:0:20}" |
| 20 | echo "xo""xb-1234567890-abcdef" |
| 21 | echo "sk-ant-api03-${k:0:30}" |
| 22 | echo "sk-${k:0:40}" |
| 23 | echo "AIza${k:0:35}" |
| 24 | echo "tskey-auth-${k:0:24}" |
| 25 | echo "glpat-${k:0:24}" |
| 26 | echo "xai-${k}" |
| 27 | echo "$jh.eyJzdWIiOiIxMjM0NTY3ODkwIn0.abcdefghijklmnop" |
| 28 | echo "ssh-ed25519 AAAA${k}${k}" |
| 29 | echo "$ak = \"abcdefghijklmnop1234\"" |
| 30 | } > leak.txt |
| 31 | planted=$(wc -l < leak.txt) |
| 32 | git add leak.txt; git commit -qm "add" |
| 33 | git rm -q leak.txt; git commit -qm "remove; also npm_${k:0:36}" |
| 34 | planted=$((planted + 1)) |
| 35 | # A binary blob (NUL bytes) and a compressed one: both must still be read. |
| 36 | printf 'bin\000\001\002\nAKIA%s\n\000tail\n' "${k:0:16}" > blob.bin |
| 37 | printf 'ghp_%s\n' "${k:4:36}" | gzip -9n > leak.gz |
| 38 | git add blob.bin leak.gz; git commit -qm "binary and gzip" |
| 39 | planted=$((planted + 2)) |
| 40 | binsha=$(git rev-parse HEAD:blob.bin) |
| 41 | if "$here/audit-scan.sh" "$t/r" "$t/out" > "$t/log"; then echo "SELFTEST FAIL: scanner reported clean"; exit 1; fi |
| 42 | found=$(wc -l < "$t/out/secrets.txt") |
| 43 | if (( found < planted )); then echo "SELFTEST FAIL: planted $planted, found $found"; cat "$t/out/secrets.txt"; exit 1; fi |
| 44 | if ! grep -q "^$binsha " "$t/out/binaries.txt"; then echo "SELFTEST FAIL: NUL-byte blob not listed in binaries.txt"; exit 1; fi |
| 45 | if ! grep -q "leak.gz(gzip):" "$t/out/secrets.txt"; then echo "SELFTEST FAIL: secret inside gzip blob not found"; exit 1; fi |
| 46 | echo "SELFTEST PASS: planted $planted (one in a deleted file's history, one in a commit message, one in a NUL-byte blob, one gzipped), found $found; binary listed" |
| 47 | bash "$here/audit-error-selftest.sh" |