aboutsummaryrefslogtreecommitdiffstats
path: root/pinentry-rofi.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-07 15:44:33 +0200
committerMatěj Cepl <mcepl@cepl.eu>2023-08-11 11:59:10 +0200
commit130e1d1c8ae3b951e1f499b6d428062c050c7aa9 (patch)
tree90432f3c6269698c9b6bda6196fec06edc7915ce /pinentry-rofi.sh
parentdd3d3357cdeb05d83210b0f51d9fe4bffbc3f387 (diff)
downloadpinentry-rofi-130e1d1c8ae3b951e1f499b6d428062c050c7aa9.tar.gz
fix: decode RFC-3986 encoded strings in SETDESC
Diffstat (limited to 'pinentry-rofi.sh')
-rwxr-xr-xpinentry-rofi.sh32
1 files changed, 25 insertions, 7 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh
index 5a32d65..b6904be 100755
--- a/pinentry-rofi.sh
+++ b/pinentry-rofi.sh
@@ -48,16 +48,35 @@ split_line() {
log_debug "args: \"$1\", ${rmfirst}"
read -ra out_arr <<< "$1"
log_debug "out: $(declare -p out_arr)"
- if [ $rmfirst -ne 1 ] ; then
+ if [ "$rmfirst" -ne 1 ] ; then
unset "out_arr[0]"
fi
echo "${out_arr[@]}"
}
+# Originally from https://www.baeldung.com/linux/decoding-encoded-urls
+rfc3986-decode() {
+ strg="${*}"
+ printf '%s' "${strg%%[%+]*}"
+ j="${strg#"${strg%%[%+]*}"}"
+ strg="${j#?}"
+ case "${j}" in "%"* )
+ printf '%b' "\\0$(printf '%o' "0x${strg%"${strg#??}"}")"
+ strg="${strg#??}"
+ ;; "+"* ) printf ' '
+ ;; * ) return
+ esac
+ if [ -n "${strg}" ] ; then rfc3986-decode "${strg}"; fi
+}
+
+# This is something too clever, doesn’t work in the script
+# from https://stackoverflow.com/a/70560850/164233
+# rfc3986decode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
+
rofi_cmd="rofi -dmenu -input /dev/null -password"
INSIDE_BATS=${INSIDE_BATS:-0}
-if [ $INSIDE_BATS -ne 1 ] ; then
+if [ "$INSIDE_BATS" -ne 1 ] ; then
assuan_send "OK Please go ahead"
@@ -135,10 +154,9 @@ while : ; do
assuan_send "OK"
elif [[ "$line" =~ ^SETDESC ]] ; then
#SETDESC Please enter the passphrase for the ssh key%0A ke:yf:in:ge:rp:ri:nt
- # rofi << "-mesg" << $1.gsub("<", "&lt;").gsub(/%([0-9A-Fa-f]{2})/) { $1.to_i(16).chr }
IFS=" " line_arr=("$(split_line "$line")")
log_debug "line_arr: ${line_arr[*]}"
- win_mesg="${line_arr[*]}"
+ win_mesg="$(rfc3986-decode "${line_arr[*]}")"
assuan_send "OK"
elif [[ "$line" =~ ^SETPROMPT ]] ; then
#SETPROMPT Passphrase:
@@ -149,8 +167,8 @@ while : ; do
elif [[ "$line" =~ ^GETPIN ]] ; then
passw=None
sys_env="$(systemctl --user show-environment | tr -s " \t\n" " ")"
- IFS=" " line_arr=("$(split_line "$line" 1)")
- log_debug "line_arr: ${line_arr[*]}"
+ IFS=" " sys_env_arr=("$(split_line "$sys_env" 1)")
+ log_debug "sys_env_arr: ${sys_env_arr[*]}"
for env_line in "${sys_env_arr[@]}" ; do
log_debug "env_line=${env_line}"
# GPIN_VALID=re.compile(r)
@@ -169,7 +187,7 @@ while : ; do
passw_err=$?
if [[ ${passw_err} -ne 0 ]] ; then
# assuan_send "ERR 83886179 Operation cancelled <rofi>"
- log_debug "rofi failed to run: ${passw} (${passw_err})"
+ log_debug "rofi failed to run: ${passw} / ${passw_err}"
exit $passw_err
else
if [[ -n ${passw} ]] ; then