forked from pool/python-websockify
- Add JWT token plugin feature.
Added patches:
u_added_jwt_tokens_capability.patch
PyJWT-token-plugin.patch: fate#325762
OBS-URL: https://build.opensuse.org/request/show/674430
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-websockify?expand=0&rev=33
54 lines
2.2 KiB
Diff
54 lines
2.2 KiB
Diff
From cf2bd3930d8506dbb4db172c89a6a628134595aa Mon Sep 17 00:00:00 2001
|
|
From: UXabre <arend.lapere@gmail.com>
|
|
Date: Fri, 21 Dec 2018 03:21:29 -0500
|
|
Subject: [PATCH] Added JWT tokens capability
|
|
|
|
---
|
|
setup.py | 2 +-
|
|
tests/jwt.secret | 1 +
|
|
tests/jwt_rsa | 27 ++++++++++++++++++
|
|
tests/jwt_rsa.pub | 1 +
|
|
tests/test_websocketproxy.py | 54 ++++++++++++++++++++++++++++++++++++
|
|
websockify/token_plugins.py | 16 +++++++++++
|
|
6 files changed, 100 insertions(+), 1 deletion(-)
|
|
create mode 100644 tests/jwt.secret
|
|
create mode 100644 tests/jwt_rsa
|
|
create mode 100644 tests/jwt_rsa.pub
|
|
|
|
Index: websockify-0.8.0/setup.py
|
|
===================================================================
|
|
--- websockify-0.8.0.orig/setup.py
|
|
+++ websockify-0.8.0/setup.py
|
|
@@ -34,7 +34,7 @@ setup(name=name,
|
|
|
|
packages=['websockify'],
|
|
include_package_data=True,
|
|
- install_requires=['numpy'],
|
|
+ install_requires=['numpy', 'PyJWT', 'cryptography'],
|
|
zip_safe=False,
|
|
entry_points={
|
|
'console_scripts': [
|
|
Index: websockify-0.8.0/websockify/token_plugins.py
|
|
===================================================================
|
|
--- websockify-0.8.0.orig/websockify/token_plugins.py
|
|
+++ websockify-0.8.0/websockify/token_plugins.py
|
|
@@ -125,5 +125,17 @@ class JWTTokenApi(BasePlugin):
|
|
print >>sys.stderr, "Failed to parse token: %s" % (e)
|
|
return None
|
|
except ImportError as e:
|
|
- print >>sys.stderr, "package jwcrypto not found, are you sure you've installed it correctly?"
|
|
+ try:
|
|
+ import jwt
|
|
+
|
|
+ secret = open(self.source, 'rb').read()
|
|
+ parsed = jwt.decode(token, secret, algorithms=['RS256', 'RS384', 'RS512', 'HS256', 'HS384', 'HS512', 'ES256', 'ES384', 'ES512', 'PS256', 'PS384', 'PS512'])
|
|
+
|
|
+ return (parsed['host'], parsed['port'])
|
|
+ except Exception as e:
|
|
+ print >>sys.stderr, "Failed to parse token: %s" % (e)
|
|
+ return None
|
|
+ except ImportError:
|
|
+ print >>sys.stderr, "neither package jwcrypto nor PyJWT found, are you sure you've installed one of them correctly?"
|
|
+ return None
|
|
return None
|