I am reasoning about the following scenario:
- A server listening on a port
- A client (always the same) that sends messages
When the server receive a message, it performs an action and then responds to client saying success or failure. The only requirements of this simple communications are integrity of client messages and authentication of the client. The simplest and fastest idea it came to my mind is to generate RSA keys on client side, then store permanently its public key on server side.
The client send messages with this structure
Pr{packet | hash(packet)} where packet is data | time. ( | means concatenation, Pr{abc} means abc encrypted with RSA by private key of client Pr )
The idea is to prevent replay attack with time, provide integrity check with hash(packet) and provide authentication by the means of the encryption with client private key.
Why am I using a custom protocol to do the job instead of TLS socket? Because data are a few bytes, for which I don't require strong symmetric encryption, so TLS handshake is too expensive for the goal. And more, as said the client is supposed to be always the same machine, and it must be the unique machine for which server accepts messages.