interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tools / extract / audit-selftest.sh

47 lines · 2447 bytes Raw Blame History
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.
7set -euo pipefail
8here=$(cd "$(dirname "$0")" && pwd)
9t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
10git init -q "$t/r"; cd "$t/r"
11git config user.email t@example.invalid; git config user.name t
12k=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij0123456789
13# The fakes are put together at run time so no secret-shaped string sits in this file (outside scanners stay quiet).
14b=-----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
31planted=$(wc -l < leak.txt)
32git add leak.txt; git commit -qm "add"
33git rm -q leak.txt; git commit -qm "remove; also npm_${k:0:36}"
34planted=$((planted + 1))
35# A binary blob (NUL bytes) and a compressed one: both must still be read.
36printf 'bin\000\001\002\nAKIA%s\n\000tail\n' "${k:0:16}" > blob.bin
37printf 'ghp_%s\n' "${k:4:36}" | gzip -9n > leak.gz
38git add blob.bin leak.gz; git commit -qm "binary and gzip"
39planted=$((planted + 2))
40binsha=$(git rev-parse HEAD:blob.bin)
41if "$here/audit-scan.sh" "$t/r" "$t/out" > "$t/log"; then echo "SELFTEST FAIL: scanner reported clean"; exit 1; fi
42found=$(wc -l < "$t/out/secrets.txt")
43if (( found < planted )); then echo "SELFTEST FAIL: planted $planted, found $found"; cat "$t/out/secrets.txt"; exit 1; fi
44if ! grep -q "^$binsha " "$t/out/binaries.txt"; then echo "SELFTEST FAIL: NUL-byte blob not listed in binaries.txt"; exit 1; fi
45if ! grep -q "leak.gz(gzip):" "$t/out/secrets.txt"; then echo "SELFTEST FAIL: secret inside gzip blob not found"; exit 1; fi
46echo "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"
47bash "$here/audit-error-selftest.sh"