簡體   English   中英

正確的客戶端<->服務器通信

[英]Proper Client <-> Server Communication

假設我有一個用於簡單聊天室的客戶端和服務器。

它們通過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. 如果這恰好是大公司的聊天服務器,並且密碼不是以純文本形式存儲,而是與私鑰和公鑰一起使用,那么還有什么大的安全漏洞?

我之所以問是因為,我發現了很多有關客戶端和服務器進行通信的好方法 ,但沒有找到來回發送的實際內容

先感謝您!

如您所說,這不是很安全。 一些MITM可能會破解連接,發送其owm命令。 因此,為了確保安全,您應該嘗試進行一些對稱/不對稱加密以保護內容並使用校驗和以避免偽造的消息

要回答您的問題:

  1. JSON比XML具有更少的開銷,但是JSON本身並不打算用作通信協議。 JSON通常用於在游戲中持久保存某些數據(例如配置),...一些Messenger也使用它們(至少API)。
  2. 關於什么? 好消息是,自己的協議(通信)有一些小步驟。 錯誤:您傳輸的是純文本(沒有加密,沒有校驗和)。 您可以使用它進行某種局域網聊天
  3. 制作自己的協議,通過Tcp傳輸,使用gzip壓縮流
  4. 只是被加密對您沒有幫助。 為了證明此收到的消息是來自您的聊天伙伴而不是來自MITM,您必須計算一個校驗和,將其附加,加密並發送。 只需閱讀一些有關私人加密的內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM