@@ -20,6 +20,12 @@ VERSION="1.1.2"
20
20
OATH=$( which oathtool)
21
21
OTPTOOL=$( which otptool)
22
22
23
+ if [[ $PASSAGE == 1 ]]; then
24
+ EXT=" age"
25
+ else
26
+ EXT=" gpg"
27
+ fi
28
+
23
29
# # source: https://gist.github.com/cdown/1163649
24
30
urlencode () {
25
31
local l=${# 1}
@@ -137,9 +143,13 @@ otp_insert() {
137
143
set_git " $passfile "
138
144
139
145
mkdir -p -v " $PREFIX /$( dirname " $path " ) "
140
- set_gpg_recipients " $( dirname " $path " ) "
141
-
142
- echo " $contents " | $GPG -e " ${GPG_RECIPIENT_ARGS[@]} " -o " $passfile " " ${GPG_OPTS[@]} " || die " OTP secret encryption aborted."
146
+ if [[ $PASSAGE == 1 ]]; then
147
+ set_age_recipients " $( dirname " $path " ) "
148
+ echo " $contents " | $AGE -e " ${AGE_RECIPIENT_ARGS[@]} " -o " $passfile " || die " OTP secret encryption aborted"
149
+ else
150
+ set_gpg_recipients " $( dirname " $path " ) "
151
+ echo " $contents " | $GPG -e " ${GPG_RECIPIENT_ARGS[@]} " -o " $passfile " " ${GPG_OPTS[@]} " || die " OTP secret encryption aborted."
152
+ fi
143
153
144
154
if [[ " $quiet " -eq 1 ]]; then
145
155
git_add_file " $passfile " " $message " 1> /dev/null
@@ -243,7 +253,7 @@ cmd_otp_insert() {
243
253
yesno " Insert into $path ?"
244
254
fi
245
255
246
- local passfile=" $PREFIX /$path .gpg "
256
+ local passfile=" $PREFIX /$path .$EXT "
247
257
[[ $force -eq 0 && -e $passfile ]] && yesno " An entry already exists for $path . Overwrite it?"
248
258
249
259
otp_insert " $path " " $passfile " " $otp_uri " " Add OTP secret for $path to store."
@@ -268,16 +278,21 @@ cmd_otp_append() {
268
278
local uri
269
279
local path=" ${1%/ } "
270
280
local prompt=" $path "
271
- local passfile=" $PREFIX /$path .gpg "
281
+ local passfile=" $PREFIX /$path .$EXT "
272
282
273
283
[[ -f $passfile ]] || die " Passfile not found"
284
+ if [[ $PASSAGE == 1 ]]; then
285
+ old_contents=$( $AGE -d -i " $IDENTITIES_FILE " " $passfile " )
286
+ else
287
+ old_contents=$( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
288
+ fi
274
289
275
290
local existing contents=" "
276
291
while IFS= read -r line || [ -n " $line " ]; do
277
292
[[ -z " $existing " && " $line " == otpauth://* ]] && existing=" $line "
278
293
[[ -n " $contents " ]] && contents+=$' \n '
279
294
contents+=" $line "
280
- done < <( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
295
+ done < <( echo " $old_contents " )
281
296
282
297
[[ -n " $existing " ]] && yesno " An OTP secret already exists for $path . Overwrite it?"
283
298
@@ -329,11 +344,15 @@ cmd_otp_code() {
329
344
[[ $err -ne 0 || $# -ne 1 ]] && die " Usage: $PROGRAM $COMMAND [--clip,-c] [--quiet,-q] pass-name"
330
345
331
346
local path=" ${1%/ } "
332
- local passfile=" $PREFIX /$path .gpg "
347
+ local passfile=" $PREFIX /$path .$EXT "
333
348
check_sneaky_paths " $path "
334
349
[[ ! -f $passfile ]] && die " $path : passfile not found."
335
350
336
- contents=$( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
351
+ if [[ $PASSAGE == 1 ]]; then
352
+ contents=$( $AGE -d -i " $IDENTITIES_FILE " " $passfile " )
353
+ else
354
+ contents=$( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
355
+ fi
337
356
while read -r line; do
338
357
if [[ " $line " == otpauth://* ]]; then
339
358
local uri=" $line "
@@ -401,11 +420,15 @@ cmd_otp_uri() {
401
420
[[ $err -ne 0 || $# -ne 1 ]] && die " Usage: $PROGRAM $COMMAND uri [--clip,-c | --qrcode,-q] pass-name"
402
421
403
422
local path=" $1 "
404
- local passfile=" $PREFIX /$path .gpg "
423
+ local passfile=" $PREFIX /$path .$EXT "
405
424
check_sneaky_paths " $path "
406
425
[[ ! -f $passfile ]] && die " Passfile not found"
426
+ if [[ $PASSAGE == 1 ]]; then
427
+ contents=$( $AGE -d -i " $IDENTITIES_FILE " " $passfile " )
428
+ else
429
+ contents=$( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
430
+ fi
407
431
408
- contents=$( $GPG -d " ${GPG_OPTS[@]} " " $passfile " )
409
432
while read -r line; do
410
433
if [[ " $line " == otpauth://* ]]; then
411
434
otp_parse_uri " $line "
0 commit comments