chiark / gitweb /
Keysigning script, from Gergely Nagy via Martin Michlmayr.
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Sun, 1 Sep 2002 17:13:26 +0000 (17:13 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Sun, 1 Sep 2002 17:13:26 +0000 (17:13 +0000)
keyfoo [new file with mode: 0755]

diff --git a/keyfoo b/keyfoo
new file mode 100755 (executable)
index 0000000..bed31cd
--- /dev/null
+++ b/keyfoo
@@ -0,0 +1,122 @@
+#! /bin/sh
+## keyfoo -- do something with a key, and e-mail it to its owner
+## (C) 2001 Gergely Nagy <algernon@debian.org>
+##
+## Released under the terms of the GNU GPL v2.
+##
+## $Id: keyfoo,v 1.6 2001/06/27 14:30:43 mhp Exp $
+## Last updated: <2001/06/27 16:30:27 algernon>
+##
+
+## some globals, initialized as empty
+KF_KEY=
+KF_ADDRESS=
+KF_RECIPIENT=
+KF_KEYID=
+TEMPFILE=
+KF_BODY=
+KF_KEYFILE=
+KF_KEYSERVER=keyring.debian.org
+GPG=gpg
+KF_MAIL_CMD='mutt -H "${KF_BODY}" -a "${KF_KEYFILE}"'
+
+
+
+## this one prints the usage, *wonder*
+keyfoo_usage ()
+{
+    cat <<EOF
+keyfoo -- the key hacker script
+
+Usage: keyfoo [id|email|whatever] <[address to send mail to]> [keyserver]
+EOF
+    exit ${1:-0}
+}
+
+## this one LARTs the user
+keyfoo_not_configured ()
+{
+    cat <<EOF
+keyfoo -- the key hacker script
+
+keyfoo is not configured, no command specified to send the signed key,
+please consult the documentation
+EOF
+
+    exit ${1:-1}
+}
+
+## this one parses the output of gpg --list-key
+keyfoo_parse_gpg ()
+{
+    local kf_tmp
+    kf_tmp=`gpg --list-key ${KF_KEY} | head -n 1`
+    # and now a complicated regexp, I do this separately, so
+    # the line will fit into 80 chars ;]
+    KF_ADDRESS=`echo ${kf_tmp} | sed -e "s,^pub *[^ ]* *[0-9\-]* *,,"`
+    KF_KEYID=`echo ${kf_tmp} | sed -e "s,^pub *[^\/]*\/\([^ ]*\) .*,0x\1,"`
+}
+
+## Here comes the main hackery-wackery
+# first of all, check paramaters
+if test $# -lt 1; then
+    keyfoo_usage 1
+fi
+
+test -e /etc/keyfoorc && . /etc/keyfoorc
+test -e ${HOME}/.keyfoorc && . ${HOME}/.keyfoorc
+
+## Sanity check..
+test -z "${KF_MAIL_CMD}" && keyfoo_not_configured
+
+## determine the tempfile
+if test -x /bin/tempfile; then
+    TEMPFILE=`tempfile`
+else
+    TEMPFILE=${TMPDIR:-/tmp}/keyfoo.$$
+fi
+
+KF_KEY=$1;
+test $# -ge 2 && test x"$2" != x && KF_RECIPIENT="$2"
+KF_RECIPIENT="${KF_RECIPIENT:-$KF_ADDRESS}"
+test $# -ge 3 && test x"$3" != x && KF_KEYSERVER="$3"
+
+KF_PRESIGN="gpg --keyserver ${KF_KEYSERVER} --recv-key ${KF_KEY} ; gpg --list-sigs ${KF_KEY}"
+test -z "${KF_PRESIGN}" || eval "${KF_PRESIGN}"
+
+keyfoo_parse_gpg
+
+# now, we got everything we'll ever need :]
+# time to launch gpg --edit-key
+gpg --sign-key "${KF_KEY}"
+
+KF_SUBJECT="Your signed GPG key (Key ID ${KF_KEYID})"
+
+## now mail the thing
+# first, create a draft mail:
+KF_BODY=${TEMPFILE}
+cat >${KF_BODY} <<EOF
+From: Colin Watson <cjwatson@debian.org>
+To: ${KF_RECIPIENT}
+Subject: ${KF_SUBJECT}
+Fcc: =debian/keysigning
+
+Hi,
+
+Attached to this e-mail is your signed GPG key. I've also uploaded it to
+the keyserver at ${KF_KEYSERVER}.
+
+Cheers,
+EOF
+
+# export the key..
+KF_KEYFILE="${TEMPFILE}.key"
+$GPG --armor --export "${KF_KEY}" >"${KF_KEYFILE}"
+
+# ..then launch the mailer
+eval ${KF_MAIL_CMD}
+
+rm -f "${KF_KEYFILE}" "${KF_BODY}"
+
+$GPG --keyserver "${KF_KEYSERVER}" --send-key "${KF_KEY}"
+