From c0151a32b4cf30fe58dbe63f2c58f1f862c3f82e Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Fri, 1 Feb 2013 18:33:23 -0700 Subject: 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. --- pyramid/authentication.py | 14 +++++++++++--- 1 file 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) -- cgit v1.2.3