I'm attempting to develop my messanging app with encryption evolved. For now I came up with algorithm for authorization and message exchange.
P.S. conneciton between server and client is over https
Auth:
- User generates his private and public key based on his password
- User requests authorization
- Server generates random 64 bytes string
- Server encrypts string with user’s public key, that was stored in database
- Server sends challenge to user. Challenge is encrypted string
- Client decrypts challenge with his private key
- Client sends server decrypted string
- Server compares string, if they match user is authorized and granted permissions to exchange messages and/or view old messages
Exchange:
- User #1 requests User #2 public key
- Server responds with User #2 public key
- User #1 encrypts message with User #2 public key
- User #1 generates a signature based on User #2 username and message body
- User #1 encrypt signature with his private key
- User #1 encrypt message with User #1 public key
- User #1 generate a signature based on his password and message body
- User #1 sends server a message encrypted with User #2 public key
- User #1 sends server a signature for message to User #2
- User #1 sends server a message encrypted with User #1 public key
- User #1 sends server a signature for message encrypted with his public key
In this case server doesn't user's password, therefore is unable to generate private key. But if someone will have access to the server he can perform attack by faking someone's public keys and therefore will be able to decrypt messages.
- Server generates fake keys for User #1
- User #2 requests User #1 public key
- Server responds with fake public key
- … User #2 encrypts message …
- Server retrieves message and is able to decrypt them
So, how can I verify that keys were not faked by the server? I was thinking about user when signing up generating secret string, doing some encryption with it, so server cannot decrypt it and recipient should verify that secret string was used to generate keys without actually knowing secret and private key. But I have no idea how this can be done.