#!/bin/bash set -eu # Using inspiration from # https://github.com/plattfot/pinentry-rofis # by (c) 2018-2023 Fredrik Salomonsson posteo net> # which was using inspiration from # https://gist.github.com/sardemff7/759cbf956bea20d382a6128c641d2746 # by (c) 2016 Quentin "Sardem FF7" Glidic # however no line of code was actually taken from either script # (they are in different language anyway). # Copyright (c) 2023 Matěj Cepl cepl eu> # Licensed under the terms of the include license in the file LICENSE. # Some documentation # https://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?(pinentry)Protocol # https://superuser.com/a/1655428 # TODO https://superuser.com/questions/1457167/i-want-to-make-pinentry-use-gui-locally-and-cli-on-ssh # Even better # https://github.com/gpg/libassuan/blob/master/doc/assuan.texi # Although it is called a PIN-Entry, it does allow to enter reasonably # long strings (at least 2048 characters are supported by every # pinentry). # The client using the PIN-Entry has to check for correctness. # Note that all strings are expected to be encoded as UTF-8; # PINENTRY takes care of converting it to the locally used codeset. # To include linefeeds or other special characters, you may # percent-escape them (i.e. a line feed is encoded as `%0A', the # percent sign itself is encoded as `%25'). VERSION="0.0.1" log_debug() { echo "$@" >> /tmp/pinentry-log.txt } assuan_send() { log_debug "assuan_send: $*" echo "$@" } split_line() { rmfirst=${2:-0} log_debug "args: \"$1\", ${rmfirst}" read -ra out_arr <<< "$1" log_debug "out: $(declare -p out_arr)" if [ "$rmfirst" -ne 1 ] ; then unset "out_arr[0]" fi echo "${out_arr[@]}" } # 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" log_debug "rofi failed to run: ${passw} / ${passw_err}" exit $passw_err else if [[ -n ${passw} ]] ; then assuan_send "D ${passw}" fi fi assuan_send "OK" # Close the connection. The server will respond with OK. elif [[ ${line} =~ ^BYE ]] ; then exit 0 else assuan_send "BYE" exit 1 fi done fi # End of $INSIDE_BATS exclusion