Ticket #2133: beaker-hmac2.4.patch
| File beaker-hmac2.4.patch, 2.8 KB (added by toshio, 3 years ago) |
|---|
-
Beaker-1.3.1/beaker/crypto/pbkdf2.py
diff -up Beaker-1.3.1/beaker/crypto/pbkdf2.py.hmac Beaker-1.3.1/beaker/crypto/pbkdf2.py
old new try: 79 79 except ImportError: 80 80 # PyCrypto not available. Use the Python standard library. 81 81 import hmac as HMAC 82 try: 83 from hashlib import sha1 as SHA1 84 except ImportError: 82 import sys 83 # When using the stdlib, we have to make sure the hmac version and sha 84 # version are compatible 85 if sys.version_info[0:2] <= (2,4): 86 # hmac in python2.4 or less require the sha module 87 import sha as SHA1 88 else: 85 89 # NOTE: We have to use the callable with hashlib (hashlib.sha1), 86 90 # otherwise hmac only accepts the sha module object itself 87 import shaas SHA191 from hashlib import sha1 as SHA1 88 92 89 93 def strxor(a, b): 90 94 return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)]) -
Beaker-1.3.1/beaker/session.py
diff -up Beaker-1.3.1/beaker/session.py.hmac Beaker-1.3.1/beaker/session.py
old new import random 6 6 import time 7 7 from datetime import datetime, timedelta 8 8 try: 9 from hashlib import md5 , sha19 from hashlib import md5 10 10 except ImportError: 11 11 from md5 import md5 12 # NOTE: We have to use the callable with hashlib (hashlib.sha1), 13 # otherwise hmac only accepts the sha module object itself 14 import sha as sha1 12 try: 13 # Use PyCrypto (if available) 14 from Crypto.Hash import HMAC, SHA as SHA1 15 16 except ImportError: 17 # PyCrypto not available. Use the Python standard library. 18 import hmac as HMAC 19 import sys 20 # When using the stdlib, we have to make sure the hmac version and sha 21 # version are compatible 22 if sys.version_info[0:2] <= (2,4): 23 # hmac in python2.4 or less require the sha module 24 import sha as SHA1 25 else: 26 # NOTE: We have to use the callable with hashlib (hashlib.sha1), 27 # otherwise hmac only accepts the sha module object itself 28 from hashlib import sha1 as SHA1 15 29 16 30 # Check for pycryptopp encryption for AES 17 31 try: … … class SignedCookie(Cookie.BaseCookie): 37 51 38 52 def value_decode(self, val): 39 53 val = val.strip('"') 40 sig = hmac.new(self.secret, val[40:], sha1).hexdigest()54 sig = HMAC.new(self.secret, val[40:], SHA1).hexdigest() 41 55 if sig != val[:40]: 42 56 return None, val 43 57 else: 44 58 return val[40:], val 45 59 46 60 def value_encode(self, val): 47 sig = hmac.new(self.secret, val, sha1).hexdigest()61 sig = HMAC.new(self.secret, val, SHA1).hexdigest() 48 62 return str(val), ("%s%s" % (sig, val)) 49 63 50 64