diff options
author | Bruno Windels <brunow@matrix.org> | 2018-09-18 16:04:57 +0200 |
---|---|---|
committer | Bruno Windels <brunow@matrix.org> | 2018-09-18 16:04:57 +0200 |
commit | b6498e323c029afebf4fa20c8d894b01faf56a7d (patch) | |
tree | 8d9e342940aa596b7097d580b9b07552d0fe8edb | |
parent | Merge pull request #3879 from matrix-org/matthew/fix-autojoin (diff) | |
download | synapse-b6498e323c029afebf4fa20c8d894b01faf56a7d.tar.xz |
fallback for compare_digest for py < 2.7.7
-rw-r--r-- | synapse/rest/client/v1/admin.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/synapse/rest/client/v1/admin.py b/synapse/rest/client/v1/admin.py index 41534b8c2a..49e2d153ca 100644 --- a/synapse/rest/client/v1/admin.py +++ b/synapse/rest/client/v1/admin.py @@ -37,6 +37,12 @@ from .base import ClientV1RestServlet, client_path_patterns logger = logging.getLogger(__name__) +# use hmac.compare_digest if we have it (python 2.7.7), else just use equality +if hasattr(hmac, "compare_digest"): + compare_digest = hmac.compare_digest +else: + def compare_digest(a, b): + return a == b class UsersRestServlet(ClientV1RestServlet): PATTERNS = client_path_patterns("/admin/users/(?P<user_id>[^/]*)") @@ -173,7 +179,7 @@ class UserRegisterServlet(ClientV1RestServlet): want_mac.update(b"admin" if admin else b"notadmin") want_mac = want_mac.hexdigest() - if not hmac.compare_digest( + if not compare_digest( want_mac.encode('ascii'), got_mac.encode('ascii') ): |