You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
3.3 KiB

  1. # Secure P2P
  2. The Tendermint p2p protocol uses an authenticated encryption scheme
  3. based on the [Station-to-Station
  4. Protocol](https://en.wikipedia.org/wiki/Station-to-Station_protocol).
  5. Each peer generates an ED25519 key-pair to use as a persistent
  6. (long-term) id.
  7. When two peers establish a TCP connection, they first each generate an
  8. ephemeral X25519 key-pair to use for this session, and send each other
  9. their respective ephemeral public keys. This happens in the clear.
  10. They then each compute the shared secret, as done in a [diffie hellman
  11. key exhange](https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange).
  12. The shared secret is used as the symmetric key for the encryption algorithm.
  13. We then run [hkdf-sha256](https://en.wikipedia.org/wiki/HKDF) to expand the
  14. shared secret to generate a symmetric key for sending data,
  15. a symmetric key for receiving data,
  16. a challenge to authenticate the other party.
  17. One peer will send data with their sending key, and the other peer
  18. would decode it using their own receiving key.
  19. We must ensure that both parties don't try to use the same key as the sending
  20. key, and the same key as the receiving key, as in that case nothing can be
  21. decoded.
  22. To ensure this, the peer with the canonically smaller ephemeral pubkey
  23. uses the first key as their receiving key, and the second key as their sending key.
  24. If the peer has the canonically larger ephemeral pubkey, they do the reverse.
  25. Each peer also keeps a received message counter and sent message counter, both
  26. are initialized to zero.
  27. All future communication is encrypted using chacha20poly1305.
  28. The key used to send the message is the sending key, and the key used to decode
  29. the message is the receiving key.
  30. The nonce for chacha20poly1305 is the relevant message counter.
  31. It is critical that the message counter is incremented every time you send a
  32. message and every time you receive a message that decodes correctly.
  33. Each peer now signs the challenge with their persistent private key, and
  34. sends the other peer an AuthSigMsg, containing their persistent public
  35. key and the signature. On receiving an AuthSigMsg, the peer verifies the
  36. signature.
  37. The peers are now authenticated.
  38. The communication maintains Perfect Forward Secrecy, as
  39. the persistent key pair was not used for generating secrets - only for
  40. authenticating.
  41. ## Caveat
  42. This system is still vulnerable to a Man-In-The-Middle attack if the
  43. persistent public key of the remote node is not known in advance. The
  44. only way to mitigate this is with a public key authentication system,
  45. such as the Web-of-Trust or Certificate Authorities. In our case, we can
  46. use the blockchain itself as a certificate authority to ensure that we
  47. are connected to at least one validator.
  48. ## Config
  49. Authenticated encryption is enabled by default.
  50. ## Specification
  51. The full p2p specification can be found [here](https://github.com/tendermint/tendermint/tree/master/docs/spec/p2p).
  52. ## Additional Reading
  53. - [Implementation](https://github.com/tendermint/tendermint/blob/64bae01d007b5bee0d0827ab53259ffd5910b4e6/p2p/conn/secret_connection.go#L47)
  54. - [Original STS paper by Whitfield Diffie, Paul C. van Oorschot and
  55. Michael J.
  56. Wiener](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.216.6107&rep=rep1&type=pdf)
  57. - [Further work on secret
  58. handshakes](https://dominictarr.github.io/secret-handshake-paper/shs.pdf)