I haven't been programming much lately, so I figured I would make an encrypted instant-messaging program (read: Skype clone) with groups to hone my skills. That's not important though, I can do that. The problem is that I know almost nothing about cryptography, so I figured I'd ask here so I don't discover down the road that my way of doing crypto is all wrong and I have to remake everything.
Here's my plan:
- When a client connects, it generates a keypair (or loads one from disk) and sends the public key off to the server.
- The server broadcasts the public keys of everyone in a group chat to everyone else.
- When a client sends a message, it encrypts (with NaCl's crypto_box) the message many times, once with each public key. Then it sends all of them off to the server, including information about which encrypted message goes to which client.
- The server simply forwards the messages to the recipients, and the recipient decrypts it with his own private key and the sender's public key (again with NaCl's crypto_box).
There will of course be authentication, so someone can't just send their public key to the server, pretending to be someone else.
I have no idea how secure that method is, or if it can even work. If this is not optimal, how would you do it?