A handshake implementation for a P2P node
- Based on ljedrz's pea2pea P2P node architecture.
- Uses the Elliptic Curve Diffie-Hellman key exchange, leveraging Rust's ring cryptographic primitives.
- Aims to keep things simple: only mandatory parameters are exchanged during the handhake, as explicitly required.
On any handshake we consider two participants:
- The initiator: The node that wants to join the network
- The responder: An existing peer in the network
The handshake process goes as follows:
- Both nodes have generated an ephemeral key pair for the session.
- The initiator generates a random salt and sends it along with its public key to the responder.
- The responder receives the salt and the initiator's public key, and responds with its own public key.
- The initiator receives the responder's public key.
- Both compute and store the shared secret that will allow them to talk to each other during the session.
Running cargo test
should run all tests that showcase the handshake works in multiple environments:
- Basic scenario with just two nodes.
- A linear topology consisting of 10 nodes.
- A mesh topology consisting of 10 nodes.
To ensure the handshake has indeed taken place we check the following:
- Both nodes have agreed on a common shared secret (and the secrets match)
- Nodes are sequentially connected and have agreed on a common shared secret only with the next node in the chain.
- All nodes have successfully connected to all other peers in the network.