2015-03-07 19:21:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#####
|
|
|
|
#
|
|
|
|
# Author: Kevin Douglas <douglk@gmail.com>
|
|
|
|
#
|
|
|
|
# Simple command line script to backup ascii armor gpg keys to paper. You can
|
|
|
|
# use the following commands to export your keys in ascii armor format:
|
|
|
|
#
|
|
|
|
# gpg --armor --export > pgp-public-keys.asc
|
|
|
|
# gpg --armor --export-secret-keys > pgp-private-keys.asc
|
|
|
|
# gpg --armor --gen-revoke [your key ID] > pgp-revocation.asc
|
|
|
|
#
|
|
|
|
# These can then be used to restore your keys if necessary.
|
|
|
|
#
|
|
|
|
# This script will allow you to convert the above ascii armor keys into a
|
|
|
|
# printable QR code for long-term archival.
|
|
|
|
#
|
|
|
|
# This script depends on the following libraries/applications:
|
|
|
|
#
|
|
|
|
# libqrencode (http://fukuchi.org/works/qrencode/)
|
|
|
|
#
|
|
|
|
# If you need to backup or restore binary keys, see this link to get started:
|
|
|
|
#
|
|
|
|
# https://gist.github.com/joostrijneveld/59ab61faa21910c8434c#file-gpg2qrcodes-sh
|
|
|
|
#
|
|
|
|
#####
|
|
|
|
|
|
|
|
# Maximum chuck size to send to the QR encoder. QR version 40 supports
|
|
|
|
# 2,953 bytes of storage.
|
2016-07-17 20:41:41 +02:00
|
|
|
max_qr_bytes=2800
|
2015-03-07 19:21:50 +01:00
|
|
|
|
|
|
|
# Prefix string for the PNG images that are produced
|
|
|
|
image_prefix="QR"
|
|
|
|
|
|
|
|
# Argument/usage check
|
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
echo "usage: `basename ${0}` <ascii armor key file>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
asc_key=${1}
|
|
|
|
if [ ! -f ${asc_key} ]; then
|
|
|
|
echo "key file not found: ${asc_key}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-07-17 20:41:41 +02:00
|
|
|
## Split the key file into usable chunks that the QR encoder can consume
|
|
|
|
chunks=()
|
|
|
|
while true; do
|
2016-07-27 04:49:29 +02:00
|
|
|
IFS= read -r -d'\0' -n ${max_qr_bytes} s
|
2016-07-17 20:41:41 +02:00
|
|
|
if [ ${#s} -gt 0 ]; then
|
|
|
|
chunks+=("${s}")
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
2016-07-26 14:21:04 +02:00
|
|
|
done < ${asc_key}
|
2015-03-07 19:21:50 +01:00
|
|
|
|
2016-07-17 20:41:41 +02:00
|
|
|
## For each chunk, encode it into a qr image
|
2015-03-07 19:21:50 +01:00
|
|
|
index=1
|
2016-07-17 20:41:41 +02:00
|
|
|
for c in "${chunks[@]}"; do
|
|
|
|
img="${image_prefix}${index}.png"
|
|
|
|
echo "generating ${img}"
|
|
|
|
echo -n "${c}" | qrencode -o ${img}
|
2015-03-07 19:21:50 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "failed to encode image"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
index=$((index+1))
|
|
|
|
done
|