summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-29 14:26:52 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-29 14:26:52 (GMT)
commit813601486216e197069a1e2d119ea00202426bcd (patch)
treec7afb1c6abc3f30b6f3d204ed565cf272e90e9b8 /Lib/urllib2.py
parentec9a4afa32e723bece8b77fe79b2371cd4947270 (diff)
downloadcpython-813601486216e197069a1e2d119ea00202426bcd.zip
cpython-813601486216e197069a1e2d119ea00202426bcd.tar.gz
cpython-813601486216e197069a1e2d119ea00202426bcd.tar.bz2
Fix up brokenness with hashing, now hashlib is strict in requiring bytes too.
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 1defbe9..0995aeb 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -837,7 +837,7 @@ class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
def randombytes(n):
"""Return n random bytes."""
- return str(os.urandom(n), "latin-1")
+ return os.urandom(n)
class AbstractDigestAuthHandler:
# Digest authentication is specified in RFC 2617.
@@ -896,8 +896,9 @@ class AbstractDigestAuthHandler:
# and server to avoid chosen plaintext attacks, to provide mutual
# authentication, and to provide some message integrity protection.
# This isn't a fabulous effort, but it's probably Good Enough.
- dig = hashlib.sha1("%s:%s:%s:%s" % (self.nonce_count, nonce, time.ctime(),
- randombytes(8))).hexdigest()
+ s = "%s:%s:%s:" % (self.nonce_count, nonce, time.ctime())
+ b = s.encode("ascii") + randombytes(8)
+ dig = hashlib.sha1(b).hexdigest()
return dig[:16]
def get_authorization(self, req, chal):
@@ -959,9 +960,9 @@ class AbstractDigestAuthHandler:
def get_algorithm_impls(self, algorithm):
# lambdas assume digest modules are imported at the top level
if algorithm == 'MD5':
- H = lambda x: hashlib.md5(x).hexdigest()
+ H = lambda x: hashlib.md5(x.encode("ascii")).hexdigest()
elif algorithm == 'SHA':
- H = lambda x: hashlib.sha1(x).hexdigest()
+ H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest()
# XXX MD5-sess
KD = lambda s, d: H("%s:%s" % (s, d))
return H, KD