[Debian-uk] GPG keys and QR codes

Lars Wirzenius liw at liw.fi
Sun Aug 18 15:27:17 BST 2013


On Sun, Aug 18, 2013 at 11:43:05AM +0100, Lars Wirzenius wrote:
> I've attached a quick hack to do what Colin suggests. There may be
> existing tools, but it's Sunday morning and if I can't NIH on a
> Sunday morning, when can I?

Well, that was an utter failure... Colin pointed out that I had
shell script quoting problems of my own.

http://paste.debian.net/26612/ (and attached) should be a fixed
version.

-- 
http://www.cafepress.com/trunktees -- geeky funny T-shirts
http://gtdfh.branchable.com/ -- GTD for hackers
-------------- next part --------------
#!/bin/sh
#
# A small script to produce a PDF with key slips for exchanging PGP
# key information for key signing purposes.
#
# Requires gpg, qrencode, and pandoc (with TeX stuff).
#
# Usage: $0 keyid...

set -eu

temp=$(mktemp)
trap 'rm -f "$temp"' EXIT

for keyid in "$@"
do
    # Save key info to a file.
    keyinfo=$(gpg --fingerprint "$keyid")

    # Generate QR code for key info.
    qrencode "$keyinfo" -o "$keyid.png"

    # Create the Markdown document.
    # Indent the key info by four spaces, so its a code block.
    echo "$keyinfo" | sed 's/^/    /' > "$keyid.mdwn"

    # Include the QR code.
    cat <<EOF >> "$keyid.mdwn"

![Key information as QR]($keyid.png)\\ 


EOF

    # Duplicate it a few times to have many keyslips per page.  With
    # my key, experimentation shows only one slip will fit on one
    # page. That's obviously dependent on how many usernames a key
    # has, etc.
    #
    # Someone who understands pandoc better might tweak margins and
    # font sizes enough that more can be fit on the page. Or someone
    # could do the formatting with another tool, which could allow
    # for a tighter layout.

    for i in $(seq 1)
    do
	cat "$keyid.mdwn"
    done | 
    sponge "$keyid.mdwn"

    # Produce a PDF.
    pandoc -f markdown -o "$keyid.pdf" "$keyid.mdwn"
done


More information about the Debian-uk mailing list