[pass] Password-Store with Cygwin, but Gpg4Win (patch included)
Lorenz Weber
mail at lenzw.de
Mon Aug 25 14:29:36 CEST 2014
Hi,
as there is no cygwin-compatible copy of gpg2 and I am using an OpenPGP
smartcard v2 and thus am bound to use gpg2, I made some modifications
that the external Gpg4win binary is called with Windows paths while
everything else is called with *nix paths.
I am aware that this is a niche patch that would most probably clutter
the original program, so I don't expect that it will be included in
pass, but it may be useful for someone else, so I'm posting it here.
What would be the best course of action to preserve this for others with
a similar setup?
Would it be okay to open a fork on github on this?
Regards,
Lorenz
-------------- next part --------------
diff --git a/src/password-store.sh b/src/password-store.sh
index 2287a46..31636a4 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -18,6 +18,23 @@ CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"
export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}"
+
+#
+# gpg4win specific
+#
+handle_path(){
+ if [ -z "$GPG4WIN" ]; then
+ $GPG --help | grep -q Gpg4win
+ GPG4WIN=$?
+ fi
+
+ if [ $GPG4WIN -eq 0 ] && [ -f /usr/bin/cygpath ]; then
+ cygpath -am $*
+ else
+ echo $*
+ fi
+}
+
#
# BEGIN helper functions
#
@@ -110,11 +127,11 @@ reencrypt_path() {
done
gpg_keys="$($GPG --list-keys --keyid-format long "${GPG_RECIPIENTS[@]}" | sed -n 's/sub *.*\/\([A-F0-9]\{16\}\) .*/\1/p' | LC_ALL=C sort -u)"
fi
- current_keys="$($GPG -v --no-secmem-warning --no-permission-warning --list-only --keyid-format long "$passfile" 2>&1 | cut -d ' ' -f 5 | LC_ALL=C sort -u)"
+ current_keys="$($GPG -v --no-secmem-warning --no-permission-warning --list-only --keyid-format long "$(handle_path $passfile)" 2>&1 | cut -d ' ' -f 5 | LC_ALL=C sort -u)"
if [[ $gpg_keys != "$current_keys" ]]; then
echo "$passfile_display: reencrypting to ${gpg_keys//$'\n'/ }"
- $GPG -d "${GPG_OPTS[@]}" "$passfile" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}" &&
+ $GPG -d "${GPG_OPTS[@]}" "$(handle_path $passfile)" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile_temp)" "${GPG_OPTS[@]}" &&
mv "$passfile_temp" "$passfile" || rm -f "$passfile_temp"
fi
prev_gpg_recipients="${GPG_RECIPIENTS[*]}"
@@ -320,9 +337,9 @@ cmd_show() {
check_sneaky_paths "$path"
if [[ -f $passfile ]]; then
if [[ $clip -eq 0 ]]; then
- exec $GPG -d "${GPG_OPTS[@]}" "$passfile"
+ exec $GPG -d "${GPG_OPTS[@]}" "$(handle_path $passfile)"
else
- local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | head -n 1)"
+ local pass="$($GPG -d "${GPG_OPTS[@]}" "$(handle_path $passfile)" | head -n 1)"
[[ -n $pass ]] || exit 1
clip "$pass" "$path"
fi
@@ -352,7 +369,7 @@ cmd_grep() {
agent_check
local search="$1" passfile grepresults
while read -r -d "" passfile; do
- grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$search")"
+ grepresults="$($GPG -d "${GPG_OPTS[@]}" "$(handle_path $passfile)" | grep --color=always "$search")"
[ $? -ne 0 ] && continue
passfile="${passfile%.gpg}"
passfile="${passfile#$PREFIX/}"
@@ -388,7 +405,7 @@ cmd_insert() {
if [[ $multiline -eq 1 ]]; then
echo "Enter contents of $path and press Ctrl+D when finished:"
echo
- $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}"
+ $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile)" "${GPG_OPTS[@]}"
elif [[ $noecho -eq 1 ]]; then
local password password_again
while true; do
@@ -397,7 +414,7 @@ cmd_insert() {
read -r -p "Retype password for $path: " -s password_again || exit 1
echo
if [[ $password == "$password_again" ]]; then
- $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" <<<"$password"
+ $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile)" "${GPG_OPTS[@]}" <<<"$password"
break
else
echo "Error: the entered passwords do not match."
@@ -406,7 +423,7 @@ cmd_insert() {
else
local password
read -r -p "Enter password for $path: " -e password
- $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" <<<"$password"
+ $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile)" "${GPG_OPTS[@]}" <<<"$password"
fi
git_add_file "$passfile" "Add given password for $path to store."
}
@@ -426,12 +443,12 @@ cmd_edit() {
local action="Add"
if [[ -f $passfile ]]; then
- $GPG -d -o "$tmp_file" "${GPG_OPTS[@]}" "$passfile" || exit 1
+ $GPG -d -o "$(handle_path $tmp_file)" "${GPG_OPTS[@]}" "$(handle_path $passfile)" || exit 1
action="Edit"
fi
${EDITOR:-vi} "$tmp_file"
[[ -f $tmp_file ]] || die "New password not saved."
- while ! $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" "$tmp_file"; do
+ while ! $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile)" "${GPG_OPTS[@]}" "$(handle_path $tmp_file)"; do
yesno "GPG encryption failed. Would you like to try again?"
done
git_add_file "$passfile" "$action password for $path using ${EDITOR:-vi}."
@@ -464,10 +481,10 @@ cmd_generate() {
local pass="$(pwgen -s $symbols $length 1)"
[[ -n $pass ]] || exit 1
if [[ $inplace -eq 0 ]]; then
- $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" <<<"$pass"
+ $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$(handle_path $passfile)" "${GPG_OPTS[@]}" <<<"$pass"
else
local passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--"
- if $GPG -d "${GPG_OPTS[@]}" "$passfile" | sed $'1c \\\n'"$(sed 's/[\/&]/\\&/g' <<<"$pass")"$'\n' | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}"; then
+ if $GPG -d "${GPG_OPTS[@]}" "$(handle_path $passfile)" | sed $'1c \\\n'"$(sed 's/[\/&]/\\&/g' <<<"$pass")"$'\n' | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}"; then
mv "$passfile_temp" "$passfile"
else
rm -f "$passfile_temp"
More information about the Password-Store
mailing list