Move DigestAuth hash algorithms to use usedforsecurity=False (#7310)

This commit is contained in:
Nate Prewitt
2026-04-15 08:56:38 -06:00
committed by GitHub
parent 16df2a0917
commit a044b020de

View File

@@ -145,7 +145,7 @@ class HTTPDigestAuth(AuthBase):
def md5_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.md5(x).hexdigest()
return hashlib.md5(x, usedforsecurity=False).hexdigest()
hash_utf8 = md5_utf8
elif _algorithm == "SHA":
@@ -153,7 +153,7 @@ class HTTPDigestAuth(AuthBase):
def sha_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha1(x).hexdigest()
return hashlib.sha1(x, usedforsecurity=False).hexdigest()
hash_utf8 = sha_utf8
elif _algorithm == "SHA-256":
@@ -161,7 +161,7 @@ class HTTPDigestAuth(AuthBase):
def sha256_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha256(x).hexdigest()
return hashlib.sha256(x, usedforsecurity=False).hexdigest()
hash_utf8 = sha256_utf8
elif _algorithm == "SHA-512":
@@ -169,7 +169,7 @@ class HTTPDigestAuth(AuthBase):
def sha512_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha512(x).hexdigest()
return hashlib.sha512(x, usedforsecurity=False).hexdigest()
hash_utf8 = sha512_utf8
@@ -202,7 +202,7 @@ class HTTPDigestAuth(AuthBase):
s += time.ctime().encode("utf-8")
s += os.urandom(8)
cnonce = hashlib.sha1(s).hexdigest()[:16]
cnonce = hashlib.sha1(s, usedforsecurity=False).hexdigest()[:16]
if _algorithm == "MD5-SESS":
HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}")