From a8e19d5d8057e82cbda2705d755f3d4e1d3da20a Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 1 May 2016 05:25:14 -0400 Subject: remove references to files outside of this repo (commit the files into this repo) --- src/samizdat-password-agent | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 src/samizdat-password-agent (limited to 'src/samizdat-password-agent') diff --git a/src/samizdat-password-agent b/src/samizdat-password-agent new file mode 100755 index 0000000..0fb26c6 --- /dev/null +++ b/src/samizdat-password-agent @@ -0,0 +1,73 @@ +#!/bin/sh +[ "$(id -u)" -gt 0 ] && exec sudo "$0" "$@" + +scan_gnupg_db() +{ + keylist= + mainkeygrip= + uid= + local IFS=' +' + for record in $(gpg2 --with-fingerp --with-fingerp --with-colons -K | cut -d: -f1,5,10); do + : "$record" + case "$record" in + fpr:*) keylist="$keylist ${record##*:}" ;; + sec:*) + if [ -z "$mainkeygrip" ]; then + mainkeygrip="${record#sec:}" + mainkeygrip="${mainkeygrip%%:*}" + fi ;; + uid:*) : ${uid:=${record#uid:*:}} ;; + esac + done +} + +eval $(samizdat-gpg-agent) + +gpg2_test_sign() +{ + GPG_TTY=none gpg2 \ + --ignore-valid-from --ignore-time-conflict --no-tty --batch --clearsign /dev/null 2>&1 +} + +if [ ! "$FORCE_PINENTRY" ] && gpg2_test_sign; then + echo "Made signature with default key successfully. No additional passphrase is needed." >&2 + exit +fi + +scan_gnupg_db # get $uid + +if [ "$uid" ]; then + DESC='Please enter the passphrase to unlock the secret key for the OpenPGP certificate:%0A'"'$uid'." +else + DESC='Please enter the passphrase to unlock the secret key for the OpenPGP certificate.' +fi + +exec samizdat-pinentry \ + --setdesc "$DESC" \ + --ttyname "$(tty)" \ + --socket "${GPG_AGENT_INFO%%:*}" \ + --resocket /root/"${GPG_AGENT_INFO%%:*}" \ + --tell-immediately ' + read secret + for grip in '"$keylist"' -; do + read status || break + printf "< %s\n" "$status" >&2 + [ -z "${status##OK*}" ] || break + [ "$grip" = - ] && break + printf "> PRESET_PASSPHRASE %s -1 %%s\n" "$grip" >&2 + printf "PRESET_PASSPHRASE %s -1 %s\n" "$grip" "$secret" + done + ' \ + --validate ' + exec 7<&0 + gpgoutput=$(gpg2 --batch --no-tty --ignore-valid-from --ignore-time-conflict \ + --passphrase-fd 7 --default-key '"$mainkeygrip"' --clearsign /dev/null) + status=$? + case "$gpgoutput" in + *"Bad passphrase"*) echo "Error: Bad passphrase." ;; + "") [ $status -eq 0 ] || echo "Error: gpg returned $status." ;; + *) printf "gpg returned unexpected error (exit status $status):\n%s\n" "$gpgoutput" ;; + esac + exit $status + ' \ -- cgit v1.2.3