You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.8 KiB

#!/usr/bin/env python
import sys, subprocess, io
cwd = sys.path[0]
import gnupg
class TrollWoT_ASCIISign:
def __init__(self, filename, target_keyid, homedir):
self.target_keyid = keyid
self.homedir = homedir
self.keyserver_url = "{0}".format(keyid)
self.fingerprints = [self.target_keyid]
self.gpg = gnupg.GPG(gnupghome=homedir, gpgbinary=cwd+'/lib/gnupg/g10/gpg', verbose=False)
# download target key
print 'Downloading key {0} from'.format(keyid)
# generate new keys
# show fingerprints with gpg
subprocess.Popen(['gpg', '--homedir', self.gpg.gnupghome, '--list-sigs', self.target_keyid]).wait()
def gen_keys_and_sign(self, filename):
fingerprints_to_sign = []
userids = open(filename, 'r').read().strip().split('\n')
if len(userids) > 50:
print "This ASCII art is more than 50 lines. I think that's a bit much, don't you?"
for userid in open(filename, 'r').read().strip().split('\n'):
fingerprint = self.gen_key(userid)
for fingerprint in fingerprints_to_sign:
def gen_key(self, userid):
print 'Generating key with userid: {0}'.format(userid)
input = self.gpg.gen_key_input(name_real = userid, key_length = 4096)
input_lines = input.split('\n')
input = ''
for line in input_lines:
if 'Name-Comment' not in line and 'Name-Email' not in line:
input += line+'\n'
key = self.gpg.gen_key(input)
return key.fingerprint
def sign_key(self, signing_fingerprint):
keyid = signing_fingerprint[-8:]
print 'Signing key {0} with key {1}'.format(self.target_keyid, keyid)
subprocess.Popen(['gpg', '--homedir', self.gpg.gnupghome, '--yes', '--default-key', keyid, '--sign-key', self.target_keyid]).wait()
def recv_key(self, fingerprint):
keyid = fingerprint[-8:]
print 'Receiving key {0} from'.format(keyid)
subprocess.Popen(['gpg', '--homedir', self.gpg.gnupghome, '--keyserver', '', '--recv-keys', keyid]).wait()
if __name__ == '__main__':
# arguments
if len(sys.argv) != 3:
print 'Usage: {0} [ascii_art.txt] [keyid]'.format(sys.argv[0])
filename = sys.argv[1]
keyid = sys.argv[2]
ascii_sign = TrollWoT_ASCIISign(filename, keyid, homedir=cwd+'/homedir_ascii_sign')