-
Notifications
You must be signed in to change notification settings - Fork 0
/
createauth.py
50 lines (38 loc) · 1.11 KB
/
createauth.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from hashlib import md5
from datetime import datetime
import pyme.core, pyme.constants.sig
import yaml
def getPassphrase(hint, desc, prev_bad):
#print "Passphrase Callback! %s %s %s" % (hint, desc, prev_bad)
#sys.stdout.write("Enter passphrase: ")
#return sys.stdin.readline().strip()
return "123456"
c = pyme.core.Context()
c.set_armor(1)
c.set_passphrase_cb(getPassphrase)
c.op_keylist_start('Voter 2', 0)
votekey = c.op_keylist_next()
if not votekey:
print ("No such key found.")
sys.exit(1)
voterid = votekey.subkeys[0].fpr
topicid = '82529AF0DBF39AAE02BFA77FE00A9A6E8F5630AB/lunch'
authorization = yaml.dump([voterid, topicid])
authblob = pyme.core.Data(authorization)
c.op_keylist_start('Authority', 0)
authkey = c.op_keylist_next()
if not authkey:
print ("No such key found.")
sys.exit(1)
#sign legitimation with authority key
authsig = pyme.core.Data()
c.signers_add(authkey)
c.op_sign(authblob, authsig, pyme.constants.sig.mode.CLEAR)
c.signers_clear()
data = {}
authsig.seek(0,0)
data[topicid] = authsig.read()
print(yaml.dump(data))