fix: Hashing algorithm wasn't returning a consistent hash
All checks were successful
Build Docker / Build Image (push) Successful in 27s
All checks were successful
Build Docker / Build Image (push) Successful in 27s
This commit is contained in:
parent
0c0125b40c
commit
dc240bb1a7
86
plugin.py
86
plugin.py
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import importlib
|
import importlib
|
||||||
|
import sys
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -26,13 +28,11 @@ def listPlugins():
|
|||||||
|
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
# Hash the plugin file
|
# Hash the plugin file
|
||||||
with open(f"plugins/{plugin['link']}.py", "r") as f:
|
pluginHash = hashPlugin(plugin["link"])
|
||||||
file = f.read()
|
if pluginHash not in signatures:
|
||||||
plugin_hash = hash(file)
|
plugin["verified"] = False
|
||||||
if plugin_hash not in signatures:
|
else:
|
||||||
plugin["verified"] = False
|
plugin["verified"] = True
|
||||||
else:
|
|
||||||
plugin["verified"] = True
|
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
@ -54,13 +54,49 @@ def verifyPlugin(plugin: str):
|
|||||||
json.dump(signatures, f)
|
json.dump(signatures, f)
|
||||||
|
|
||||||
# Hash the plugin file
|
# Hash the plugin file
|
||||||
with open(f"plugins/{plugin}.py", "r") as f:
|
pluginHash = hashPlugin(plugin)
|
||||||
file = f.read()
|
if pluginHash not in signatures:
|
||||||
plugin_hash = hash(file)
|
signatures.append(pluginHash)
|
||||||
if plugin_hash not in signatures:
|
with open("plugins/signatures.json", "w") as f:
|
||||||
signatures.append(plugin_hash)
|
json.dump(signatures, f)
|
||||||
with open("plugins/signatures.json", "w") as f:
|
|
||||||
json.dump(signatures, f)
|
|
||||||
|
def hashPlugin(plugin: str):
|
||||||
|
BUF_SIZE = 65536
|
||||||
|
|
||||||
|
# Initializing the sha256() method
|
||||||
|
sha256 = hashlib.sha256()
|
||||||
|
|
||||||
|
# Opening the file provided as the first
|
||||||
|
# commandline argument
|
||||||
|
with open("plugins/"+plugin+".py", 'rb') as f:
|
||||||
|
while True:
|
||||||
|
# reading data = BUF_SIZE from the
|
||||||
|
# file and saving it in a variable
|
||||||
|
data = f.read(BUF_SIZE)
|
||||||
|
|
||||||
|
# True if eof = 1
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Passing that data to that sh256 hash
|
||||||
|
# function (updating the function with that data)
|
||||||
|
sha256.update(data)
|
||||||
|
|
||||||
|
# sha256.hexdigest() hashes all the input data passed
|
||||||
|
# to the sha256() via sha256.update()
|
||||||
|
# Acts as a finalize method, after which
|
||||||
|
# all the input data gets hashed
|
||||||
|
# hexdigest() hashes the data, and returns
|
||||||
|
# the output in hexadecimal format
|
||||||
|
return sha256.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getPluginData(pluginStr: str):
|
def getPluginData(pluginStr: str):
|
||||||
plugin = importlib.import_module("plugins."+pluginStr)
|
plugin = importlib.import_module("plugins."+pluginStr)
|
||||||
@ -77,13 +113,13 @@ def getPluginData(pluginStr: str):
|
|||||||
|
|
||||||
info = plugin.info
|
info = plugin.info
|
||||||
# Hash the plugin file
|
# Hash the plugin file
|
||||||
with open(f"plugins/{pluginStr}.py", "r") as f:
|
pluginHash = hashPlugin(pluginStr)
|
||||||
file = f.read()
|
print(pluginHash)
|
||||||
plugin_hash = hash(file)
|
print(signatures)
|
||||||
if plugin_hash not in signatures:
|
if pluginHash not in signatures:
|
||||||
info["verified"] = False
|
info["verified"] = False
|
||||||
else:
|
else:
|
||||||
info["verified"] = True
|
info["verified"] = True
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@ -113,11 +149,9 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
|
|||||||
json.dump(signatures, f)
|
json.dump(signatures, f)
|
||||||
|
|
||||||
# Hash the plugin file
|
# Hash the plugin file
|
||||||
with open(f"plugins/{plugin}.py", "r") as f:
|
pluginHash = hashPlugin(plugin)
|
||||||
file = f.read()
|
if pluginHash not in signatures:
|
||||||
plugin_hash = hash(file)
|
return {"error": "Plugin not verified"}
|
||||||
if plugin_hash not in signatures:
|
|
||||||
return {"error": "Plugin not verified"}
|
|
||||||
|
|
||||||
|
|
||||||
# Call the function with provided parameters
|
# Call the function with provided parameters
|
||||||
|
Loading…
Reference in New Issue
Block a user