This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathascii_sign
executable file
·73 lines (57 loc) · 2.8 KB
/
ascii_sign
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
import sys, subprocess, io
cwd = sys.path[0]
sys.path.append(cwd+'/lib/python-gnupg-0.3.3')
import gnupg
class TrollWoT_ASCIISign:
def __init__(self, filename, target_keyid, homedir):
self.target_keyid = keyid
self.homedir = homedir
self.keyserver_url = "http://pool.sks-keyservers.net:11371/pks/lookup?op=vindex&search=0x{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 pool.sks-keyservers.net'.format(keyid)
self.recv_key(self.target_keyid)
# generate new keys
self.gen_keys_and_sign(filename)
# 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?"
sys.exit();
for userid in open(filename, 'r').read().strip().split('\n'):
fingerprint = self.gen_key(userid)
fingerprints_to_sign.append(fingerprint)
self.fingerprints.append(fingerprint)
for fingerprint in fingerprints_to_sign:
self.sign_key(fingerprint)
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 pool.sks-keyservers.net'.format(keyid)
subprocess.Popen(['gpg', '--homedir', self.gpg.gnupghome, '--keyserver', 'pool.sks-keyservers.net', '--recv-keys', keyid]).wait()
if __name__ == '__main__':
# arguments
if len(sys.argv) != 3:
print 'Usage: {0} [ascii_art.txt] [keyid]'.format(sys.argv[0])
sys.exit()
filename = sys.argv[1]
keyid = sys.argv[2]
ascii_sign = TrollWoT_ASCIISign(filename, keyid, homedir=cwd+'/homedir_ascii_sign')