2020-06-02 12:56:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
deps=(curl jq)
|
|
|
|
for cmd in "${deps[@]}"; do
|
2023-04-14 11:06:14 +00:00
|
|
|
which ${cmd} >/dev/null || {
|
|
|
|
echo "'${cmd}' util is required for this script"
|
|
|
|
exit 1
|
|
|
|
}
|
2020-06-02 12:56:25 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Get URL from CLI argument
|
|
|
|
url="${1:-}"
|
|
|
|
[[ -n $url ]] || {
|
2023-04-14 11:06:14 +00:00
|
|
|
echo "Usage: $0 'URL to get the secret'"
|
|
|
|
exit 1
|
2020-06-02 12:56:25 +00:00
|
|
|
}
|
|
|
|
# normalize url and extract parts
|
|
|
|
url="${url/|/%7C}"
|
|
|
|
host="${url%%/\#*}"
|
|
|
|
idpass="${url##*\#}"
|
|
|
|
pass="${idpass##*\%7C}"
|
|
|
|
id="${idpass%%\%7C*}"
|
|
|
|
geturl="${host}/api/get/${id}"
|
|
|
|
|
|
|
|
# fetch secret and decrypt to STDOUT
|
|
|
|
curl -sSf "${geturl}" | jq -r ".secret" |
|
2023-04-14 11:06:14 +00:00
|
|
|
openssl aes-256-cbc -base64 -pass "pass:${pass}" -iter 300000 -md sha512 -d 2>/dev/null
|