gh-128192: support HTTP sha-256 digest authentication as per RFC-7617 (GH-128193)

support sha-256 digest authentication

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Calvin Bui 2024-12-29 08:05:34 +11:00 committed by GitHub
parent 492b224b99
commit f9a5a3a3ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 5 deletions

View file

@ -1048,7 +1048,7 @@ _randombytes = os.urandom
class AbstractDigestAuthHandler:
# Digest authentication is specified in RFC 2617.
# Digest authentication is specified in RFC 2617/7616.
# XXX The client does not inspect the Authentication-Info header
# in a successful response.
@ -1176,11 +1176,14 @@ class AbstractDigestAuthHandler:
return base
def get_algorithm_impls(self, algorithm):
# algorithm names taken from RFC 7616 Section 6.1
# lambdas assume digest modules are imported at the top level
if algorithm == 'MD5':
H = lambda x: hashlib.md5(x.encode("ascii")).hexdigest()
elif algorithm == 'SHA':
elif algorithm == 'SHA': # non-standard, retained for compatibility.
H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest()
elif algorithm == 'SHA-256':
H = lambda x: hashlib.sha256(x.encode("ascii")).hexdigest()
# XXX MD5-sess
else:
raise ValueError("Unsupported digest authentication "