async def join(): async with websockets.connect('ws://localhost:8765') as websocket: print("> Ask to join") # Prepare parameters u = dict(Y) # Commit out = {'cmd': 'join', 'name': "Adam"} out.update(join_0(u)) await websocket.send(jencode(out)) # Await and response data = await websocket.recv() frame = jdecode(data) if frame["status"] != "OK": print("JOIN ERROR") return u.update(frame) out = join_2(u) await websocket.send(jencode(out)) # Await data = await websocket.recv() if frame["status"] != "OK": print("JOIN ERROR") return frame = jdecode(data) u.update(frame) if join_4(u): global Key Key = u
async def handler(websocket, path): data = await websocket.recv() frame = jdecode(data) print("< {}".format(frame['cmd'])) import pdb pdb.set_trace() if frame['cmd'] == 'get_pk': print("> Public Key") out = dict(Y) await websocket.send(jencode(out)) return if frame['cmd'] == 'open': print("> OPEN by", frame['name']) gm = dict(Y) gm.update(S) gm.update(frame) out = open(gm, gm['msg'], gm['sign']) await websocket.send(jencode(out)) if frame['cmd'] == 'join': # prepare values try: print("> JOIN by", frame['name']) gm = dict(Y) gm.update(S) gm.update(frame) # Answer to commit out = join_1(gm) await websocket.send(jencode(out)) # Await response data = await websocket.recv() frame = jdecode(data) gm.update(frame) # Generate key out = join_3(gm) await websocket.send(jencode(out)) # Add user to list Users[gm['name']] = gm print(gm['name'], "successfully added") print("{} users on the list".format(len(Users))) except Exception: out = {"status": "ERROR"} print("JOIN ERROR!!!") await websocket.send(jencode(out)) return
async def get_pk(): async with websockets.connect('ws://localhost:8765') as websocket: print("> Ask for Public Key") # Construct and send requrest frame frame = {"cmd": "get_pk"} await websocket.send(jencode(frame)) # Await response data = await websocket.recv() frame = jdecode(data) global Y Y = frame
def test_sign(): Y, S = setup() u = jdecode(jencode(Y)) gm = jdecode(jencode(Y)) gm.update(jdecode(jencode(S))) gm.update(jdecode(jencode(join_0(u)))) u.update(jdecode(jencode(join_1(gm)))) gm.update(jdecode(jencode(join_2(u)))) u.update(jdecode(jencode(join_3(gm)))) join_4(u) s = jdecode(jencode(sign(u, "Awsome message"))) verify(u, "Awsome message", s) open(gm, "Awsome message", s)
async def open_msg(): async with websockets.connect('ws://localhost:8765') as websocket: print("> SIGN") msg = "Random message to sign" u = dict(Key) u.update(Y) signature = sign(u, msg) # Commit out = {'cmd': 'open', 'name': "Adam", "msg": msg, "sign": signature} await websocket.send(jencode(out)) # Await and response data = await websocket.recv() frame = jdecode(data) print(frame)
#!/usr/bin/env python3 from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair from anon_creds import step_7 as challange from anon_creds import step_9 as verify from utils import jencode, jdecode if __name__ == "__main__": # Read {g, x, y, z, X, Y, Z} v = jdecode(input("pk: ")) # Await commit v.update(jdecode(input("commit: "))) # Create challange print(jencode(challange(v))) # Await answer to challange v.update(jdecode(input("anwser: "))) # Issue credentials print(verify(v))
#!/usr/bin/env python3 from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair from anon_creds import step_1 as challange from anon_creds import step_3 as issue from utils import jencode, jdecode if __name__ == "__main__": # Read {g, x, y, z, X, Y, Z} i = jdecode(input("sk: ")) # Await commit i.update(jdecode(input("commit: "))) # Create challange print(jencode(challange(i))) # Await answer to challange i.update(jdecode(input("anwser: "))) # Issue credentials print(jencode(issue(i)))
from utils import b64encode, jencode import json import base64 if __name__ == "__main__": G = PairingGroup('SS512') g = input("g: ") g = G.random(G1) if g == "" else G.deserialize(base64.b64decode(g)) skey = G.random(ZR) pkey = g**skey m = G.random(ZR) pk = {"g": g, "pk": pkey} sk = {"g": g, "pk": pkey, "sk": skey} mg = {"m": m} print("Generated credentials: {}".format( json.dumps(b64encode(sk), indent=4))) with open("cred.pk", "w+") as f: f.write(jencode(pk)) with open("cred.sk", "w+") as f: f.write(jencode(sk)) with open("msg.mg", "w+") as f: f.write(jencode(mg))
#!/usr/bin/env python3 from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair from anon_creds import step_0 as commit from anon_creds import step_2 as answer from anon_creds import step_4 as store from utils import jencode, jdecode if __name__ == "__main__": # Read {g, X, Y, Z, m} u = jdecode(input("pk: ")) u.update(jdecode(input("m: "))) # Commit print(jencode(commit(u))) # Await challange u.update(jdecode(input("c: "))) # Answer challange print(jencode(answer(u))) # Await credentials u.update(jdecode(input("store: "))) # Store credentials print(jencode(store(u)))
#!/usr/bin/env python3 from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair from schnorr import step_0 as commit from schnorr import step_2 as answer from utils import jencode, jdecode if __name__ == "__main__": # Read {g, sk [,pk]} p = jdecode(input("priv: ")) # Commit X print(jencode(commit(p))) # Await challange x p.update(jdecode(input("c: "))) # Answer challange with p print(jencode(answer(p)))
#!/usr/bin/env python3 from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair from schnorr import step_0 as sign from utils import jencode, jdecode if __name__ == "__main__": # Read {g, sk [,pk]} s = jdecode(input("priv: ")) s.update(jdecode(input("m: "))) # Sign message m print(jencode(sign(s)))