Call `hashlib functions with usedforsecurity=False`

This commit is contained in:
Adam Turner 2023-01-06 19:00:22 +00:00
parent f0dbe8180d
commit 13a87d8070

View File

@ -6,6 +6,7 @@ import hashlib
import os import os
import posixpath import posixpath
import re import re
import sys
import warnings import warnings
from importlib import import_module from importlib import import_module
from os import path from os import path
@ -133,31 +134,23 @@ class FilenameUniqDict(dict):
def md5(data=b'', **kwargs): def md5(data=b'', **kwargs):
"""Wrapper around hashlib.md5 """Wrapper around hashlib.md5
Attempt call with 'usedforsecurity=False' if we get a ValueError, which happens when Attempt call with 'usedforsecurity=False' if supported.
OpenSSL FIPS mode is enabled:
ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips
See: https://github.com/sphinx-doc/sphinx/issues/7611
""" """
try: if sys.version_info[:2] > (3, 8):
return hashlib.md5(data, **kwargs) return hashlib.md5(data, usedforsecurity=False)
except ValueError: return hashlib.md5(data, **kwargs)
return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore
def sha1(data=b'', **kwargs): def sha1(data=b'', **kwargs):
"""Wrapper around hashlib.sha1 """Wrapper around hashlib.sha1
Attempt call with 'usedforsecurity=False' if we get a ValueError Attempt call with 'usedforsecurity=False' if supported.
See: https://github.com/sphinx-doc/sphinx/issues/7611
""" """
try: if sys.version_info[:2] > (3, 8):
return hashlib.sha1(data, **kwargs) return hashlib.sha1(data, usedforsecurity=False)
except ValueError: return hashlib.sha1(data, **kwargs)
return hashlib.sha1(data, **kwargs, usedforsecurity=False) # type: ignore
class DownloadFiles(dict): class DownloadFiles(dict):