Skip to content

Instantly share code, notes, and snippets.

@prauscher
Last active July 11, 2016 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prauscher/4fafa789af25e393bc760d9db2a5d802 to your computer and use it in GitHub Desktop.
Save prauscher/4fafa789af25e393bc760d9db2a5d802 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
own_key = "31E64F8042984BA4E830C574966642860AECFC71"
import sys
from mailbox import mbox
import email
import subprocess
def walk_payload(outer, handle):
if outer.is_multipart():
for inner in outer.get_payload():
walk_payload(inner, handle)
else:
handle(outer)
def gpg_import(payload):
subprocess.run(["gpg", "--import"], input=payload.get_payload(decode=True))
mailbox = mbox(sys.argv[1])
for i, mail in mailbox.items():
b = email.message_from_string(mail.as_string())
for payload in b.get_payload():
decrypt = subprocess.run(["gpg", "--decrypt"], input=payload.as_bytes(), stdout=subprocess.PIPE)
decrypted = decrypt.stdout
if decrypted != "":
inner = email.message_from_bytes(decrypted)
walk_payload(inner, gpg_import)
subprocess.run(["gpg", "--send-keys", own_key])
#!/usr/bin/zsh
OWN='31E64F8042984BA4E830C574966642860AECFC71'
# Find remote key, saving full fingerprint in $FPR
gpg --status-fd 5 --search-keys "$*" 5> /tmp/gpg-sign.$$
FPR=$(grep -F "[GNUPG:] IMPORT_OK 0 " /tmp/gpg-sign.$$ | awk '{ print $4 }')
if [ "x$FPR" = "x" ]; then
echo "No key found"
exit
fi
# Verify Fingerprint
gpg --fingerprint "$FPR"
read r"?Sign key? [y/N] "
if [ "x$r" != "xy" ]; then
exit 0
fi
# Sign
export SIGN_GNUPGHOME=$(mktemp -d)
gpg --export-secret-keys $OWN | gpg --homedir $SIGN_GNUPGHOME --import
gpg --export $FPR | gpg --homedir $SIGN_GNUPGHOME --import
gpg --homedir $SIGN_GNUPGHOME --batch --default-cert-level 3 --quick-sign-key $FPR
# Send UIDs using the users MUA
i=1
gpg --with-colons -k $FPR | grep '^uid:' | while IFS=':' read -A LINE
do
if [[ ${LINE[2]} == 'f' ]]
then
export TMP_GNUPGHOME=$(mktemp -d)
gpg --homedir $SIGN_GNUPGHOME --export $OWN | gpg --homedir $TMP_GNUPGHOME --import
gpg --homedir $SIGN_GNUPGHOME --export $FPR | gpg --homedir $TMP_GNUPGHOME --import
gpg --homedir $TMP_GNUPGHOME --batch --command-fd=0 --status-fd=2 --edit-key $FPR <<-EOT
uid *
uid ${i}
deluid
yes
clean
save
EOT
gpg -a --homedir $TMP_GNUPGHOME --export $FPR >$SIGN_GNUPGHOME/uid$i.asc
xdg-open "mailto:${LINE[10]}?subject=Signature for ${LINE[10]}&body=Find attached the signature for this identity.&attachment=$SIGN_GNUPGHOME/uid$i.asc"
sleep 5
rm -rf $TMP_GNUPGHOME
fi
let i=i+1
done
rm -rf $SIGN_GNUPGHOME
keyserver hkp://pool.sks-keyservers.net
default-key 31E64F8042984BA4E830C574966642860AECFC71
require-cross-certification
ask-cert-level
no-greeting
keyid-format 0xlong
with-fingerprint
charset utf-8
lock-once
photo-viewer eog %i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment