-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqkserver.py
74 lines (51 loc) · 1.76 KB
/
qkserver.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
68
69
70
71
72
73
74
#!/usr/bin/python3
from flask import Flask, request
from flask_restful import Resource, Api
from mim import generateQK
from json import dumps
import base64
app = Flask(__name__)
api = Api(app)
map = {}
class QKServerKeyFactory(Resource):
def get(self):
print(map)
return dumps(map)
def post(self):
print(request.json)
#sender = request.json['sender']
#receiver = request.json['receiver']
try:
qkeyarray = generateQK(256)
alice_key = qkeyarray.get('A')
bob_key = qkeyarray.get('B')
print(alice_key)
print(bob_key)
qkey = int(alice_key, 2).to_bytes((len(alice_key) + 7) // 8, byteorder='little')
qkeyb = int(bob_key, 2).to_bytes((len(bob_key) + 7) // 8, byteorder='little')
print(qkey)
print(qkeyb)
b64qkey = base64.encodebytes(qkey).decode('utf-8')
b64qkeyb = base64.encodebytes(qkeyb).decode('utf-8')
print(b64qkey)
print(b64qkeyb)
map['A']={"B":b64qkey}
map['B']={"A":b64qkeyb}
print(map)
return {'status': 'success'}
except:
return {'status':'failed'}
class QKServerUserKeyService(Resource):
def get(self, user_id):
return {'status': 'success'}
def post(self, user_id):
print(request.json)
dicc = map.get(user_id)
print(dicc)
receiver = request.json['receiver']
key = dicc.get(receiver)
return {'status': key}
api.add_resource(QKServerKeyFactory, '/qkfactory')
api.add_resource(QKServerUserKeyService, '/qkuser/<user_id>')
if __name__ == '__main__':
app.run()