checkout auth
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by daftshady · committed by daftshady · parent 39fe006 · Browse files · 1 file·+17 added−22 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+17 added−22 removed
- other:+17 added−22 removed
Provenance
- Commit
373166d- Tree
f884aa7- Author
daftshady <daftonshady@gmail.com>- Committer
daftshady <daftonshady@gmail.com>- Parent
39fe006
1 file changed+17 added−22 removed
modified:requests/auth.py+17 added-22 removed
75 unmodified lines76 _algorithm = 'MD5'77 else:78 _algorithm = algorithm.upper()79 # lambdas assume digest modules are imported at the top level80- if _algorithm == 'MD5' or _algorithm == 'MD5-SESS':80+ if _algorithm == 'MD5':81 def md5_utf8(x):82 if isinstance(x, str):83 x = x.encode('utf-8')84 return hashlib.md5(x).hexdigest()3 unmodified lines88 if isinstance(x, str):89 x = x.encode('utf-8')90 return hashlib.sha1(x).hexdigest()91 hash_utf8 = sha_utf892-92+ # XXX MD5-sess93 KD = lambda s, d: hash_utf8("%s:%s" % (s, d))94 95 if hash_utf8 is None:96 return None6 unmodified lines103 path += '?' + p_parsed.query104 105 A1 = '%s:%s:%s' % (self.username, realm, self.password)106 A2 = '%s:%s' % (method, path)107- 108- HA1 = hash_utf8(A1)109- HA2 = hash_utf8(A2)107 111- if nonce == self.last_nonce:112- self.nonce_count += 1113- else:114- self.nonce_count = 1115- ncvalue = '%08x' % self.nonce_count116- s = str(self.nonce_count).encode('utf-8')117- s += nonce.encode('utf-8')118- s += time.ctime().encode('utf-8')119- s += os.urandom(8)120-121- cnonce = (hashlib.sha1(s).hexdigest()[:16])122- noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, HA2)123- if _algorithm == 'MD5-SESS':124- HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce))125-108 if qop is None:127- respdig = KD(HA1, "%s:%s" % (nonce, HA2))109+ respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2)))110 elif qop == 'auth' or 'auth' in qop.split(','):111+ if nonce == self.last_nonce:112+ self.nonce_count += 1113+ else:114+ self.nonce_count = 1115+116+ ncvalue = '%08x' % self.nonce_count117+ s = str(self.nonce_count).encode('utf-8')118+ s += nonce.encode('utf-8')119+ s += time.ctime().encode('utf-8')120+ s += os.urandom(8)121+122+ cnonce = (hashlib.sha1(s).hexdigest()[:16])123+ noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))129- respdig = KD(HA1, noncebit)124+ respdig = KD(hash_utf8(A1), noncebit)125 else:126 # XXX handle auth-int.127 return None128 52 unmodified lines