[fix]: so. many. bugs.

This commit is contained in:
alterNERDtive 2024-06-15 23:50:29 +02:00
parent 169071c7dd
commit a9c95b8838
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

37
gpgtool
View file

@ -2,6 +2,8 @@
_dependencies=("echo" "gpg" "ln" "ls" "mktemp" "mkdir" "mv" "rm" "udisksctl") _dependencies=("echo" "gpg" "ln" "ls" "mktemp" "mkdir" "mv" "rm" "udisksctl")
_tempdir=/tmp/gpgtool.tempdir _tempdir=/tmp/gpgtool.tempdir
stty sane
# Sets up GPGtool. Creates temporary GNUPG home directory, mounts key device if # Sets up GPGtool. Creates temporary GNUPG home directory, mounts key device if
# given, checks for key directory. # given, checks for key directory.
init () { init () {
@ -92,7 +94,7 @@ EOF
echo "GPGtool initialized. Temporary working directory: ${tempdir}, key path ${keypath}." echo "GPGtool initialized. Temporary working directory: ${tempdir}, key path ${keypath}."
echo "" echo ""
echo "Try \`${0} list\` next." echo "Try \`gpgtool list\` next."
} }
# Cleans up GPGtool. Clears the temp directory and closes the mounted volume. # Cleans up GPGtool. Clears the temp directory and closes the mounted volume.
@ -195,6 +197,8 @@ closeall () {
# Creates a new key and stores it in the key path. # Creates a new key and stores it in the key path.
create () { create () {
_checkinit
echo "----- Create master key:" echo "----- Create master key:"
gpg --homedir "${tempdir}/gpghome" --full-generate-key gpg --homedir "${tempdir}/gpghome" --full-generate-key
echo -n "----- Enter the fingerprint of your new key: " echo -n "----- Enter the fingerprint of your new key: "
@ -203,14 +207,15 @@ create () {
gpg --homedir "${tempdir}/gpghome" --edit-key ${id} addkey gpg --homedir "${tempdir}/gpghome" --edit-key ${id} addkey
echo "----- Moving secret key …" echo "----- Moving secret key …"
keygrip=$(gpg --homedir "${tempdir}/gpghome" --with-keygrip --list-key ${id} | grep Keygrip | head -n 1 | awk {'print $3'}) keygrip=$(gpg --homedir "${tempdir}/gpghome" --with-keygrip --list-key ${id} | grep Keygrip | head -n 1 | awk {'print $3'})
mv ${tempdir}/gpghome/private-keys-v1.d/${keygrip}.key ${keypath}/${id}/ mkdir -p "${keypath}/${id}/"
mv "${tempdir}/gpghome/private-keys-v1.d/${keygrip}.key" "${keypath}/${id}/"
echo "----- Exporting …" echo "----- Exporting …"
exdir=${keypath}/${id}/$(date +%F) exdir="${keypath}/${id}/$(date +%F)"
mkdir -p ${exdir} mkdir -p "${exdir}"
gpg --homedir "${tempdir}/gpghome" --armor --export-secret-keys ${id} > ${keypath}/${id}/${id}.private.asc gpg --homedir "${tempdir}/gpghome" --armor --export-secret-keys ${id} > "${keypath}/${id}/${id}.private.asc"
gpg --homedir "${tempdir}/gpghome" --armor --export ${id} > ${keypath}/${id}/${id}.public.asc gpg --homedir "${tempdir}/gpghome" --armor --export ${id} > "${keypath}/${id}/${id}.public.asc"
cp ${keypath}/${id}/${id}.*.asc ${exdir} cp ${keypath}/${id}/${id}.*.asc ${exdir}
mv /home/daniel/.gnupg/openpgp-revocs.d/${id}.rev ${keypath}/${id}/ mv "${tempdir}/gpghome/openpgp-revocs.d/${id}.rev" "${keypath}/${id}/"
echo "----- Restoring secret key for further modification …" echo "----- Restoring secret key for further modification …"
ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/ ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/
echo "----- Remember to import / send & close when done!" echo "----- Remember to import / send & close when done!"
@ -218,7 +223,10 @@ create () {
# Extends an open key. # Extends an open key.
extend () { extend () {
_checkinit
id=${1} id=${1}
echo "----- Step 1: change expiry date; end with \`save\`:" echo "----- Step 1: change expiry date; end with \`save\`:"
gpg --homedir "${tempdir}/gpghome" --edit-key ${id} expire gpg --homedir "${tempdir}/gpghome" --edit-key ${id} expire
echo "----- Step 2: add new encryption key; end with \`save\`:" echo "----- Step 2: add new encryption key; end with \`save\`:"
@ -229,8 +237,8 @@ extend () {
keygrip=$(gpg --homedir "${tempdir}/gpghome" --with-keygrip --list-key ${id} | grep Keygrip | head -n 1 | awk {'print $3'}) keygrip=$(gpg --homedir "${tempdir}/gpghome" --with-keygrip --list-key ${id} | grep Keygrip | head -n 1 | awk {'print $3'})
rm ${tempdir}/gpghome/private-keys-v1.d/${keygrip}.key rm ${tempdir}/gpghome/private-keys-v1.d/${keygrip}.key
echo "----- Exporting …" echo "----- Exporting …"
exdir=$(dirname $(ls ${keypath}/${id}))/$(date +%F) exdir="${keypath}/${id}/$(date +%F)"
mkdir $exdir mkdir -p $exdir
gpg --homedir "${tempdir}/gpghome" --armor --export-secret-keys ${id} > ${keypath}/${id}/${id}.private.asc gpg --homedir "${tempdir}/gpghome" --armor --export-secret-keys ${id} > ${keypath}/${id}/${id}.private.asc
gpg --homedir "${tempdir}/gpghome" --armor --export ${id} > ${keypath}/${id}/${id}.public.asc gpg --homedir "${tempdir}/gpghome" --armor --export ${id} > ${keypath}/${id}/${id}.public.asc
cp ${keypath}/${id}/${id}.*.asc ${exdir} cp ${keypath}/${id}/${id}.*.asc ${exdir}
@ -241,9 +249,12 @@ extend () {
# Sends keys to key servers. # Sends keys to key servers.
send () { send () {
zparseopts -D -E -- -keyserver=servers: _checkinit
[[ -z "${servers}" ]] && servers=GPGTOOLKEYSERVERS # FIXXME: bugged?
# zparseopts -D -E -- -keyserver=servers:
[[ -z "${servers}" ]] && servers=( $GPGTOOLKEYSERVERS )
[[ -z "${servers}" ]] && echo "No key servers given, aborting …" && exit 1 [[ -z "${servers}" ]] && echo "No key servers given, aborting …" && exit 1
@ -260,10 +271,12 @@ send () {
import () { import () {
_checkinit _checkinit
id=$1
local keyfile=${keypath}/${id}/${id}.private.asc local keyfile=${keypath}/${id}/${id}.private.asc
[[ ! -f "${keyfile}" ]] && echo "Cannot find secret key ${keyfile}, aborting …" && exit 1 [[ ! -f "${keyfile}" ]] && echo "Cannot find secret key ${keyfile}, aborting …" && exit 1
"Importing key into your regular GnuPG keying …" echo "Importing key into your regular GnuPG keyring …"
gpg --import-options keep-ownertrust --import "${keyfile}" gpg --import-options keep-ownertrust --import "${keyfile}"
} }