From 625ddd0a9db0d084c670eff81b8dfc259f76b464 Mon Sep 17 00:00:00 2001 From: bestlibre Date: Mon, 11 May 2020 14:51:10 +0200 Subject: [PATCH] Add exemple script to get secret from CLI --- cli_get.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cli_get.sh diff --git a/cli_get.sh b/cli_get.sh new file mode 100644 index 0000000..c4c1e20 --- /dev/null +++ b/cli_get.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -euo pipefail + +deps=(curl jq) +for cmd in "${deps[@]}"; do + which ${cmd} >/dev/null || { + echo "'${cmd}' util is required for this script" + exit 1 + } +done + +# Get URL from CLI argument +URL=${@:-} +[[ -n $URL ]] || { + echo "Usage: $0 'URL to get the secret'" + exit 1 +} +# normalize url and extract parts +URL=${URL/|/%7C} +HOST=${URL%%/\#*} +IDPASS=${URL##*\#} +PASS=${IDPASS##*\%7C} +ID=${IDPASS%%\%7C*} +GETURL=${HOST}/api/get/${ID} + +# Get the secret +resp=$(curl -s $GETURL) +# decrypt +deciphertext=$(echo $resp| jq -r ".secret" | openssl aes-256-cbc -base64 -pass "pass:$PASS" -md md5 -d 2> /dev/null) +echo $deciphertext