I'm writing a module that creates a secure communication channel using ZeroMQ sockets and Pycryptodome.
The initial handshake between client and server would follow these steps :
- Both parties send their public RSA key to each other.
- The server generates an AES session key and a signature for that key.
- The server RSA-encrypts the session key and the signature before sending it to the client. (*)
- The client verifies the signature and stores the session key.
- The client generates a token, generates its signature and sends both AES-encrypted to the server.
- The server verifies the signature and echoes back the token.
- If the token received matches the one sent, the handshake is considered successful.
I found on this thread that it was preferable to sign the message then encrypt it, rather than encrypting then signing it.
The problem is that the signature, for a 2048 bits RSA key, is 256 bytes long. The maximum encryption size for the same key is 190 bytes. This means I can't encrypt the signature as suggested in the thread.
Should I encrypt the signature with the AES session key ? Should I proceed another way ?
I know there are "standardized" key exchange protocols (ECDH for example) but they are not available in Pycryptodome yet.
Cipher: RSA PKCS1 OAEP
Signing : PKCS1 PSS w/ BLAKE2b hash