From ae2b9d47ed7c103de368ef9137baf3f3ac37f6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Fri, 24 Nov 2023 23:01:18 -0300 Subject: [PATCH] Add code integrity verification --- trabalho5/proxy.py | 23 +++++++++++++++++++++++ trabalho5/proxy.py.md5 | 1 + 2 files changed, 24 insertions(+) create mode 100644 trabalho5/proxy.py.md5 diff --git a/trabalho5/proxy.py b/trabalho5/proxy.py index 3520b7c..c31c335 100644 --- a/trabalho5/proxy.py +++ b/trabalho5/proxy.py @@ -152,6 +152,29 @@ def connectionHandle(client_socket, client_address): server_socket.close() client_socket.close() +def verify_code_integrity(): + import hashlib + import sys + + content = None + md5_hash = None + + with open(sys.argv[0], 'rb') as f: + content = f.read() + + with open('proxy.py.md5', 'r') as f: + md5_hash = f.read() + + hash = hashlib.md5(content).hexdigest() + + if hash != md5_hash: + print('ERROR: proxy.py has been tampered with!') + exit(1) + + print('[Code Integrity] proxy.py is verified!') + if __name__ == '__main__': + verify_code_integrity() + ser = Server(host="0.0.0.0", port=8080) ser.start() diff --git a/trabalho5/proxy.py.md5 b/trabalho5/proxy.py.md5 new file mode 100644 index 0000000..d71a27e --- /dev/null +++ b/trabalho5/proxy.py.md5 @@ -0,0 +1 @@ +24d2be62b48be63f31093585f52f7887 \ No newline at end of file