]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
md5: don't rely on version for usedforsecurity
authorJason Ish <jason.ish@oisf.net>
Tue, 8 Apr 2025 22:42:02 +0000 (16:42 -0600)
committerJason Ish <jason.ish@oisf.net>
Tue, 8 Apr 2025 22:42:02 +0000 (16:42 -0600)
The usedforsecurity flag to hashlib.md5 doesn't appear to be version
specific, due to backporting, etc.

Instead attempt to use it, on exception, fallback to not using it.

Ticket: https://redmine.openinfosecfoundation.org/issues/7255

suricata/update/util.py

index c2a73d0b4845d0505dbdbebfa1fa0f465fb32835..2fa1f3330c47a6147150b1ef4dba8de3db07c5f2 100644 (file)
@@ -30,10 +30,10 @@ def md5_hexdigest(buf):
 
     :returns: A string representing the hex value of the computed MD5.
     """
-    if sys.version_info.major < 3 or (sys.version_info.major == 3 and sys.version_info.minor < 9):
-        return hashlib.md5(buf).hexdigest().strip()
-    else:
+    try:
         return hashlib.md5(buf, usedforsecurity=False).hexdigest().strip()
+    except:
+        return hashlib.md5(buf).hexdigest().strip()
 
 def mktempdir(delete_on_exit=True):
     """ Create a temporary directory that is removed on exit. """