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.

79 lines
3.3 KiB

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