Skip to content

Commit

Permalink
Support passage as backend
Browse files Browse the repository at this point in the history
  • Loading branch information
remko committed Dec 28, 2022
1 parent a364d2a commit 5a1528e
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions otp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,22 @@ otp_read_secret() {
otp_insert() {
local path="$1" passfile="$2" contents="$3" message="$4" quiet="$5"

check_sneaky_paths "$path"
set_git "$passfile"
if [[ $PASSAGE == 1 ]]; then
echo "$contents" | $PROGRAM insert -m $path
else
check_sneaky_paths "$path"
set_git "$passfile"

mkdir -p -v "$PREFIX/$(dirname "$path")"
set_gpg_recipients "$(dirname "$path")"
mkdir -p -v "$PREFIX/$(dirname "$path")"
set_gpg_recipients "$(dirname "$path")"

echo "$contents" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "OTP secret encryption aborted."
echo "$contents" | $GPG -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
else
git_add_file "$passfile" "$message"
if [[ "$quiet" -eq 1 ]]; then
git_add_file "$passfile" "$message" 1>/dev/null
else
git_add_file "$passfile" "$message"
fi
fi
}

Expand Down Expand Up @@ -269,15 +273,19 @@ cmd_otp_append() {
local path="${1%/}"
local prompt="$path"
local passfile="$PREFIX/$path.gpg"

[[ -f $passfile ]] || die "Passfile not found"
if [[ $PASSAGE == 1 ]]; then
old_contents=$($PROGRAM show $1)
else
[[ -f $passfile ]] || die "Passfile not found"
old_contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
fi

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 < <(echo "$old_contents")

[[ -n "$existing" ]] && yesno "An OTP secret already exists for $path. Overwrite it?"

Expand Down Expand Up @@ -328,12 +336,16 @@ 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"
check_sneaky_paths "$path"
[[ ! -f $passfile ]] && die "$path: passfile not found."
if [[ $PASSAGE == 1 ]]; then
contents=$($PROGRAM show $1)
else
local path="${1%/}"
check_sneaky_paths "$path"
local passfile="$PREFIX/$path.gpg"
[[ ! -f $passfile ]] && die "$path: passfile not found."

contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
fi
while read -r line; do
if [[ "$line" == otpauth://* ]]; then
local uri="$line"
Expand Down Expand Up @@ -400,12 +412,16 @@ 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"
check_sneaky_paths "$path"
[[ ! -f $passfile ]] && die "Passfile not found"
if [[ $PASSAGE == 1 ]]; then
contents=$($PROGRAM show $1)
else
local path="$1"
local passfile="$PREFIX/$path.gpg"
check_sneaky_paths "$path"
[[ ! -f $passfile ]] && die "Passfile not found"
contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
fi

contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
while read -r line; do
if [[ "$line" == otpauth://* ]]; then
otp_parse_uri "$line"
Expand Down

0 comments on commit 5a1528e

Please sign in to comment.