diff --git a/src/endpoints/web.py b/src/endpoints/web.py index 12cbf7f..21bf7b4 100644 --- a/src/endpoints/web.py +++ b/src/endpoints/web.py @@ -306,3 +306,15 @@ def api_debug_matchmaking(): "len_open_lobbies": len_open_lobbies, "lobby_data": lobby_return_data }) + + +@app.route("/api/sha", methods=["GET"]) +def api_sha(): + try: + # todo generate this on BOOT + # generate SHA256 of PAK and SIG on boot then save it to a file and return here + hashes = hash_handler.get_hash() + return jsonify({"pak": hashes[0], "sig": hashes[1]}) + except Exception as e: + logger.graylog_logger(level="error", handler="web-api-sha", message=e) + return jsonify({"status": "error"}), 500 diff --git a/src/flask_definitions.py b/src/flask_definitions.py index 79ad22c..8083cf1 100644 --- a/src/flask_definitions.py +++ b/src/flask_definitions.py @@ -8,6 +8,7 @@ from logic.mongodb_handler import mongo from logic.webhook_handler import discord_webhook from logic.time_handler import get_lifetime from logic.challenge_handler import get_challenge +from logic.hash_handler import hash_handler import json import os diff --git a/src/logic/hash_handler.py b/src/logic/hash_handler.py new file mode 100644 index 0000000..4eb7687 --- /dev/null +++ b/src/logic/hash_handler.py @@ -0,0 +1,25 @@ +import hashlib +import mmap + +class HashHandler: + def __init__(self): + self.pak = "" + self.sig = "" + self.pak_path = "files/TheExitRebirthBackendAPI-WindowsNoEditor_P.pak" + self.sig_path = "files/TheExitRebirthBackendAPI-WindowsNoEditor_P.sig" + + def setup(self): + self.pak = self.get_256_sum(self.pak_path) + self.sig = self.get_256_sum(self.sig_path) + + def get_256_sum(self, filename): + h = hashlib.sha256() + with open(filename, 'rb') as f: + with mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ) as mm: + h.update(mm) + return h.hexdigest() + + def get_hash(self): + return str(self.pak), str(self.sig) + +hash_handler = HashHandler() \ No newline at end of file diff --git a/src/start_app.py b/src/start_app.py index 5f91a09..2075d61 100644 --- a/src/start_app.py +++ b/src/start_app.py @@ -53,4 +53,5 @@ def keep_alive(): logger.setup_graylog(use_graylog, graylog_server) mongo.setup(mongo_host, mongo_db, mongo_collection) session_manager.setup() +hash_handler.setup() keep_alive()