-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBob.py
64 lines (48 loc) · 1.84 KB
/
Bob.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
__author__ = 'Liran & Rotem '
from Client import Client
from Crypto.PublicKey import RSA
PORT = 8888
HOST = ""
class Bob(Client):
def __init__(self):
super(Bob, self).__init__()
self.alice_password = "123456"
def open_connection(self):
super(Bob, self).open_connection()
print "Binding..."
self.sock.bind((HOST, PORT))
print "Listening..."
self.sock.listen(10)
print "Accepting..."
conn, address_info = self.sock.accept()
print 'Connected with ' + address_info[0] + ':' + str(address_info[1]), "\n===================================="
while True:
data = conn.recv(1024)
if not data:
conn.close()
return
if data == "Hey I'm Alice":
print "Waved To Alice"
self.send_message(conn, "Hey I'm Bob")
elif '-----BEGIN PUBLIC KEY-----' in data:
print "Received Alice's Public Key"
self.rsa.dst_public_key = RSA.importKey(str(data))
elif "QUIT" == data:
self.sock.close()
break
elif data == "GET PUBLIC KEY":
print "Sent Alice My Public Key"
self.send_public_key(conn)
elif self.read_enc_message(data) == "GET PWD":
print "Received GET PWD"
self.send_enc_message(conn, self.alice_password)
elif self.read_enc_message(data) == "SET PWD":
print "Received SET PWD"
self.send_message(conn, "OK")
self.alice_password = self.read_enc_message(conn.recv(1024))
print "Alice's password is: " + self.alice_password
else:
print "Other Data In: ", repr(data)
# ================
client = Bob()
client.open_connection()