2021-02-24 06:18:01 -05:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-02-25 14:03:38 -05:00
|
|
|
set -e
|
|
|
|
|
|
|
|
positional=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
argument="$1"
|
|
|
|
case $argument in
|
|
|
|
--split-words)
|
|
|
|
split_words=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
positional+=("$1")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
set -- "${positional[@]}"
|
|
|
|
|
2021-02-24 06:18:01 -05:00
|
|
|
bold=$(tput bold)
|
|
|
|
red=$(tput setaf 1)
|
|
|
|
normal=$(tput sgr0)
|
|
|
|
|
|
|
|
printf "%s\n" "Scan QR code…"
|
|
|
|
|
|
|
|
data=""
|
|
|
|
|
|
|
|
while read line; do
|
|
|
|
if echo -n $line | grep -Eq "^QR-Code:"; then
|
|
|
|
line=$(echo -n $line | sed 's/QR-Code://')
|
|
|
|
fi
|
|
|
|
data="$data$line"
|
|
|
|
if [ "$line" = "-----END PGP MESSAGE-----" ]; then
|
|
|
|
killall zbarcam --signal SIGINT
|
|
|
|
else
|
|
|
|
data="$data\n"
|
|
|
|
fi
|
|
|
|
done < <(zbarcam --nodisplay --quiet)
|
|
|
|
|
|
|
|
encrypted_secret=$(echo -e $data)
|
|
|
|
|
|
|
|
encrypted_secret_hash=$(echo -n "$encrypted_secret" | openssl dgst -sha512 | sed 's/^.* //')
|
|
|
|
encrypted_secret_short_hash=$(echo -n "$encrypted_secret_hash" | head -c 8)
|
|
|
|
|
|
|
|
printf "%s\n" "$encrypted_secret"
|
|
|
|
printf "SHA512 hash: $bold%s$normal\n" "$encrypted_secret_hash"
|
|
|
|
printf "SHA512 short hash: $bold%s$normal\n" "$encrypted_secret_short_hash"
|
|
|
|
|
|
|
|
printf "$bold$red%s$normal\n" "Show secret? (y or n)? "
|
|
|
|
|
|
|
|
read -r answer
|
|
|
|
if [ "$answer" = "y" ]; then
|
|
|
|
secret=$(echo -e "$encrypted_secret" | gpg --decrypt)
|
|
|
|
gpg-connect-agent reloadagent /bye > /dev/null 2>&1
|
2021-02-25 14:03:38 -05:00
|
|
|
if [ "$split_words" = true ]; then
|
|
|
|
printf "%s" "Secret: "
|
|
|
|
array=($secret)
|
|
|
|
for i in ${!array[@]}; do
|
|
|
|
position=$(($i + 1))
|
|
|
|
printf "%s" "$position.$bold${array[$i]}$normal "
|
|
|
|
done
|
|
|
|
printf "\n"
|
|
|
|
else
|
|
|
|
printf "Secret: $bold%s$normal\n" "$secret"
|
|
|
|
fi
|
2021-02-24 06:18:01 -05:00
|
|
|
fi
|
|
|
|
|
2021-02-25 14:03:38 -05:00
|
|
|
printf "%s\n" "Done"
|