|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -# Save the exact stdout bytes produced by a Black Belt response. |
5 | | -# Network transport is opt-in through BBEA_TRANSPORT. |
6 | | -OUTPUT="${1:?response file required}" |
| 4 | +# Transmit an already-saved Black Belt response without modifying its bytes. |
| 5 | +OUTPUT="${1:?saved response file required}" |
| 6 | +[[ -f "$OUTPUT" ]] || { echo "Response file not found: $OUTPUT" >&2; exit 2; } |
7 | 7 |
|
8 | | -mkdir -p "$(dirname -- "$OUTPUT")" |
9 | | - |
10 | | -if [[ "${BBEA_NO_SAVE:-0}" != "1" ]]; then |
11 | | - cat > "$OUTPUT" |
12 | | -else |
13 | | - cat >/dev/null |
| 8 | +if [[ -z "${BBEA_TRANSPORT:-}" ]]; then |
| 9 | + exit 0 |
14 | 10 | fi |
15 | 11 |
|
16 | | -if [[ -n "${BBEA_TRANSPORT:-}" ]]; then |
17 | | - transport="$BBEA_TRANSPORT" |
18 | | - case "$transport" in |
19 | | - https://*|http://*) |
20 | | - if [[ "$transport" == http://* && "${BBEA_ALLOW_INSECURE:-0}" != "1" ]]; then |
21 | | - echo "Refusing plaintext HTTP transport; use HTTPS or set BBEA_ALLOW_INSECURE=1." >&2 |
22 | | - exit 8 |
23 | | - fi |
24 | | - curl --fail-with-body --silent --show-error --data-binary "@$OUTPUT" \ |
25 | | - -H 'Content-Type: application/octet-stream' "$transport" >/dev/null |
26 | | - ;; |
27 | | - ssh://*) |
28 | | - target="${transport#ssh://}" |
29 | | - hostpart="${target%%/*}" |
30 | | - remotepath="/${target#*/}" |
31 | | - if [[ "$target" == "$hostpart" ]]; then |
32 | | - echo "SSH transport requires ssh://user@host/path." >&2 |
33 | | - exit 9 |
34 | | - fi |
35 | | - scp -- "$OUTPUT" "${hostpart}:${remotepath}" |
36 | | - ;; |
37 | | - telnet://*|raw://*) |
38 | | - if [[ "${BBEA_ALLOW_INSECURE:-0}" != "1" ]]; then |
39 | | - echo "Refusing plaintext Telnet/Raw transport; set BBEA_ALLOW_INSECURE=1 explicitly." >&2 |
40 | | - exit 10 |
41 | | - fi |
42 | | - target="${transport#*://}" |
43 | | - host="${target%%:*}" |
44 | | - port="${target##*:}" |
45 | | - command -v nc >/dev/null 2>&1 || { echo "nc is required for raw/telnet transport." >&2; exit 11; } |
46 | | - nc "$host" "$port" < "$OUTPUT" |
47 | | - ;; |
48 | | - *) |
49 | | - echo "Unsupported BBEA_TRANSPORT: $transport" >&2 |
50 | | - exit 12 |
51 | | - ;; |
52 | | - esac |
53 | | -fi |
| 12 | +transport="$BBEA_TRANSPORT" |
| 13 | +case "$transport" in |
| 14 | + https://*|http://*) |
| 15 | + if [[ "$transport" == http://* && "${BBEA_ALLOW_INSECURE:-0}" != "1" ]]; then |
| 16 | + echo "Refusing plaintext HTTP transport; use HTTPS or set BBEA_ALLOW_INSECURE=1." >&2 |
| 17 | + exit 8 |
| 18 | + fi |
| 19 | + curl --fail-with-body --silent --show-error --data-binary "@$OUTPUT" \ |
| 20 | + -H 'Content-Type: application/octet-stream' "$transport" >/dev/null |
| 21 | + ;; |
| 22 | + ssh://*) |
| 23 | + target="${transport#ssh://}" |
| 24 | + hostpart="${target%%/*}" |
| 25 | + remotepath="/${target#*/}" |
| 26 | + if [[ "$target" == "$hostpart" ]]; then |
| 27 | + echo "SSH transport requires ssh://user@host/path." >&2 |
| 28 | + exit 9 |
| 29 | + fi |
| 30 | + scp -- "$OUTPUT" "${hostpart}:${remotepath}" |
| 31 | + ;; |
| 32 | + telnet://*|raw://*) |
| 33 | + if [[ "${BBEA_ALLOW_INSECURE:-0}" != "1" ]]; then |
| 34 | + echo "Refusing plaintext Telnet/Raw transport; set BBEA_ALLOW_INSECURE=1 explicitly." >&2 |
| 35 | + exit 10 |
| 36 | + fi |
| 37 | + target="${transport#*://}" |
| 38 | + host="${target%%:*}" |
| 39 | + port="${target##*:}" |
| 40 | + command -v nc >/dev/null 2>&1 || { echo "nc is required for raw/telnet transport." >&2; exit 11; } |
| 41 | + nc "$host" "$port" < "$OUTPUT" |
| 42 | + ;; |
| 43 | + *) |
| 44 | + echo "Unsupported BBEA_TRANSPORT: $transport" >&2 |
| 45 | + exit 12 |
| 46 | + ;; |
| 47 | +esac |
0 commit comments