aboutsummaryrefslogtreecommitdiffstats
path: root/pinentry-rofi.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pinentry-rofi.sh')
-rwxr-xr-xpinentry-rofi.sh52
1 files changed, 35 insertions, 17 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh
index 57e6022..7f01b2e 100755
--- a/pinentry-rofi.sh
+++ b/pinentry-rofi.sh
@@ -54,24 +54,32 @@ split_line() {
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
+# Originally from https://github.com/sfinktah/bash/blob/master/rawurlencode.inc.sh
+# There is also more explanation and documentation there
+rawurlencode() {
+ local string="${1}"
+ local strlen=${#string}
+ local encoded=""
+ local pos c o
+
+ for (( pos=0 ; pos<strlen ; pos++ )); do
+ c=${string:$pos:1}
+ case "$c" in
+ [-_.~a-zA-Z0-9] ) o="${c}" ;;
+ * ) printf -v o '%%%02x' "'$c"
+ esac
+ encoded+="${o}"
+ done
+ printf "%s" "${encoded}" # You can either set a return variable (FASTER)
}
-# This is something too clever, doesn’t work in the script
-# from https://stackoverflow.com/a/70560850/164233
-# rfc3986decode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
+rawurldecode() {
+ # This is perhaps a risky gambit, but since all escape characters must be
+ # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which
+ # will decode hex for us
+
+ printf '%b' "${1//%/\\x}"
+}
rofi_cmd="rofi -dmenu -input /dev/null -password"
INSIDE_BATS=${INSIDE_BATS:-0}
@@ -156,7 +164,9 @@ 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[*]}"
- win_mesg="$(rfc3986-decode "${line_arr[*]}")"
+ temp_str="$(rawurldecode "${line_arr[*]}")"
+ log_debug "temp_str: ${temp_str}"
+ win_mesg="$(rawurlencode "${temp_str}")"
assuan_send "OK"
elif [[ "$line" =~ ^SETPROMPT ]] ; then
#SETPROMPT Passphrase:
@@ -164,6 +174,14 @@ while : ; do
log_debug "line_arr: ${line_arr[*]}"
win_prompt="${line_arr[0]}"
assuan_send "OK"
+ elif [[ "$line" =~ ^SETTITLE ]] ; then
+ IFS=" " line_arr=($(split_line "$line"))
+ log_debug "line_arr: ${line_arr[*]}"
+ log_debug "line_arr: ${line_arr[*]}"
+ temp_str="$(rawurldecode "${line_arr[*]}")"
+ log_debug "temp_str: ${temp_str}"
+ win_title="$(rawurlencode "${temp_str}")"
+ assuan_send "OK"
elif [[ "$line" =~ ^GETPIN ]] ; then
passw=None
sys_env="$(systemctl --user show-environment | tr -s " \t\n" " ")"