Add code integrity verification

This commit is contained in:
José Henrique 2023-11-24 23:01:18 -03:00
parent 213f23977f
commit ae2b9d47ed
2 changed files with 24 additions and 0 deletions

View File

@ -152,6 +152,29 @@ def connectionHandle(client_socket, client_address):
server_socket.close() server_socket.close()
client_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__': if __name__ == '__main__':
verify_code_integrity()
ser = Server(host="0.0.0.0", port=8080) ser = Server(host="0.0.0.0", port=8080)
ser.start() ser.start()

1
trabalho5/proxy.py.md5 Normal file
View File

@ -0,0 +1 @@
24d2be62b48be63f31093585f52f7887