-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
80 lines (67 loc) · 2.6 KB
/
Client.py
File metadata and controls
80 lines (67 loc) · 2.6 KB
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
75
76
77
78
79
import math
import time
import random
import sympy
import warnings
from random import randint, seed
import sys
from ecpy.curves import Curve,Point
from Crypto.Hash import SHA3_256, HMAC, SHA256
import requests
from Crypto.Cipher import AES
from Crypto import Random
from Crypto.Util.Padding import pad
from Crypto.Util.Padding import unpad
import random
import re
import json
API_URL = 'http://harpoon1.sabanciuniv.edu:9999'
stuID = #Enter Your ID
#Server's Identitiy public key
IKey_Ser = # Use the values in the project description document to form the server's IK as a point on the EC. Note that the values should be in decimal.
def IKRegReq(h,s,x,y):
mes = {'ID':stuID, 'H': h, 'S': s, 'IKPUB.X': x, 'IKPUB.Y': y}
print("Sending message is: ", mes)
response = requests.put('{}/{}'.format(API_URL, "IKRegReq"), json = mes)
print(response.json())
def IKRegVerify(code):
mes = {'ID':stuID, 'CODE': code}
print("Sending message is: ", mes)
response = requests.put('{}/{}'.format(API_URL, "IKRegVerif"), json = mes)
if((response.ok) == False): raise Exception(response.json())
else:
print(response.json())
f = open('Identity_Key.txt', 'w')
f.write("IK.Prv: "+str(IKey_Pr)+"\n"+"IK.Pub.x: "+str(IKey_Pub.x)+"\n"+"IK.Pub.y: "+str(IKey_Pub.y))
f.close()
def SPKReg(h,s,x,y):
mes = {'ID':stuID, 'H': h, 'S': s, 'SPKPUB.X': x, 'SPKPUB.Y': y}
print("Sending message is: ", mes)
response = requests.put('{}/{}'.format(API_URL, "SPKReg"), json = mes)
print(response.json())
def OTKReg(keyID,x,y,hmac):
mes = {'ID':stuID, 'KEYID': keyID, 'OTKI.X': x, 'OTKI.Y': y, 'HMACI': hmac}
print("Sending message is: ", mes)
response = requests.put('{}/{}'.format(API_URL, "OTKReg"), json = mes)
print(response.json())
if((response.ok) == False): return False
else: return True
def ResetIK(rcode):
mes = {'ID':stuID, 'RCODE': rcode}
print("Sending message is: ", mes)
response = requests.delete('{}/{}'.format(API_URL, "ResetIK"), json = mes)
print(response.json())
if((response.ok) == False): return False
else: return True
def ResetSPK(h,s):
mes = {'ID':stuID, 'H': h, 'S': s}
print("Sending message is: ", mes)
response = requests.delete('{}/{}'.format(API_URL, "ResetSPK"), json = mes)
print(response.json())
if((response.ok) == False): return False
else: return True
def ResetOTK(h,s):
mes = {'ID':stuID, 'H': h, 'S': s}
print("Sending message is: ", mes)
response = requests.delete('{}/{}'.format(API_URL, "ResetOTK"), json = mes)
if((response.ok) == False): print(response.json())