Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
tests/gnupg
tests/password-store
tests/passage
42 changes: 33 additions & 9 deletions genphrase.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH>,--dict=<PATH>] pass-name [word-count]"

if [[ $PASSAGE == 1 ]]; then
EXT="age"
else
EXT="gpg"
fi


cmd_genphrase_help () {
cat << __genphrase_usage_097612_EOF
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions tests/identities
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# created: 2026-07-22T23:41:20+02:00
# public key: age1953gjftem2ekh43w2j738gf9xv8xu32jp3pqgth3evrh405mcgcqgzyjc2
AGE-SECRET-KEY-1UL3NS84RS4U9YGATH67ZPQWYY5JN44Y0P8ZTPETFNATQY3USY6PS7E4DCC
37 changes: 37 additions & 0 deletions tests/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down