【问题标题】:Proper Client <-> Server Communication正确的客户端 <-> 服务器通信
【发布时间】:2017-01-07 17:23:53
【问题描述】:

假设我有一个简单聊天室的客户端和服务器。

它们通过 JSON 字符串进行通信。

我了解以下示例不安全,但我只对这是一种有效的沟通方式感兴趣。

// The Client connects to the server.
// The Client sends a JSON string with the following variables to the server:
   --> Intention: "Request"
   --> Context: "Login"
   --> Message: "username:admin|password:123"
// The Server receives the JSON string and the string goes through an if-statement:
   --> if(Intention.Equals("Request")){...}else if(Intention.Equals("Response")){...}
// The Server now knows it's a Request and moves on to the next step.
   --> if(Context.Equals("Login")){.<check if user exists in server database and if the login details match>.}
// If the login details are correct, The Server marks the connected Client as logged in and sends a JSON string back to The Client:
   --> Intention: "Response"
   --> Context: "Login"
   --> Message: "OK"
// The Client receives the messages and sees it's OK, now the Client shows the user control panel and chatbox to the user which all send other Request JSON strings to The Server.
// Any other context than "Login" check if the Client actually is marked as logged in, if not, the server returns a response with "ERR_NOT_LOGGED_IN"

现在我有几个问题:

  1. 这是一种在客户端和服务器之间来回通信的有效/良好方式吗?
  2. 它有什么好处/坏处?
  3. 您对如何使沟通更好/更有效(内容方面)有什么建议吗?
  4. 如果这恰好是一家大公司的聊天服务器,并且密码不是以纯文本形式存储而是与私钥和公钥一起使用,那么还有什么大的安全漏洞?

我在问,因为我发现了很多关于客户端和服务器进行通信的 的好方法,而不是关于来回发送的实际 内容 p>

提前谢谢你!

【问题讨论】:

    标签: c# server client client-server communication


    【解决方案1】:

    正如你所说,这不是很安全。一些 MITM 可以破解连接,发送它的 owm 命令。所以为了确保安全,您应该尝试进行一些对称/非对称加密来保护内容并使用校验和来避免伪造消息

    回答您的问题:

    1. JSON 的开销比 XML 少,但 JSON 本身并不打算用作通信协议。 JSON 通常用于持久化一些数据,即配置、游戏中......一些信使也使用它们(至少是 API)
    2. 关于什么?好消息是,有一些小步骤可以实现自己的协议(通信)。不好:您传输的是纯文本(没有加密,没有校验和)。您可以将其用于某种 LAN 聊天
    3. 制作自己的协议,通过 Tcp 传输,使用 gzip 压缩流
    4. 只是加密对您没有帮助。为了证明收到的消息来自您的聊天伙伴而不是 MITM,您必须计算校验和,附加它,加密并发送它。只需阅读有关私有加密的内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 2011-09-05
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多