From f602e44dac61207d67fb51baeaddb45625a91716 Mon Sep 17 00:00:00 2001 From: Vladimir Djurovic Date: Tue, 10 Nov 2020 14:52:12 +0100 Subject: [PATCH] Hashid based token implementation --- setup.py | 2 +- websockify/token_plugins.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b487172..c83303e 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup(name=name, packages=['websockify'], include_package_data=True, - install_requires=['numpy'], + install_requires=['numpy', 'hashids'], zip_safe=False, entry_points={ 'console_scripts': [ diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index 7a988a3..3ffea42 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -186,3 +186,21 @@ class UnixDomainSocketDirectory(BasePlugin): except Exception as e: print("Error finding unix domain socket: %s" % str(e), file=sys.stderr) return None + +class HashIdToken(BasePlugin): + + def __init__(self, salt_file): + file = open(salt_file, 'r') + self.salt = file.read().rstrip() + + def lookup(self, token): + try: + from hashids import Hashids + + hashids = Hashids(salt = self.salt,min_length=10) + out = hashids.decode(token) + + return ['localost', out[0]] + except Exception as e: + print("Error looking up Hashid token: %s" % str(e)) + return None \ No newline at end of file