2015-03-07 19:21:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#####
|
|
|
|
#
|
|
|
|
# Author: Kevin Douglas <douglk@gmail.com>
|
|
|
|
#
|
|
|
|
# Simple command line script to restore ascii armor gpg keys from a QR image.
|
|
|
|
# You can use the following commands to import your restored keys:
|
|
|
|
#
|
|
|
|
# gpg --import pgp-public-keys.asc
|
|
|
|
# gpg --import pgp-private-keys.asc
|
|
|
|
#
|
|
|
|
# This script will allow you to convert QR images created with asc2qr.sh
|
|
|
|
# info an ascii armor pgp key.
|
|
|
|
#
|
|
|
|
# This script depends on the following libraries/applications:
|
|
|
|
#
|
|
|
|
# libqrencode (http://fukuchi.org/works/qrencode/)
|
|
|
|
# zbar (http://zbar.sourceforge.net)
|
|
|
|
#
|
|
|
|
# If you need to backup or restore binary keys, see this link to get started:
|
|
|
|
#
|
|
|
|
# https://gist.github.com/joostrijneveld/59ab61faa21910c8434c#file-gpg2qrcodes-sh
|
|
|
|
#
|
|
|
|
#####
|
|
|
|
|
|
|
|
# Name of the output key after decoding
|
|
|
|
output_key_name="mykey.asc"
|
|
|
|
|
|
|
|
# Argument/usage check
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
echo "usage: `basename ${0}` <QR image 1> [QR image 2] [...]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# For each image on the command line, decode it into text
|
2016-07-17 20:41:41 +02:00
|
|
|
chunks=()
|
2015-03-07 19:21:50 +01:00
|
|
|
index=1
|
|
|
|
for img in "$@"; do
|
2017-12-03 05:27:13 +01:00
|
|
|
if [ ! -f "${img}" ]; then
|
|
|
|
echo "image file not found: '${img}'"
|
2015-03-07 19:21:50 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
asc_key="${tmp_file}.${index}"
|
|
|
|
echo "decoding ${img}"
|
2017-12-03 05:27:13 +01:00
|
|
|
chunk=$( zbarimg --raw --set disable --set qrcode.enable "${img}" 2>/dev/null )
|
2015-03-07 19:21:50 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "failed to decode QR image"
|
|
|
|
exit 2
|
|
|
|
fi
|
2016-07-17 20:41:41 +02:00
|
|
|
chunks+=("${chunk}")
|
2015-03-07 19:21:50 +01:00
|
|
|
index=$((index+1))
|
|
|
|
done
|
|
|
|
|
2016-07-17 20:41:41 +02:00
|
|
|
asc_key=""
|
|
|
|
for c in "${chunks[@]}"; do
|
|
|
|
asc_key+="${c}"
|
|
|
|
done
|
2015-03-07 19:21:50 +01:00
|
|
|
|
2016-07-17 20:41:41 +02:00
|
|
|
echo "creating ${output_key_name}"
|
|
|
|
echo "${asc_key}" > ${output_key_name}
|