summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2013-02-01 18:33:23 -0700
committerBert JW Regeer <bertjw@regeer.org>2013-02-02 00:42:54 -0700
commitc0151a32b4cf30fe58dbe63f2c58f1f862c3f82e (patch)
treee49cce73329a24568df0a3d5ed39ba16f64b963a
parent54d31379c1c10879ba89b6616b033152d9bb69bf (diff)
downloadpyramid-c0151a32b4cf30fe58dbe63f2c58f1f862c3f82e.tar.gz
pyramid-c0151a32b4cf30fe58dbe63f2c58f1f862c3f82e.tar.bz2
pyramid-c0151a32b4cf30fe58dbe63f2c58f1f862c3f82e.zip
Fix IPv6 compatibility in calculate_digest()
This is a quick fix for adding IPv6 compatibility so that if the AuthTktAuthenticationPolicy is used with include_ip enabled then it won't throw an error.
-rw-r--r--pyramid/authentication.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/pyramid/authentication.py b/pyramid/authentication.py
index 190298f98..43353f3e2 100644
--- a/pyramid/authentication.py
+++ b/pyramid/authentication.py
@@ -740,9 +740,17 @@ def calculate_digest(ip, timestamp, secret, userid, tokens, user_data,
tokens = bytes_(tokens, 'utf-8')
user_data = bytes_(user_data, 'utf-8')
hash_obj = hashlib.new(hashalg)
- hash_obj.update(
- encode_ip_timestamp(ip, timestamp) + secret + userid + b'\0'
- + tokens + b'\0' + user_data)
+
+ # Check to see if this is an IPv6 address
+ if ':' in ip:
+ ip_timestamp = ip + str(int(timestamp))
+ ip_timestamp = bytes_(ip_timestamp)
+ else:
+ # encode_ip_timestamp not required, left in for backwards compatibility
+ ip_timestamp = encode_ip_timestamp(ip, timestamp)
+
+ hash_obj.update(ip_timestamp + secret + userid + b'\0' +
+ tokens + b'\0' + user_data)
digest = hash_obj.hexdigest()
hash_obj2 = hashlib.new(hashalg)
hash_obj2.update(bytes_(digest) + secret)