Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c28d81f9
Commit
c28d81f9
authored
Aug 29, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up brokenness with hashing, now hashlib is strict in requiring bytes too.
parent
e63905de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
Lib/test/test_urllib2_localnet.py
Lib/test/test_urllib2_localnet.py
+4
-4
Lib/urllib2.py
Lib/urllib2.py
+6
-5
No files found.
Lib/test/test_urllib2_localnet.py
View file @
c28d81f9
...
...
@@ -88,7 +88,7 @@ class DigestAuthHandler:
def
_generate_nonce
(
self
):
self
.
_request_num
+=
1
nonce
=
hashlib
.
md5
(
str
(
self
.
_request_num
)).
hexdigest
()
nonce
=
hashlib
.
md5
(
str
(
self
.
_request_num
)
.
encode
(
"ascii"
)
).
hexdigest
()
self
.
_nonces
.
append
(
nonce
)
return
nonce
...
...
@@ -116,14 +116,14 @@ class DigestAuthHandler:
final_dict
[
"method"
]
=
method
final_dict
[
"uri"
]
=
uri
HA1_str
=
"%(username)s:%(realm)s:%(password)s"
%
final_dict
HA1
=
hashlib
.
md5
(
HA1_str
).
hexdigest
()
HA1
=
hashlib
.
md5
(
HA1_str
.
encode
(
"ascii"
)
).
hexdigest
()
HA2_str
=
"%(method)s:%(uri)s"
%
final_dict
HA2
=
hashlib
.
md5
(
HA2_str
).
hexdigest
()
HA2
=
hashlib
.
md5
(
HA2_str
.
encode
(
"ascii"
)
).
hexdigest
()
final_dict
[
"HA1"
]
=
HA1
final_dict
[
"HA2"
]
=
HA2
response_str
=
"%(HA1)s:%(nonce)s:%(nc)s:"
\
"%(cnonce)s:%(qop)s:%(HA2)s"
%
final_dict
response
=
hashlib
.
md5
(
response_str
).
hexdigest
()
response
=
hashlib
.
md5
(
response_str
.
encode
(
"ascii"
)
).
hexdigest
()
return
response
==
auth_dict
[
"response"
]
...
...
Lib/urllib2.py
View file @
c28d81f9
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment