simplified more CRYPT logic and removed hmac_hash, functionality included in simple_hash, thanks David
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.00.0 (2012-08-09 23:09:46) dev
|
||||
Version 2.00.0 (2012-08-09 23:34:34) dev
|
||||
|
||||
+3
-4
@@ -25,7 +25,7 @@ from HTMLParser import HTMLParser
|
||||
from htmlentitydefs import name2codepoint
|
||||
|
||||
from storage import Storage
|
||||
from utils import web2py_uuid, hmac_hash, compare
|
||||
from utils import web2py_uuid, simple_hash, compare
|
||||
from highlight import highlight
|
||||
|
||||
regex_crlf = re.compile('\r|\n')
|
||||
@@ -327,8 +327,7 @@ def URL(
|
||||
|
||||
# re-assembling the same way during hash authentication
|
||||
message = h_args + '?' + urllib.urlencode(sorted(h_vars))
|
||||
sig = hmac_hash(message, (hmac_key or '')+(salt or ''),
|
||||
digest_alg='sha1')
|
||||
sig = simple_hash(message, hmac_key or '',salt or '',digest_alg='sha1')
|
||||
# add the signature into vars
|
||||
list_vars.append(('_signature', sig))
|
||||
|
||||
@@ -447,7 +446,7 @@ def verifyURL(request, hmac_key=None, hash_vars=True, salt=None, user_signature=
|
||||
message = h_args + '?' + urllib.urlencode(sorted(h_vars))
|
||||
|
||||
# hash with the hmac_key provided
|
||||
sig = hmac_hash(message, str(hmac_key)+(salt or ''), digest_alg='sha1')
|
||||
sig = simple_hash(message, str(hmac_key), salt or '', digest_alg='sha1')
|
||||
|
||||
# put _signature back in get_vars just in case a second call to URL.verify is performed
|
||||
# (otherwise it'll immediately return false)
|
||||
|
||||
+8
-12
@@ -42,10 +42,15 @@ def simple_hash(text, key='', salt = '', digest_alg = 'md5'):
|
||||
"""
|
||||
if not digest_alg:
|
||||
raise RuntimeError, "simple_hash with digest_alg=None"
|
||||
elif not isinstance(digest_alg,str):
|
||||
elif not isinstance(digest_alg,str): # manual approach
|
||||
h = digest_alg(text+key+salt)
|
||||
elif key: # backward compatile
|
||||
return hmac_hash(text, key+salt, digest_alg)
|
||||
elif digest_alg.startswith('pbkdf2'): # latest and coolest!
|
||||
iterations, keylen, alg = digest_alg[7:-1].split(',')
|
||||
return pbkdf2_hex(text, salt, int(iterations),
|
||||
int(keylen),get_digest(alg))
|
||||
elif key: # use hmac
|
||||
digest_alg = get_digest(digest_alg)
|
||||
h = hmac.new(key+salt,value,digest_alg)
|
||||
else: # compatible with third party systems
|
||||
h = hashlib.new(digest_alg)
|
||||
h.update(text+salt)
|
||||
@@ -82,15 +87,6 @@ DIGEST_ALG_BY_SIZE = {
|
||||
512/4: 'sha512',
|
||||
}
|
||||
|
||||
def hmac_hash(value, salt, digest_alg='md5'):
|
||||
if isinstance(digest_alg,str) and digest_alg.startswith('pbkdf2'):
|
||||
iterations, keylen, alg = digest_alg[7:-1].split(',')
|
||||
return pbkdf2_hex(value, salt, int(iterations),
|
||||
int(keylen),get_digest(alg))
|
||||
digest_alg = get_digest(digest_alg)
|
||||
d = hmac.new(salt,value,digest_alg)
|
||||
return d.hexdigest()
|
||||
|
||||
|
||||
### compute constant ctokens
|
||||
def initialize_urandom():
|
||||
|
||||
Reference in New Issue
Block a user