I'm creating an anonymous chat where one of the premises is that the conversations are end to end encrypted. I'm using firebase so all the comunication between the clients and the server is SSL secured. But I'm trying to hide chat even from the server.
Here is the algorithm:
- The user Alice wants to chat with Bob.
- Alice generates a public/private key pair and send its public key to Bob.
- Bob accepts the chat by generating a public/private keys and sends the public part to Alice.
- Now the server and the users know both public keys.
- Alice, who is the user that initiated the chat, generate a symmetric key, encrypt it with Bob public key.
- Since any other user could encrypt this key and send it with bob, Alice also send the encrypted message hash encrypted with its private key, so Bob can verify that it was Alice who generated the key.
- Alice sends the message (symmetric key encrypted + digital signature) to Bob.
- First, Bob decrypt the digital signature with Alice public key and compare to the encrypted message, if they don't check, the chat fails.
- Bob decrypt the symmetric key with its private key.
- Now Bob and Alice have the same symmetric key and Bob is sure that it was Alice who generated this key.
Is this algorithm correct?