[Assignment-4] moved implementations into proxymodules folder
This commit is contained in:
parent
54fc6894fa
commit
4052d20c49
3 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import os.path as path
|
||||
import json
|
||||
import socket
|
||||
|
||||
class Module:
|
||||
def __init__(self, incoming=False, verbose=False, options=None):
|
||||
# extract the file name from __file__. __file__ is proxymodules/name.py
|
||||
self.name = path.splitext(path.basename(__file__))[0]
|
||||
self.description = 'Simply print the received data as text'
|
||||
self.incoming = incoming # incoming means module is on -im chain
|
||||
self.find = None # if find is not None, this text will be highlighted
|
||||
|
||||
def execute(self, data):
|
||||
print(f"Incoming data: {data}")
|
||||
|
||||
data_json = json.loads(data)
|
||||
if data_json["id"] == 2:
|
||||
data_json["id"] = 3
|
||||
data_json["sender"], data_json["receiver"] = data_json["receiver"], data_json["sender"]
|
||||
elif data_json["id"] == 4:
|
||||
data_json["id"] = 5
|
||||
data_json["sender"], data_json["receiver"] = data_json["receiver"], data_json["sender"]
|
||||
|
||||
data = bytes(json.dumps(data_json).replace(" ", "") + "\n", 'utf-8')
|
||||
print(f"Outgoing data: {data}")
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('This module is not supposed to be executed alone!')
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import os.path as path
|
||||
import json
|
||||
import socket
|
||||
|
||||
class Module:
|
||||
def __init__(self, incoming=False, verbose=False, options=None):
|
||||
# extract the file name from __file__. __file__ is proxymodules/name.py
|
||||
self.name = path.splitext(path.basename(__file__))[0]
|
||||
self.description = 'Simply print the received data as text'
|
||||
self.incoming = incoming # incoming means module is on -im chain
|
||||
self.find = None # if find is not None, this text will be highlighted
|
||||
|
||||
def execute(self, data):
|
||||
print(f"Incoming data: {data}")
|
||||
|
||||
data_json = json.loads(data)
|
||||
if data_json["id"] == 1 and data_json["sender"] == "Bob":
|
||||
# send own Nonce instead of N_B
|
||||
data_json["content"] = '0'
|
||||
elif data_json["id"] == 2 and data_json["sender"] == "Alice":
|
||||
# start a parallel session with bob using Alice's Nonce N_A
|
||||
data_json["id"] = 1
|
||||
data_json["content"] = data_json["content"].split(',')[0]
|
||||
elif data_json["id"] == 2 and data_json["sender"] == "Bob":
|
||||
# Use Bob's signed answer to convince Alice, that we are Bob
|
||||
data_json["id"] = 3
|
||||
elif data_json["id"] == 3 and data_json["sender"] == "Alice":
|
||||
# Drop communication with Bob
|
||||
return bytes()
|
||||
|
||||
data = bytes(json.dumps(data_json).replace(" ", "") + "\n", 'utf-8')
|
||||
print(f"Outgoing data: {data}")
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('This module is not supposed to be executed alone!')
|
||||
Loading…
Add table
Add a link
Reference in a new issue