aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-10 12:31:43 +0200
committerMatěj Cepl <mcepl@cepl.eu>2023-08-11 11:59:15 +0200
commit0369230fbc74afbc8d289377567ecf9858b1d822 (patch)
treebfdc3d41f8b88790262f68e30765b306650514a8
parenta17fee5ee64a6b6cb294a9f166d7995832b0abe4 (diff)
downloadpinentry-rofi-0369230fbc74afbc8d289377567ecf9858b1d822.tar.gz
fix: just do very light decoding of the SETDESC strings.
So, after getting complete and tested implementation of URLencode/decode, I have found that Assuan doesn’t read that. No encoding aside from very simple ones are deciphered.
-rwxr-xr-xpinentry-rofi.sh11
-rw-r--r--tests/foundational.bats15
2 files changed, 23 insertions, 3 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh
index 7f01b2e..2695a88 100755
--- a/pinentry-rofi.sh
+++ b/pinentry-rofi.sh
@@ -70,7 +70,7 @@ rawurlencode() {
esac
encoded+="${o}"
done
- printf "%s" "${encoded}" # You can either set a return variable (FASTER)
+ printf "%s" "${encoded}" # You can either set a return variable (FASTER)
}
rawurldecode() {
@@ -81,6 +81,11 @@ rawurldecode() {
printf '%b' "${1//%/\\x}"
}
+# Except Assuan apparently doesn't want really encoded strings, but some kind of bastard
+basturldecode () {
+ echo "$1" | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
+}
+
rofi_cmd="rofi -dmenu -input /dev/null -password"
INSIDE_BATS=${INSIDE_BATS:-0}
@@ -164,7 +169,7 @@ while : ; do
#SETDESC Please enter the passphrase for the ssh key%0A ke:yf:in:ge:rp:ri:nt
IFS=" " line_arr=($(split_line "$line"))
log_debug "line_arr: ${line_arr[*]}"
- temp_str="$(rawurldecode "${line_arr[*]}")"
+ temp_str="$(basturldecode "${line_arr[*]}")"
log_debug "temp_str: ${temp_str}"
win_mesg="$(rawurlencode "${temp_str}")"
assuan_send "OK"
@@ -178,7 +183,7 @@ while : ; do
IFS=" " line_arr=($(split_line "$line"))
log_debug "line_arr: ${line_arr[*]}"
log_debug "line_arr: ${line_arr[*]}"
- temp_str="$(rawurldecode "${line_arr[*]}")"
+ temp_str="$(basturldecode "${line_arr[*]}")"
log_debug "temp_str: ${temp_str}"
win_title="$(rawurlencode "${temp_str}")"
assuan_send "OK"
diff --git a/tests/foundational.bats b/tests/foundational.bats
index 2d53b10..458b43f 100644
--- a/tests/foundational.bats
+++ b/tests/foundational.bats
@@ -49,6 +49,21 @@ created 2016-04-27 (main key ID 79205802880BC9D8)."
[[ "$observed" == "$expected" ]] || diff -u <(echo -e "$observed") <(echo -e "$expected")
}
+@test "decode bastardized URL encoded string" {
+ local expected
+ mapfile -d '' expected <<- EOF
+ Please enter the passphrase to unlock the OpenPGP secret key:
+ "Matěj Cepl &lt;mcepl@cepl.eu&gt;"
+ 4096-bit RSA key, ID 77D15A36BD4211B2,
+ created 2016-04-27 (main key ID 79205802880BC9D8).
+ EOF
+ log_debug "expected: ${expected}"
+ log_debug "instr: ${instr}"
+ observed=$(basturldecode "${instr}")
+ log_debug "observed: ${observed}"
+ [[ "$observed" == "$expected" ]] || diff -u <(echo "$observed") <(printf "%s" "$expected")
+}
+
@test "encode into RFC-3986 encoded string" {
local expected