正确的客户端<->服务器通信

问题描述 投票:0回答:1

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

它们通过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. 如果这恰好是大公司的聊天服务器,并且密码不是以纯文本形式存储,而是与私钥和公钥一起使用,那么还有什么大的安全漏洞?

我之所以问是因为,我发现了很多有关客户端和服务器进行通信的好方法 ,但没有找到来回发送的实际内容

先感谢您!

c# server client client-server communication
1个回答
0
投票

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

要回答您的问题:

  1. JSON比XML具有更少的开销,但是JSON本身并不打算用作通信协议。 JSON通常用于在游戏中持久保存某些数据(例如配置),...一些Messenger也使用它们(至少API)。
  2. 关于什么? 好消息是,自己的协议(通信)有一些小步骤。 错误:您传输的是纯文本(没有加密,没有校验和)。 您可以使用它进行某种局域网聊天
  3. 制作自己的协议,通过Tcp传输,使用gzip压缩流
  4. 只是被加密对您没有帮助。 为了证明此收到的消息是来自您的聊天伙伴而不是来自MITM,您必须计算一个校验和,将其附加,加密并发送。 只需阅读一些有关私人加密的内容
© www.soinside.com 2019 - 2024. All rights reserved.