-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoracle.py
62 lines (47 loc) · 1.55 KB
/
oracle.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
mac_sock = None
vrfy_sock = None
def Oracle_Connect():
import socket
global mac_sock
global vrfy_sock
mac_sock, vrfy_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM), socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
mac_sock.connect(('128.8.130.16', 49102))
vrfy_sock.connect(('128.8.130.16', 49103))
except socket.error as e:
print e
return -1
print "Connected to server successfully."
return 0
def Oracle_Disconnect():
if not mac_sock or not vrfy_sock:
print "[WARNING]: You haven't connected to the server yet."
return -1
mac_sock.close()
vrfy_sock.close()
print "Connection closed successfully."
return 0
# Packet Structure: < mlength(1) || message(mlength) || null-terminator(1) >
def Mac(message, mlength):
if not mac_sock or not vrfy_sock:
print "[WARNING]: You haven't connected to the server yet."
return -1
out = bytearray(message[:])
print("sent: ")
out.insert(0, mlength)
out.append(0)
mac_sock.send(bytearray(out))
tag = mac_sock.recv(16)
return bytearray(tag)
# Packet Structure: < mlength(1) || message(mlength) || tag(16) || null-terminator(1) >
def Vrfy(message, mlength, tag):
if not mac_sock or not vrfy_sock:
print "[WARNING]: You haven't conected to the server yet."
return -1
out = bytearray(message[:])
out.insert(0, mlength)
out += tag
out.append(0)
vrfy_sock.send(bytearray(out))
match = vrfy_sock.recv(2)
return int(match.strip('\0'))