From c2fe2b6d6066ebd8f18c9e3af461188b98db59e6 Mon Sep 17 00:00:00 2001 From: technofab Date: Sat, 19 Jul 2025 19:06:52 +0200 Subject: [PATCH] chore: initial commit --- README.md | 11 ++++++++++ pinentry-tmux.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 README.md create mode 100755 pinentry-tmux.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..8eed10d --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# GPG Pinentry inside TMUX + +See it in action: +[![asciicast](https://asciinema.org/a/UE29nOhgOVwjESVIoj1ftFqWt.svg)](https://asciinema.org/a/UE29nOhgOVwjESVIoj1ftFqWt) + +## Installation + +1. add your fallback pinentry to `pinentry-tmux.sh` +2. put the shell script in your path, eg. `~/.local/bin/pinentry-tmux` (without `.sh`) +3. configure gpg to use `pinentry-tmux` for pinentry + diff --git a/pinentry-tmux.sh b/pinentry-tmux.sh new file mode 100755 index 0000000..b8d6192 --- /dev/null +++ b/pinentry-tmux.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -eo pipefail + +# fallback if empty +if [[ -z "$PINENTRY_USER_DATA" ]]; then + # TODO: add your fallback pinentry here + exec "$@" +fi + +if [[ "$PINENTRY_USER_DATA" != "tmux" ]]; then + echo "Unsupported pinentry type in PINENTRY_USER_DATA" + exit 1 +fi + +DESCFILE=$(mktemp) + +cleanup() { + rm -f "$DESCFILE" +} +trap cleanup EXIT + +prompt="PIN:" + +echo "OK Please go ahead" +while read cmd rest; do + case "$cmd" in + SETDESC) + echo "$(tput setaf 8)$(echo "$rest" | sed -e 's/%0A/\n/g' -e 's/%22/"/g')$(tput sgr0)" > $DESCFILE + echo "OK" + ;; + SETPROMPT) + prompt="$(tput smul)$rest$(tput sgr0)" + echo "OK" + ;; + GETPIN) + PIPE=$(mktemp -u) + mkfifo "$PIPE" + chmod 600 "$PIPE" + + tmux display-popup -w 70 -h 7 -E "bash -c 'cat $DESCFILE; echo -n \"$prompt \"; read -s pw; echo \$pw > $PIPE'" & + PIN=$(<"$PIPE") + rm -f "$PIPE" + echo "D $PIN" + echo "OK" + ;; + BYE) + echo "OK" + exit 0 + ;; + *) + echo "OK" + ;; + esac +done +