From e9e79e088d711e5243d30a1f9b9adc28f91c793d Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Tue, 10 Apr 2018 13:28:32 +0200 Subject: [PATCH] Add version field to auth cookie --- auth.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/auth.py b/auth.py index 38e8d8e..33b64a2 100644 --- a/auth.py +++ b/auth.py @@ -3,6 +3,7 @@ import hashlib import ssl from datetime import datetime +FORMAT_VERSION = 1 class User: def __init__(self, username, groups, all_groups, timestamp=None, @@ -22,19 +23,26 @@ class User: def summarize(self): return ":".join(( self.username, ",".join(self.groups), ",".join(self.all_groups), - str(self.timestamp.timestamp()), str(self.permanent))) + str(self.timestamp.timestamp()), str(self.permanent), + str(FORMAT_VERSION))) @staticmethod def from_summary(summary): - parts = summary.split(":", 4) - if len(parts) != 5: + parts = summary.split(":", 5) + if len(parts) != 6: + return None + (name, group_str, all_group_str, timestamp_str, + permanent_str, version_str) = parts + try: + if int(version_str) != FORMAT_VERSION: + return None + timestamp = datetime.fromtimestamp(float(timestamp_str)) + groups = group_str.split(",") + all_groups = all_group_str.split(",") + permanent = permanent_str == "True" + return User(name, groups, all_groups, timestamp, permanent) + except ValueError: return None - (name, group_str, all_group_str, timestamp_str, permanent_str) = parts - timestamp = datetime.fromtimestamp(float(timestamp_str)) - groups = group_str.split(",") - all_groups = all_group_str.split(",") - permanent = permanent_str == "True" - return User(name, groups, all_groups, timestamp, permanent) @staticmethod def from_hashstring(secure_string): -- GitLab