Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Server file hash integrity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
knot126 committed Jan 16, 2024
1 parent eb7dc29 commit 6afe7df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion addon/shatter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import segment_import
import room_export
import extra_tools
import quick_test
import updater
import autogen
import util
Expand Down
11 changes: 10 additions & 1 deletion addon/shatter/server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ def cb_builtin():
Run the builtin level server
"""

quick_test = util.load_module(str(Path(__file__).parent) + "/quick_test.py")
script_path = str(Path(__file__).parent) + "/quick_test.py"

if (not util.check_file_hash(script_path, "c140a45b9f6574f07693442f475d84a6c82ac56dc5124124b6004a1ecd764a74")):
print("Warning: quick_test.py file hash does not match expected hash! This may become an error in the future.")

quick_test = util.load_module(script_path)
quick_test.runServer()

def cb_yorshex(asset_dir, level):
Expand All @@ -84,6 +89,10 @@ def cb_yorshex(asset_dir, level):
python_path = os.path.realpath(sys.executable)
script_path = str(Path(__file__).parent) + "/asset_server.py"

# Check file hash
if (not util.check_file_hash(script_path, "515b62fd5f829f6a57405b223b53191d3c55c9f0e52cb64a555ba4b0288466f1")):
print("Warning: asset_server.py file hash does not match expected hash! This may become an error in the future.")

# Open the process
proc = Popen([python_path, script_path, asset_dir, "-l", level, "-o"])

Expand Down
7 changes: 7 additions & 0 deletions addon/shatter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ def set_file_gzip(path, data):
f.write(data.encode('utf-8'))
f.close()

def check_file_hash(path, filehash, length = 32):
"""
Check the hash of the file against "h". True if equal, False otherwise
"""

return shake256(get_file(path), length) == filehash

def prepare_folders(path):
"""
Make the folders for the file of the given name
Expand Down

0 comments on commit 6afe7df

Please sign in to comment.