From: <Blu...@us...> - 2010-09-15 18:41:32
|
Revision: 407 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=407&view=rev Author: BlueWolf_ Date: 2010-09-15 18:41:24 +0000 (Wed, 15 Sep 2010) Log Message: ----------- Added a better handling for rsa en json-parse errors. These aren't really errors but warnings and are known to happen. App can optionally catch these warnings Modified Paths: -------------- trunk/server/callback.py trunk/server/core/callback.py trunk/server/core/parser.py trunk/server/core/server.py Modified: trunk/server/callback.py =================================================================== --- trunk/server/callback.py 2010-09-15 17:45:24 UTC (rev 406) +++ trunk/server/callback.py 2010-09-15 18:41:24 UTC (rev 407) @@ -56,7 +56,10 @@ return False else: return result['username'] - + + def error(self, name, reason): + log("warning", "Error '" + name + "' occured: " + reason) + def signup(self, cid, usr, pwd, extra): db.execute("SELECT `id` FROM `users` WHERE `username`=%s", usr) Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2010-09-15 17:45:24 UTC (rev 406) +++ trunk/server/core/callback.py 2010-09-15 18:41:24 UTC (rev 407) @@ -171,6 +171,25 @@ pass + def error(self, name, reason): + """ + When something within the code goes wrong or unexpected (like a + json or rsa-parse error, which don't need a complete traceback, they + will be dumped into this function. You can safely ignore this message, + the server should continue working normally + + name: + Which error this is. + * rsa + * json + + reason: + String with the reason of this error + + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. + """ + def check_login(self, cid, usr, pwd): """ This is used to verify the user's login. Return the real username* when Modified: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py 2010-09-15 17:45:24 UTC (rev 406) +++ trunk/server/core/parser.py 2010-09-15 18:41:24 UTC (rev 407) @@ -39,7 +39,7 @@ func = getattr(self, str(head), None) if (func): - func(cid, body) + return func(cid, body) def _check_double_user(self, isbot, screenname, data): """ @@ -112,7 +112,13 @@ # Decrypt the password - pwd = rsa.decrypt(msg['pwd'], client['rsa']) + try: + pwd = rsa.decrypt(msg['pwd'], client['rsa']) + except Exception, error: + self.call.error("rsa", error.__class__.__name__ + " - " + \ + error.message) + return True + # Double sha, so no one can insert "raw" sha pwd = hashlib.sha1(pwd).hexdigest() @@ -261,7 +267,13 @@ connection = client['con'] # Decrypt the password - pwd = rsa.decrypt(msg['pwd'], client['rsa']) + try: + pwd = rsa.decrypt(msg['pwd'], client['rsa']) + except Exception, error: + self.call.error("rsa", error.__class__.__name__ + " - " + \ + error.message) + return True + # Double sha, so no one can insert "raw" sha pwd = hashlib.sha1(pwd).hexdigest() @@ -286,4 +298,4 @@ """ self.call.custom(cid, msg['header'], msg['body']) - \ No newline at end of file + Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2010-09-15 17:45:24 UTC (rev 406) +++ trunk/server/core/server.py 2010-09-15 18:41:24 UTC (rev 407) @@ -326,12 +326,25 @@ for msg in data: try: - self.__parser(self.__cid, simplejson.loads(msg)) - except Exception, Er: + try: + parsed = simplejson.loads(msg) + except Exception, error: + self.__call.error("json", error.__class__.__name__ \ + + " - " + error.message + " - " + repr(msg)) + self.close_msg("crash") + return + + if self.__parser(self.__cid, parsed): + # Force to close the connection due to an error + self.close_msg("crash") + return + + except Exception, error: self.__parser_crash() # Kick connection self.close_msg("crash") + return def close(self, reason = "manual"): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |