diff --git a/.gitignore b/.gitignore index 2d7c4a9..002edec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ tests/gnupg tests/password-store +tests/passage diff --git a/genphrase.bash b/genphrase.bash index 11b7e17..f7be2e7 100755 --- a/genphrase.bash +++ b/genphrase.bash @@ -51,6 +51,12 @@ GENPHRASE_EXEC="$GENPHRASE_RESOURCES/_phrase.py" GENPHRASE_DEFAULT_WORDCOUNT=6 CMD_GENPHRASE_USAGE="Usage: $PROGRAM $COMMAND [-h,--help] [-c,--clip] [-f,--force] [-i,--in-place] [-q,--qrcode] [-n, --no-spaces] [-d ,--dict=] pass-name [word-count]" +if [[ $PASSAGE == 1 ]]; then + EXT="age" +else + EXT="gpg" +fi + cmd_genphrase_help () { cat << __genphrase_usage_097612_EOF @@ -123,8 +129,12 @@ cmd_genphrase_exec () { # NOTE: lots of copypasta mkdir -p -v "$PREFIX/$(dirname -- "$path")" - set_gpg_recipients "$(dirname -- "$path")" - local passfile="$PREFIX/$path.gpg" + if [[ $PASSAGE == 1 ]]; then + set_age_recipients "$(dirname "$path")" + else + set_gpg_recipients "$(dirname "$path")" + fi + local passfile="$PREFIX/$path.$EXT" set_git "$passfile" if [[ $inplace -eq 0 && $force -eq 0 && -e $passfile ]]; then @@ -147,15 +157,29 @@ cmd_genphrase_exec () { die "Error: passphrase generation failed (word count mismatch)." fi - if [[ $inplace -eq 0 ]]; then - echo "$passphrase" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "Password encryption aborted." + if [[ $PASSAGE == 1 ]]; then + if [[ $inplace -eq 0 ]]; then + echo "$passphrase" | $AGE -e "${AGE_RECIPIENT_ARGS[@]}" -o "$passfile"|| die "Password encryption aborted." + else + local passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--" + if { echo "$passphrase"; $AGE -d -i "$IDENTITIES_FILE" "$passfile" | tail -n +2; } | $AGE -e "${AGE_RECIPIENT_ARGS[@]}" -o "$passfile_temp"; then + mv "$passfile_temp" "$passfile" + else + rm -f "$passfile_temp" + die "Could not reencrypt new password." + fi + fi else - local passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--" - if { echo "$passphrase"; $GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +2; } | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}"; then - mv "$passfile_temp" "$passfile" + if [[ $inplace -eq 0 ]]; then + echo "$passphrase" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "Password encryption aborted." else - rm -f "$passfile_temp" - die "Could not reencrypt new password." + local passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--" + if { echo "$passphrase"; $GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +2; } | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}"; then + mv "$passfile_temp" "$passfile" + else + rm -f "$passfile_temp" + die "Could not reencrypt new password." + fi fi fi local verb="Add" diff --git a/tests/identities b/tests/identities new file mode 100644 index 0000000..61d652f --- /dev/null +++ b/tests/identities @@ -0,0 +1,3 @@ +# created: 2026-07-22T23:41:20+02:00 +# public key: age1953gjftem2ekh43w2j738gf9xv8xu32jp3pqgth3evrh405mcgcqgzyjc2 +AGE-SECRET-KEY-1UL3NS84RS4U9YGATH67ZPQWYY5JN44Y0P8ZTPETFNATQY3USY6PS7E4DCC diff --git a/tests/runall.sh b/tests/runall.sh index a44d4cd..b908e57 100755 --- a/tests/runall.sh +++ b/tests/runall.sh @@ -89,6 +89,7 @@ if ! [ -e "$PASS" ]; then fi export PASS GPG="gpg" +PASSAGE_AGE="age" which gpg2 > /dev/null 2>&1 && GPG="gpg2" export GPG export GNUPGHOME="./gnupg" @@ -128,6 +129,42 @@ echo "Total skipped: $CUL_SKIP" # Clean up. rm -rf "$PASSWORD_STORE_DIR" rm -rf "$GNUPGHOME" + +PASS="$(command -v passage)" +if ! [ -e "$PASS" ]; then + printf '%b: cannot locate "passage" command.\n' "$TERM_FAIL" + exit 1 +fi + + +# Run passage tests +export PASSAGE_DIR="./passage" +export PASSAGE_EXTENSIONS_DIR="../" +export PASSAGE_IDENTITIES_FILE="./passage/identities" +mkdir ./passage +cp ./identities ./passage/identities + +# Run them. +expect_true "help" "./test_help.sh" +expect_true "generate default" "./test_default.sh" +expect_true "generate nospaces" "./test_nospaces.sh" +expect_true "specify length" "./test_len.sh" +expect_true "alt. dictionary (Diceware English)" "./test_dict_en.sh" +expect_true "alt. dictionary (Diceware Czech)" "./test_dict_cz.sh" +expect_true "force" "./test_force.sh" +expect_true "inplace" "./test_inplace.sh" +with_cond "$CLIP_P" expect_true "clipboard" "./test_clip.sh" +with_cond "$CLIP_P" expect_true "clipboard expire" "./test_clip_wait.sh" +with_cond "$QR_P" expect_true "QR code" "./test_qr.sh" +expect_false "conflict options" "./test_conflict.sh" +expect_false "bad length" "./test_bad_length.sh" +expect_false "bad dictionary" "./test_bad_dict.sh" +echo "Total run: $CUL_ALL" +echo "Total failed: $CUL_ST" +echo "Total skipped: $CUL_SKIP" + +# Clean up. +rm -rf "$PASSAGE_DIR" # In case this file gets sourced ... unset PASS unset GPG