-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyring.py
68 lines (54 loc) · 1.58 KB
/
keyring.py
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
#!/usr/bin/python
#
# key manager
# designed after the Enigmail OpenPGP Key Manager
# http://www.enigmail.net/documentation/keyring.php
#
import bobo
pubkey_algo = {
1: 'RSA',
17: 'DSA'
}
@bobo.query('/keyring.py')
def keyring():
try:
import gpgme
except:
return 'Exception: Python-GPGME library'
# load templates
key_template = open('keyring/key.html').read()
uid_template = open('keyring/uid.html').read()
subkey_template = open('keyring/subkey.html').read()
signature_template = open('keyring/signature.html').read()
# connect to GPG
gpg = gpgme.Context()
keylist = gpg.keylist()
keys = ''
# list keys
for key in keylist:
subkey = key.subkeys[0]
title = ''
certificate = ''
signatures = ''
# get title
if len(key.uids) > 0:
uid = key.uids[0]
title += uid.name
if uid.email.strip() != '':
title += ' <'+uid.email+'>'
# draw certificate
for uid in key.uids:
certificate += uid_template % (uid.name, uid.email)
# for subkey in key.subkeys:
subkey = key.subkeys[0]
certificate += subkey_template % (pubkey_algo[subkey.pubkey_algo] + ', ' + str(subkey.length)+' bit', subkey.keyid, subkey.fpr)
# get all signatures for this certificate
# for signature in key.signatures:
signatures += signature_template % ('Matthias Bock', '[email protected]', '12345678')
# render
keys += key_template % (title, "C72A19AB", certificate, signatures)
# from subprocess import Popen, PIPE
# from shlex import split
# keys = Popen(['whoami'], stdout=PIPE).communicate()[0]
# "root"
return open('keyring/keyring.html').read() % (keys)