I am building a secured messaging app for android mostly as a learning experience. The app will allow encrypted communication between one or more people, where the server will never be able to see the message content in plain text.
Below is an example of my protocol, I would like opinions on if it is suitable or a terrible way of doing it, as I am only learning cryptography best practices.
Below we have client A and B, A wishes to communicate with B privately
- A & B handshake with server when they come online
- Server sends A & B its RSA public key (RSA 2048 bit updated regularly)
- Clients A & B generate a key pair each, encrypt their public keys and send to server
- Client A packs the message, recipient(B), its public key, meta data and a hash of the servers publickey + this packet
- Client encrypts all of this using servers public key and sends to server
- Server decrypts, reads recipient address, checks hash, then re encrypts the packet with B's public key and sends
- B decrypts message
I'm not sure if this is secure, the reason for double encryption is to make it harder for MITM attacks to get A or B's public key so they could falsely send messages or intercept anything of value.
Any opinions as to a better way of doing it, or suggested improvements?