From 0dc0955faae83bcf8cde609f8da01aac50e105d8 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 7 Jul 2013 16:00:05 +0000 Subject: [PATCH] Bugfix: authorization: Handle utf8 decoding outside of generic modules, safe if password is None --- eloipool.py | 4 ++++ httpserver.py | 3 +++ jsonrpcserver.py | 3 --- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/eloipool.py b/eloipool.py index 15c8646..6ddd358 100755 --- a/eloipool.py +++ b/eloipool.py @@ -649,6 +649,10 @@ def logShare(share): i.logShare(share) def checkAuthentication(username, password): + # HTTPServer uses bytes, and StratumServer uses str + if hasattr(username, 'decode'): username = username.decode('utf8') + if hasattr(password, 'decode'): password = password.decode('utf8') + for i in authenticators: if i.checkAuthentication(username, password): return True diff --git a/httpserver.py b/httpserver.py index 2199cdd..d2a97eb 100644 --- a/httpserver.py +++ b/httpserver.py @@ -115,6 +115,9 @@ class HTTPHandler(networkserver.SocketHandler): if b'gzip' in value: self.quirks['gzip'] = True + def checkAuthentication(self, *a, **ka): + return self.server.checkAuthentication(*a, **ka) + def doHeader_authorization(self, value): value = value.split(b' ') if len(value) != 2 or value[0] != b'Basic': diff --git a/jsonrpcserver.py b/jsonrpcserver.py index faf5b6b..397d46a 100644 --- a/jsonrpcserver.py +++ b/jsonrpcserver.py @@ -69,9 +69,6 @@ class JSONRPCHandler(httpserver.HTTPHandler): reason = self.fmtError(reason, code) return self.sendReply(500, reason) - def checkAuthentication(self, un, pw): - return self.server.checkAuthentication(un.decode('utf8'), pw.decode('utf8')) - _MidstateNotAdv = (b'phoenix', b'poclbm', b'gminor') def doHeader_user_agent(self, value): self.reqinfo['UA'] = value -- 2.1.4