Last active
August 29, 2015 14:16
-
-
Save valberg/c5a7979f4341fcb1f718 to your computer and use it in GitHub Desktop.
Sign keys from a keysigning party _more_ easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
def recv_and_sign_key(keyid, email): | |
print(keyid, email) | |
subprocess.call(['gpg2', '--recv-keys', '0x{}'.format(keyid)]) | |
subprocess.call(['gpg2', '--fingerprint', email]) | |
valid = input('Is the above fingerprint correct? ') | |
if valid.lower() in ['y', 'yes']: | |
subprocess.call(['gpg2', '--ask-cert-level', '--sign-key', email]) | |
signed_key = subprocess.check_output([ | |
'gpg2', | |
'-a', | |
'--export', | |
email, | |
], universal_newlines=True) | |
with open('{}.{}.signed.asc'.format(email, keyid), 'w+') as key_file: | |
key_file.write(signed_key) | |
if len(sys.argv) == 1: | |
print('Usage: keysign.py (batch <key file> | <keyid> <email>)') | |
elif sys.argv[1] == 'batch': | |
if not sys.argv[2]: | |
raise Exception('Batch mode require file') | |
with open(sys.argv[2], 'r') as f: | |
for line in f: | |
keyid, email = line.strip().split(' ') | |
recv_and_sign_key(keyid, email) | |
else: | |
if not sys.argv[1]: | |
raise Exception('Missing keyid') | |
if not sys.argv[2]: | |
raise Exception('Missing email') | |
recv_and_sign_key(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment