From ff3fdd149d102bdde5497f4d57206cb2320f251c Mon Sep 17 00:00:00 2001 From: PexMor Date: Thu, 4 Apr 2019 13:53:17 +0200 Subject: [PATCH] novnc redis backed token_plyugins.py --- test-requirements.txt | 2 ++ websockify/auth_plugins.py | 2 +- websockify/token_plugins.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index b4f8d9a..22027e6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,3 +2,5 @@ mox3 nose jwcrypto;python_version>="2.7" enum34;python_version=="3.3" +redis;python_version>="2.7" +simplejson;python_version>="2.7" diff --git a/websockify/auth_plugins.py b/websockify/auth_plugins.py index ed3a169..2d636c2 100644 --- a/websockify/auth_plugins.py +++ b/websockify/auth_plugins.py @@ -87,7 +87,7 @@ class ExpectOrigin(object): origin = headers.get('Origin', None) if origin is None or origin not in self.source: raise InvalidOriginError(expected=self.source, actual=origin) - + class ClientCertCNAuth(object): """Verifies client by SSL certificate. Specify src as whitespace separated list of common names.""" diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index 972907b..92aec98 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -134,3 +134,23 @@ class JWTTokenApi(BasePlugin): except ImportError as e: print("package jwcrypto not found, are you sure you've installed it correctly?", file=sys.stderr) return None + +import sys + +if sys.version_info >= (2, 7): + import redis + import simplejson + + class TokenRedis(object): + def __init__(self, src): + self._server, self._port = src.split(":") + + def lookup(self, token): + client = redis.Redis(host=self._server,port=self._port) + stuff = client.get(token) + if stuff is None: + return None + else: + combo = simplejson.loads(stuff.decode("utf-8")) + pair = combo["host"] + return pair.split(':')