DEV Community

Discussion on: How to implement WhatsApp like End-to-end encryption?

 
anduser96 profile image
Andrei Gatej

Never head of Diffie–Hellman before, thanks for mentioning it, this discussion made me want to explore cryptography more in depth in the future.

Yeah, there must be a lot of interesting details behind the scenes. One of my career goals is to work on projects of such scale, imagine how many cool things one could learn!

Regarding the last paragraph, that is a very good question. I'm not sure about this approach, but since there is no other active connection from an existing member(which basically means that the new user is alone there), I suppose we could still encrypt messages with the public key of the group and temporarily store these encrypted messaged on the server. Then, when any of the existing members(apart from this new one) comes back online, we can now:

  • send the temporarily stored messages to the already existing members which are online, and they can decrypt them since they have the private key of the group
  • apply the same logic as if there was at least one active connection when the new user joined, so now they will have the initial private key of the group

I guess this explains why as a new member of a group, you can't see any of the group history: messages, photos etc, because if you're a new user and there is no other existing member online, you can't get the private key of the group immediately, so you can't see the history of that group. What would you say?

Thread Thread
 
pankajtanwarbanna profile image
Pankaj Tanwar

That's a really smart approach, Andrei. We can store the message temporarily on the server with the public key and everything works smooth and that's why we are not able to see the previous message/history of the group.

But let's say, WhatsApp wants to add this feature of showing history of the group too, when a new user joins the group. How would you go about this? I could not think of a work around for it. Would you like to add you thoughts here?

Thread Thread
 
anduser96 profile image
Andrei Gatej

I don't think there is a way to solve this with the current approach. That's because if a new member joins and none of the other members is active, then it's impossible to get that private key of the group, so you can't decrypt the messages.

Moreover, I read that Discord does not use E2EE, so this might be a reason why you can see previous messages when you join a group there.

Thread Thread
 
pankajtanwarbanna profile image
Pankaj Tanwar

Yes, Discord & Telegram has developed their own smart algorithms to deal with such use cases. Do you have any documentation or article related to Discord's implementation for this?

Thread Thread
 
anduser96 profile image
Andrei Gatej

Sorry for the late reply. No, I just did a quick search to see whether Discord is using such feature or not. But I'd be glad to read more about it too.

Thread Thread
 
pankajtanwarbanna profile image
Pankaj Tanwar

I am also searching a bit. I will let you know if I find something. Thank you for such a useful conversation. Hope to learn more from you.