#!/bin/sh ENABLE_LOGGING="TRUE" logger() { if [ "$ENABLE_LOGGING" == "TRUE" ]; then /usr/bin/logger -t "${0} [$]" "$@"; fi } # Decode URL-encoded characters (%0A = newline, %20 = space, etc.) decode() { printf '%b' "$(echo "$1" | sed 's/%\([0-9A-Fa-f][0-9A-Fa-f]\)/\\x\1/g')" } # Base command and misc variables DESC="" PROMPT="" COUNTFILE="/tmp/pinentry-fuzzel-count-$$" # Check if this is a repeat prompt (within 5 seconds of last) LASTFILE="/tmp/pinentry-fuzzel-last" NOW=$(date +%s) if [ -f "$LASTFILE" ]; then LAST=$(cat "$LASTFILE") if [ $((NOW - LAST)) -lt 5 ]; then REPEAT=1 else REPEAT=0 fi else REPEAT=0 fi echo "$NOW" > "$LASTFILE" echo "OK Please go ahead" while read cmd rest; do logger "RAW=< ${cmd} ${rest} >" logger "cmd=<${cmd}> rest=<${rest}>" case $cmd in GETINFO) case "$rest" in flavor) echo "D fuzzel" echo "OK" ;; version) echo "D 0.1" echo "OK" ;; ttyinfo) echo "D - - -" echo "OK" ;; pid) echo "D $$" echo "OK" ;; esac ;; SETDESC) DESC=$(decode "$rest") echo "OK" ;; SETERROR) logger "ERROR $rest" # Silently acknowledge errors (e.g., empty passphrase on escape) echo "OK" ;; SETPROMPT) PROMPT=$(decode "$rest") # Remove trailing colon if present (we add our own) PROMPT="${PROMPT%:}" echo "OK" ;; GETPIN | getpin) if [ "$REPEAT" -eq 0 ]; then LABEL="password: " else LABEL="reenter: " fi PASS=$(fuzzel --prompt "$LABEL" --width 25 --lines 0 --cache /dev/null --password --dmenu) if [ -z "$PASS" ]; then # User cancelled - return error to GPG rm -f "$LASTFILE" echo "ERR 83886179 Operation cancelled" else echo "D $PASS" echo "OK" fi ;; BYE|bye) echo "OK closing connection" logger "EXITING" exit 0 ;; *) echo "OK" ;; esac done