From 0369230fbc74afbc8d289377567ecf9858b1d822 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 10 Aug 2023 12:31:43 +0200 Subject: fix: just do very light decoding of the SETDESC strings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pinentry-rofi.sh | 11 ++++++++--- tests/foundational.bats | 15 +++++++++++++++ 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//\>/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 <mcepl@cepl.eu>" + 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 -- cgit