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
68
plugin.py
68
plugin.py
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import importlib
|
import importlib
|
||||||
|
import sys
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -26,10 +28,8 @@ 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)
|
|
||||||
if plugin_hash not in signatures:
|
|
||||||
plugin["verified"] = False
|
plugin["verified"] = False
|
||||||
else:
|
else:
|
||||||
plugin["verified"] = True
|
plugin["verified"] = True
|
||||||
@ -54,14 +54,50 @@ 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:
|
|
||||||
signatures.append(plugin_hash)
|
|
||||||
with open("plugins/signatures.json", "w") as f:
|
with open("plugins/signatures.json", "w") as f:
|
||||||
json.dump(signatures, 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,10 +113,10 @@ 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
|
||||||
@ -113,10 +149,8 @@ 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)
|
|
||||||
if plugin_hash not in signatures:
|
|
||||||
return {"error": "Plugin not verified"}
|
return {"error": "Plugin not verified"}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user