diff options
author | Nicholas Johnson <nick@nicholasjohnson.ch> | 2022-12-16 00:00:00 +0000 |
---|---|---|
committer | Nicholas Johnson <nick@nicholasjohnson.ch> | 2023-08-26 00:00:00 +0000 |
commit | 01290a5a1c9230c48b9d5ca225f9a8386584f77a (patch) | |
tree | 4612f735c3187d0a5ac4f707665c532c4990e281 | |
parent | a364d2a71ad24158a009c266102ce0d91149de67 (diff) | |
download | pass-otp-master.tar.gz pass-otp-master.zip |
-rwxr-xr-x | otp.bash | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -20,6 +20,9 @@ VERSION="1.1.2" OATH=$(which oathtool) OTPTOOL=$(which otptool) +[[ "$PROGRAM" == "passage" ]] && PASSAGE=true +[[ $PASSAGE ]] && GPG=age && ext=age || ext=gpg + ## source: https://gist.github.com/cdown/1163649 urlencode() { local l=${#1} @@ -137,9 +140,10 @@ otp_insert() { set_git "$passfile" mkdir -p -v "$PREFIX/$(dirname "$path")" - set_gpg_recipients "$(dirname "$path")" + [[ $PASSAGE ]] || set_gpg_recipients "$(dirname "$path")" - echo "$contents" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "OTP secret encryption aborted." + [[ $PASSAGE ]] && local age_opts=("-i" "$PASSAGE_IDENTITIES_FILE") + echo "$contents" | $GPG "${age_opts[@]}" -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "OTP secret encryption aborted." if [[ "$quiet" -eq 1 ]]; then git_add_file "$passfile" "$message" 1>/dev/null @@ -243,7 +247,7 @@ cmd_otp_insert() { yesno "Insert into $path?" fi - local passfile="$PREFIX/$path.gpg" + local passfile="$PREFIX/$path.$ext" [[ $force -eq 0 && -e $passfile ]] && yesno "An entry already exists for $path. Overwrite it?" otp_insert "$path" "$passfile" "$otp_uri" "Add OTP secret for $path to store." @@ -268,16 +272,17 @@ cmd_otp_append() { local uri local path="${1%/}" local prompt="$path" - local passfile="$PREFIX/$path.gpg" + local passfile="$PREFIX/$path.$ext" [[ -f $passfile ]] || die "Passfile not found" + [[ $PASSAGE ]] && local age_opts=("-i" "$PASSAGE_IDENTITIES_FILE") local existing contents="" while IFS= read -r line || [ -n "$line" ]; do [[ -z "$existing" && "$line" == otpauth://* ]] && existing="$line" [[ -n "$contents" ]] && contents+=$'\n' contents+="$line" - done < <($GPG -d "${GPG_OPTS[@]}" "$passfile") + done < <($GPG "${age_opts[@]}" -d "${GPG_OPTS[@]}" "$passfile") [[ -n "$existing" ]] && yesno "An OTP secret already exists for $path. Overwrite it?" @@ -329,11 +334,12 @@ cmd_otp_code() { [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] [--quiet,-q] pass-name" local path="${1%/}" - local passfile="$PREFIX/$path.gpg" + local passfile="$PREFIX/$path.$ext" check_sneaky_paths "$path" [[ ! -f $passfile ]] && die "$path: passfile not found." - contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile") + [[ $PASSAGE ]] && local age_opts=("-i" "$PASSAGE_IDENTITIES_FILE") + contents=$($GPG "${age_opts[@]}" -d "${GPG_OPTS[@]}" "$passfile") while read -r line; do if [[ "$line" == otpauth://* ]]; then local uri="$line" @@ -401,11 +407,12 @@ cmd_otp_uri() { [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND uri [--clip,-c | --qrcode,-q] pass-name" local path="$1" - local passfile="$PREFIX/$path.gpg" + local passfile="$PREFIX/$path.$ext" check_sneaky_paths "$path" [[ ! -f $passfile ]] && die "Passfile not found" - contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile") + [[ $PASSAGE ]] && local age_opts=("-i" "$PASSAGE_IDENTITIES_FILE") + contents=$($GPG "${age_opts[@]}" -d "${GPG_OPTS[@]}" "$passfile") while read -r line; do if [[ "$line" == otpauth://* ]]; then otp_parse_uri "$line" |