聊天应用程序的端到端加密

End-to-End encryption for a chat application

我正在尝试构建一个 android 聊天应用程序,仅用于教育目的。我想尝试实施 端到端加密 以便我的消息安全。我想到了使用 RSA 作为加密方案(我是密码学领域的新手)

这就是我认为我应该做的,

Step 1: Generate public and private key in the Client and Server sides.

Step 2: Exchange the public keys. (This means that server will have the public key of each and every client).

Step 3: Encrypt the message using the public key of the Server and send to Server or vice-versa.

Step 4: The Server can then use its private key to decrypt the message.

所以我的问题是,

  1. How am I to store the private keys?
  2. What are the drawbacks of this approach?
  3. How should this actually be implemented?

请帮我理清这个概念

您描述的是不是端到端加密。

端到端意味着两个端点(客户端)之间的通信是加密的。整个想法是服务器永远无法读取或修改对话数据。

我主要回答你最后一个问题,因为这可能是最相关的一个:

How should this actually be implemented?

您要实现的目标是让对话伙伴共享相同的密钥。普遍接受的方法是使用(椭圆曲线)Diffie-Hellman key exchange. After we have established a shared secret, we can start communicating between the clients using a suitable AEAD scheme.

请注意,这仍然容易受到中间人攻击,因此我们需要一种带外方法来验证两个客户端实际上共享相同的密钥。这通常是通过手动比较键的散列值 (example: Signal).

来完成的

所以基本上服务器只充当客户端的中继。无论如何,使用 TLS 与服务器连接仍然是个好主意。

请注意,我们没有考虑以下主题:

  • 前向保密(通过重新输入密钥)
  • 重播攻击
  • 客户的匿名性
  • 冒充其他客户
  • 等等

最后,你真的想要实施一个像OMEMO or Axolotl这样经过彻底审查的协议,但我想这对于教育来说太牵强了项目.