diff options
author | Calvin Bui <3604363+calvinbui@users.noreply.github.com> | 2024-12-28 21:05:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-28 21:05:34 (GMT) |
commit | f9a5a3a3ef34e63dc197156e9a5f57842859ca04 (patch) | |
tree | b823b79dc0e2edaf819b13224d6795c93179ecfb /Lib/urllib | |
parent | 492b224b991cd9027f1bc6d9988d01e94f764992 (diff) | |
download | cpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.zip cpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.tar.gz cpython-f9a5a3a3ef34e63dc197156e9a5f57842859ca04.tar.bz2 |
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>
Diffstat (limited to 'Lib/urllib')
-rw-r--r-- | Lib/urllib/request.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index c5a6a18..0d1b594 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -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 " |