通过客户端和服务器保护命令

时间:2013-02-17 09:19:08

标签: php javascript security sockets websocket

我在Javascript中使用Fancy WebSockets与我的php服务器进行通信以进行多人游戏。

但是现在,我只是将原始套接字(json)发送为

Sending: {"command": "login", "data": {"id" : "1575","md5" : "6bd8937a8789a3e58489c4cfd514b1a7","username": "densortekat"}} index.php:58
Sending: {"command": "inroom"} index.php:58
Reciveing: {"command": "roombg","data" : "shop.png"} index.php:83
Reciveing: {"command" : "NEWUSER","data" : { "username" : "densortekat","seat_id" : "29","room_id" : "9"}} index.php:83
Sending: {"command" : "move", "data" : { "seat_id" : "53"}} index.php:58
Reciveing: {"command": "move", "data" : {"username" : "densortekat", "seat_id" : "53"}} index.php:83
Sending: {"command": "request_trade", "data" : "densortekat"} index.php:58
Reciveing: {"command":"trade", "data": {"username":"densortekat"}} index.php:83
Sending: {"command":"ping"} 

我的问题是,我怎么能从javascript到PHP以及PHP-> Javascript加密数据的方式相同,所以其他人看不到发生了什么?

2 个答案:

答案 0 :(得分:3)

请参阅html5 Websocket with SSL - 如果您的初始页面是HTTPS(SSL / TLS),那么它上面的网页框也是。

答案 1 :(得分:1)

您无法确定javascript是否已在客户端激活,但实际问题是,您无法知道您发送的数据&从服务器接收到客户端是由javascript处理而不是由用户处理。

作为恶意用户,我可以向您发送我自己伪造的数据,而不是由您的js代码计算的数据。没有办法从客户端接收带有任何证书的数据,说明“此数据是由受信任的js VM生成的,而不是由用户伪造/操纵”。