| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import hmac | |
| 2 import hashlib | |
| 3 | |
| 4 from sitescripts.utils import get_config | |
| 5 | |
| 6 _SECRET = get_config().get('DEFAULT', 'secret') | |
|
Wladimir Palant
2015/04/23 16:04:40
No, it should be .get('submit_email', 'secret') -
Sebastian Noack
2015/04/23 16:29:41
Done.
| |
| 7 | |
| 8 def constant_time_compare(s1, s2): | |
| 9 if len(s1) != len(s2): | |
| 10 return False | |
| 11 return reduce(lambda a, b: a | b, (ord(c1) ^ ord(c2) for c1, c2 in zip(s1, s2) )) == 0 | |
|
Wladimir Palant
2015/04/23 16:04:40
Do I get it correctly that you are trying to addre
Sebastian Noack
2015/04/23 16:29:41
Sure, that was the idea. But fair enough.
| |
| 12 | |
| 13 def sign(data): | |
| 14 return hmac.new(_SECRET, data, hashlib.sha1).hexdigest() | |
| 15 | |
| 16 def verify(data, signature): | |
| 17 return constant_time_compare(sign(data), signature) | |
| OLD | NEW |