Skip to content

Fix to hashing compatability issues [2697] with some environments (FIPS) #2817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def register_clientside_callback(
if isinstance(clientside_function, str):
namespace = "_dashprivate_clientside_funcs"
# Create a hash from the function, it will be the same always
function_name = hashlib.md5(clientside_function.encode("utf-8")).hexdigest()
function_name = hashlib.sha256(clientside_function.encode("utf-8")).hexdigest()

inline_scripts.append(
_inline_clientside_template.format(
Expand Down
6 changes: 3 additions & 3 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _concat(x):
_id = x.component_id_str().replace(".", "\\.") + "." + x.component_property
if x.allow_duplicate:
if not hashed_inputs:
hashed_inputs = hashlib.md5(
hashed_inputs = hashlib.sha256(
".".join(str(x) for x in inputs).encode("utf-8")
).hexdigest()
# Actually adds on the property part.
Expand Down Expand Up @@ -213,9 +213,9 @@ def run_command_with_process(cmd):
proc.communicate()


def compute_md5(path):
def compute_hash(path):
with io.open(path, encoding="utf-8") as fp:
return hashlib.md5(fp.read().encode("utf-8")).hexdigest()
return hashlib.sha256(fp.read().encode("utf-8")).hexdigest()


def job(msg=""):
Expand Down
2 changes: 1 addition & 1 deletion dash/development/_jl_components_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def generate_toml_file(project_shortname, pkg_data):
u = uuid.UUID(jl_dash_uuid)

package_uuid = uuid.UUID(
hex=u.hex[:-12] + hashlib.md5(package_name.encode("utf-8")).hexdigest()[-12:]
hex=u.hex[:-12] + hashlib.sha256(package_name.encode("utf-8")).hexdigest()[-12:]
)

authors_string = (
Expand Down
4 changes: 2 additions & 2 deletions dash/development/build_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fire
import requests

from .._utils import run_command_with_process, compute_md5, job
from .._utils import run_command_with_process, compute_hash, job

logger = logging.getLogger(__name__)
coloredlogs.install(
Expand Down Expand Up @@ -97,7 +97,7 @@ def digest(self):
logger.info("bundles in %s %s", folder, copies)

for copy in copies:
payload[f"MD5 ({copy})"] = compute_md5(self._concat(folder, copy))
payload[f"SHA256 ({copy})"] = compute_hash(self._concat(folder, copy))

with open(self._concat(self.main, "digest.json"), "w", encoding="utf-8") as fp:
json.dump(payload, fp, sort_keys=True, indent=4, separators=(",", ":"))
Expand Down
4 changes: 2 additions & 2 deletions dash/long_callback/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def build_cache_key(self, fn, args, cache_args_to_ignore):
# Call cache function
hash_dict[f"cache_key_{i}"] = cache_item()

return hashlib.sha1(str(hash_dict).encode("utf-8")).hexdigest()
return hashlib.sha256(str(hash_dict).encode("utf-8")).hexdigest()

def register(self, key, fn, progress):
self.func_registry[key] = self.make_job_fn(fn, progress, key)
Expand Down Expand Up @@ -102,6 +102,6 @@ def _make_progress_key(key):
def hash_function(fn, callback_id=""):
fn_source = inspect.getsource(fn)
fn_str = fn_source
return hashlib.sha1(
return hashlib.sha256(
callback_id.encode("utf-8") + fn_str.encode("utf-8")
).hexdigest()