From 802025417edde28f6fbfb2bc09b6db6cd9d76de1 Mon Sep 17 00:00:00 2001 From: Logan Bibby Date: Fri, 22 Nov 2024 08:50:44 -0600 Subject: [PATCH 1/4] Update md5 to set usedforsecurity for FIPS compliance --- cacheops/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cacheops/utils.py b/cacheops/utils.py index cd71c6ea..d37ce835 100644 --- a/cacheops/utils.py +++ b/cacheops/utils.py @@ -143,7 +143,7 @@ def repl(m): class md5: def __init__(self, s=None): - self.md5 = hashlib.md5() + self.md5 = hashlib.md5(usedforsecurity=False) if s is not None: self.update(s) From 9b973454f3e2a2155abfb5de1c86093c712bee1d Mon Sep 17 00:00:00 2001 From: Logan Bibby Date: Mon, 25 Nov 2024 08:11:37 -0600 Subject: [PATCH 2/4] Backwards compatibility with pre-3.9 --- cacheops/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cacheops/utils.py b/cacheops/utils.py index d37ce835..578ee34b 100644 --- a/cacheops/utils.py +++ b/cacheops/utils.py @@ -1,6 +1,7 @@ import re import json import inspect +import sys from funcy import memoize, compose, wraps, any, any_fn, select_values, mapcat from django.db import models @@ -143,7 +144,16 @@ def repl(m): class md5: def __init__(self, s=None): - self.md5 = hashlib.md5(usedforsecurity=False) + md5_kwargs = {} + + # set usedforsecurity for FIPS compliance + # usedforsecurity was introduced in 3.9 + # this is for backwards compatibility + pyversion = sys.version_info + if pyversion.major == 3 and pyversion.minor >= 9: + md5_kwargs["usedforsecuirty"] = False + + self.md5 = hashlib.md5(**md5_kwargs) if s is not None: self.update(s) From 34bb1b2f0f3e6f168dfba90015c994349cb10bfb Mon Sep 17 00:00:00 2001 From: Logan Bibby Date: Mon, 25 Nov 2024 08:14:11 -0600 Subject: [PATCH 3/4] Backwards compatibility with pre-3.9 --- cacheops/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cacheops/utils.py b/cacheops/utils.py index 578ee34b..bc536785 100644 --- a/cacheops/utils.py +++ b/cacheops/utils.py @@ -150,7 +150,7 @@ def __init__(self, s=None): # usedforsecurity was introduced in 3.9 # this is for backwards compatibility pyversion = sys.version_info - if pyversion.major == 3 and pyversion.minor >= 9: + if (pyversion.major == 3 and pyversion.minor >= 9) or pyversion.major > 3: md5_kwargs["usedforsecuirty"] = False self.md5 = hashlib.md5(**md5_kwargs) From 86986ad03771ea5fa261813cb4eea35953d9dcf5 Mon Sep 17 00:00:00 2001 From: Logan Bibby Date: Mon, 25 Nov 2024 08:21:06 -0600 Subject: [PATCH 4/4] Fixed typo in md5_kwargs --- cacheops/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cacheops/utils.py b/cacheops/utils.py index bc536785..4857f262 100644 --- a/cacheops/utils.py +++ b/cacheops/utils.py @@ -151,7 +151,7 @@ def __init__(self, s=None): # this is for backwards compatibility pyversion = sys.version_info if (pyversion.major == 3 and pyversion.minor >= 9) or pyversion.major > 3: - md5_kwargs["usedforsecuirty"] = False + md5_kwargs["usedforsecurity"] = False self.md5 = hashlib.md5(**md5_kwargs) if s is not None: