From: <Blu...@us...> - 2009-12-14 21:22:43
|
Revision: 315 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=315&view=rev Author: BlueWolf_ Date: 2009-12-14 21:22:34 +0000 (Mon, 14 Dec 2009) Log Message: ----------- Changed uid(and id) now means the user-id and cid now means connection/client-id. Fixing some minor things. Server does another sha for the password Modified Paths: -------------- trunk/server/core/callback.py trunk/server/core/database.sql trunk/server/core/parser.py trunk/server/core/server.py Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2009-12-14 19:48:14 UTC (rev 314) +++ trunk/server/core/callback.py 2009-12-14 21:22:34 UTC (rev 315) @@ -29,15 +29,14 @@ """ pass - def connection_opened(self, uid, client, host, port): + def connection_opened(self, cid, client, host, port): """ Called when a new client connects and we accepted the connection. You can, however, still kill the connection by returning True in this function. - uid: - The unique ID for this connection. This is usually - 'ip:port'. + cid: + The unique ID for this connection (connection-id). client: The client info. Normally, you don't need this. host: @@ -51,15 +50,14 @@ """ pass - def connection_closed(self, uid, reason): + def connection_closed(self, cid, reason): """ Called when a connection with a client is closed. This can be when they closed their connection themselves, or when we disconnect someone. - uid: - The unique ID for this connection. This is usually - 'ip:port'. + cid: + The unique ID for this connection (connection-id). reason: A string, representing the reason why it disconnected. It currently has these options: @@ -101,14 +99,13 @@ """ pass - def data_received(self, uid, data): + def data_received(self, cid, data): """ Called when the server received data from one of the clients. Normally, you don't need this. - uid: - The unique ID for this connection. This is usually - 'ip:port'. + cid: + The unique ID for this connection (connection-id) This is a placeholder. If you want to catch this event, @@ -116,14 +113,13 @@ """ pass - def data_send(self, uid, data): + def data_send(self, cid, data): """ Called when the server send data to one of the clients. Normally, you don't need this. - uid: - The unique ID for this connection. This is usually - 'ip:port'. + cid: + The unique ID for this connection. (connectin-id) data: Dict with the data that will be send. Modified: trunk/server/core/database.sql =================================================================== --- trunk/server/core/database.sql 2009-12-14 19:48:14 UTC (rev 314) +++ trunk/server/core/database.sql 2009-12-14 21:22:34 UTC (rev 315) @@ -1,33 +1,10 @@ --- phpMyAdmin SQL Dump --- version 3.1.2deb1ubuntu0.2 --- http://www.phpmyadmin.net -- --- Host: localhost --- Generation Time: Dec 14, 2009 at 08:38 PM --- Server version: 5.0.75 --- PHP Version: 5.2.6-3ubuntu4.4 - -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - --- --- Database: `VP` --- - --- -------------------------------------------------------- - --- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL auto_increment COMMENT 'Also known as uid', `username` varchar(255) NOT NULL, - `password` varchar(40) NOT NULL COMMENT 'Password in sha1', + `password` varchar(40) NOT NULL COMMENT 'Password in double sha1', PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; +) ENGINE=MyISAM DEFAULT CHARSET=latin1; Modified: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py 2009-12-14 19:48:14 UTC (rev 314) +++ trunk/server/core/parser.py 2009-12-14 21:22:34 UTC (rev 315) @@ -15,7 +15,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import rsa +import rsa, sha class Parser(): def __init__(self, callback, server): @@ -29,18 +29,18 @@ self.db = self.server.database self.clients = self.server.clients - def __call__(self, uid, msg): - self.callback.data_received(uid, msg) + def __call__(self, cid, msg): + self.callback.data_received(cid, msg) head = msg.keys()[0] body = msg[head] func = getattr(self, str(head), None) if (func): - func(uid, body) + func(cid, body) - def login(self, uid, msg): + def login(self, cid, msg): """ Send when the users wants to log in usr - The username @@ -51,7 +51,7 @@ client - list with [app_name, app_version] """ - client = self.clients[uid] + client = self.clients[cid] data = client['con'] # Ignore when user is already logged in @@ -61,6 +61,9 @@ # Decrypt the password pwd = rsa.decrypt(msg['pwd'], client['rsa']) + # Double sha, so one can not insert "raw" sha + pwd = sha.new(pwd).hexdigest() + if msg['for'] == 'VP': self.db.execute(""" @@ -104,8 +107,8 @@ data.send("login", { "succeed": True, "username": user['username'], - "uid": uid, - "id": user['id'] + "cid": cid, + "uid": user['id'] }) else: # Client is bot Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2009-12-14 19:48:14 UTC (rev 314) +++ trunk/server/core/server.py 2009-12-14 21:22:34 UTC (rev 315) @@ -158,26 +158,26 @@ sock.close() continue - # Create unique user-id - uid = md5.new(addr[0] + str(addr[1])).hexdigest()[:8] - while uid in self.clients: - uid = md5.new(addr[0] + str(addr[1]) + + # Create unique client-id + cid = md5.new(addr[0] + str(addr[1])).hexdigest()[:8] + while cid in self.clients: + cid = md5.new(addr[0] + str(addr[1]) + str(random.random())).hexdigest()[:8] - self.clients[uid] = { + self.clients[cid] = { "status": "", - "con": Client(uid, sock, self.clients, + "con": Client(cid, sock, self.clients, self.__call, self.__parse, self.__config) } - if self.__call.connection_opened(uid, - self.clients[uid], *addr): + if self.__call.connection_opened(cid, + self.clients[cid], *addr): #User returned True -> drop user - self.clients[uid]['con'].close() + self.clients[cid]['con'].close() continue - self.clients[uid]['con'].start() + self.clients[cid]['con'].start() @@ -187,9 +187,9 @@ Each client has it's own class. """ - def __init__(self, uid, sock, clients, callback, parser, config): + def __init__(self, cid, sock, clients, callback, parser, config): - self.__uid = uid + self.__cid = cid self.__sock = sock self.__clients = clients self.__call = callback @@ -200,7 +200,7 @@ threading.Thread.__init__(self) def __repr__(self): - return '<Client(%s)>'%self.__uid + return '<Client(%s)>'%self.__cid def run(self): """ @@ -215,7 +215,7 @@ # rsa-key public, private = rsa.gen_pubpriv_keys( self.__config['rsa_bits']) - self.__clients[self.__uid]['rsa'] = private + self.__clients[self.__cid]['rsa'] = private self.send("rsa", {"public": public}) @@ -242,7 +242,7 @@ data = data[:-1] for msg in data: - self.__parser(self.__uid, + self.__parser(self.__cid, simplejson.loads(msg)) def close(self, reason = "manual"): @@ -257,9 +257,9 @@ except: pass self.__sock.close() - self.__call.connection_closed(self.__uid, reason) + self.__call.connection_closed(self.__cid, reason) - del self.__clients[self.__uid] + del self.__clients[self.__cid] def send(self, data_header, data_body = {}): """ @@ -268,7 +268,7 @@ (chr(1)) will be send automatically too. `data_header` is a string, `data_body` a dict. """ - self.__call.data_send(self.__uid, {data_header:data_body}) + self.__call.data_send(self.__cid, {data_header:data_body}) data = simplejson.dumps({data_header:data_body}) try: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |