Hashid based token implementation

This commit is contained in:
Vladimir Djurovic 2020-11-10 14:52:12 +01:00
parent 01ef6a6a55
commit f602e44dac
2 changed files with 19 additions and 1 deletions

View File

@ -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': [

View File

@ -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