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 posixpath
import re
import sys
import warnings
from importlib import import_module
from os import path
@ -133,31 +134,23 @@ class FilenameUniqDict(dict):
def md5(data=b'', **kwargs):
"""Wrapper around hashlib.md5
Attempt call with 'usedforsecurity=False' if we get a ValueError, which happens when
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
Attempt call with 'usedforsecurity=False' if supported.
"""
try:
return hashlib.md5(data, **kwargs)
except ValueError:
return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore
if sys.version_info[:2] > (3, 8):
return hashlib.md5(data, usedforsecurity=False)
return hashlib.md5(data, **kwargs)
def sha1(data=b'', **kwargs):
"""Wrapper around hashlib.sha1
Attempt call with 'usedforsecurity=False' if we get a ValueError
See: https://github.com/sphinx-doc/sphinx/issues/7611
Attempt call with 'usedforsecurity=False' if supported.
"""
try:
return hashlib.sha1(data, **kwargs)
except ValueError:
return hashlib.sha1(data, **kwargs, usedforsecurity=False) # type: ignore
if sys.version_info[:2] > (3, 8):
return hashlib.sha1(data, usedforsecurity=False)
return hashlib.sha1(data, **kwargs)
class DownloadFiles(dict):