Search code examples
javascriptdatabaseclient-servercryptographyscoring

Safest way to update game score from client to server database? Javascript


So I have this game that is completely run on the client. No server interaction what so ever apart from downloading the initial scripts to play the game. Anyway at the end of the game I would like for the client to send me back the scores which should be updated in the server database. Now I have come to accept the fact that there is no way on earth I can hide this from a hacker and send the scores unaltered. But I would like to know till what level can I modify the whole process that it virtually becomes pretty infeasible for the hacker manipulate the data which is being sent. For sure I would not like the score to be sent as plain text from client machine and I don't want my server to perform complex decryption algorithm. What is the best way hence to achieve considerable amount of security that every tom dick and harry doesn't hack the scores... I hope someone could provide a nice little way that I could work on... :) Thanks

So my ideal result should be -> have trusted result from a calculation (of score) made by an untrusted party (the player)!

-Edit-

Someone told me something about hiding the data in a picture get request. Like, I am implementing this game on canvas (html5). So he asked me at the end of the game to fetch a game over image from my server, and they request should contain the hashed score. I did not exactly understand the complete process but if you could explain it, would be really glad! :)

coda^ so you can mask the requests nicely

shouvik how do I do it!?

coda^ you can compose the checksum you want to submit. like 12312312a12313a232 is your md5 which contains the score. bring in an asset into the canvas like

coda^ server.com/images/md5_hash_of_score/congratulations.png

coda^ which you can rewrite server side via htaccess


Solution

  • "Now I have come to accept the fact that there is no way on earth I can hide this from a hacker and send the scores unaltered."

    Oh yes, there is!

    You can use RSA or any other public key encryption method (also called assymetric cryptography).

    Create a set of (public and private) keys for the server. Have your client code include your server's public key.

    At the end of the game, the client code, encrypts the score (with this key) and sends both (plain score and encrypted score) to server.

    Server decrypts and checks if plain score and decrypted one are same. If yes, accept score. If not, reject (there's a hacker or network error in the middle).

    -------UPDATE-----------CORRECTION--------------

    As Ambrosia, pointed out, my approach fails completely with this kind of attack.

    What you actually want is to have a trusted result from a calculation (of score) made by an untrusted party (the player). No easy way to achieve this.

    See this: http://coltrane.wiwi.hu-berlin.de/~fis/texts/2003-profit-untrust.pdf

    Also this one: http://www.cse.psu.edu/~snarayan/publications/securecomputation.pdf

    And this (which needs a subscription to the ACM digital library): http://portal.acm.org/citation.cfm?id=643477.643479