Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent 16df2a0 · Browse files · 1 file+5 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−5 removed

  • other:+5 added−5 removed

1 file+5 added−5 removed

modified:src/requests/auth.py+5 added-5 removed
143 unmodified lines
144145 def md5_utf8(x):146 if isinstance(x, str):147 x = x.encode("utf-8")148 return hashlib.md5(x).hexdigest()148 return hashlib.md5(x, usedforsecurity=False).hexdigest()149150 hash_utf8 = md5_utf8151 elif _algorithm == "SHA":152153 def sha_utf8(x):154 if isinstance(x, str):155 x = x.encode("utf-8")156 return hashlib.sha1(x).hexdigest()156 return hashlib.sha1(x, usedforsecurity=False).hexdigest()157158 hash_utf8 = sha_utf8159 elif _algorithm == "SHA-256":160161 def sha256_utf8(x):162 if isinstance(x, str):163 x = x.encode("utf-8")164 return hashlib.sha256(x).hexdigest()164 return hashlib.sha256(x, usedforsecurity=False).hexdigest()165166 hash_utf8 = sha256_utf8167 elif _algorithm == "SHA-512":168169 def sha512_utf8(x):170 if isinstance(x, str):171 x = x.encode("utf-8")172 return hashlib.sha512(x).hexdigest()172 return hashlib.sha512(x, usedforsecurity=False).hexdigest()173174 hash_utf8 = sha512_utf8175176 KD = lambda s, d: hash_utf8(f"{s}:{d}") # noqa:E731
24 unmodified lines
201 s += nonce.encode("utf-8")202 s += time.ctime().encode("utf-8")203 s += os.urandom(8)204205 cnonce = hashlib.sha1(s).hexdigest()[:16]205 cnonce = hashlib.sha1(s, usedforsecurity=False).hexdigest()[:16]206 if _algorithm == "MD5-SESS":207 HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}")208209 if not qop:
105 unmodified lines