#!/usr/bin/env bash # Scenario B: decrypt a transit blob produced by secret-encrypt.sh. # secret-decrypt.sh [outfile] (default outfile: w/o .vaultenc, +.dec) set -euo pipefail ADDR="${BAO_ADDR:-http://127.0.0.1:8200}" TOKF="$HOME/.config/openbao/personal-transit.token" KEY="personal-backup" in="${1:?usage: secret-decrypt.sh [outfile]}" out="${2:-${in%.vaultenc}.dec}" [ -r "$TOKF" ] || { echo "no token at $TOKF" >&2; exit 1; } [ -r "$in" ] || { echo "no input file: $in" >&2; exit 1; } b64="$(cat "$in" \ | python3 -c 'import json,sys;print(json.dumps({"ciphertext":sys.stdin.read().strip()}))' \ | curl -sS -H "X-Vault-Token: $(cat "$TOKF")" --data @- "$ADDR/v1/transit-personal/decrypt/$KEY" \ | jq -r '.data.plaintext // empty')" [ -n "$b64" ] || { echo "decrypt failed (wrong key/blob?)" >&2; exit 1; } printf '%s' "$b64" | base64 -d > "$out" echo "decrypted $in -> $out"