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.

105 lines
4.2 KiB

7 years ago
  1. # Tendermint Peers
  2. This document explains how Tendermint Peers are identified, how they connect to one another,
  3. and how other peers are found.
  4. ## Peer Identity
  5. Tendermint peers are expected to maintain long-term persistent identities in the form of a private key.
  6. Each peer has an ID defined as `peer.ID == peer.PrivKey.Address()`, where `Address` uses the scheme defined in go-crypto.
  7. Peer ID's must come with some Proof-of-Work; that is,
  8. they must satisfy `peer.PrivKey.Address() < target` for some difficulty target.
  9. This ensures they are not too easy to generate.
  10. A single peer ID can have multiple IP addresses associated with - for simplicity, we only keep track
  11. of the latest one.
  12. When attempting to connect to a peer, we use the PeerURL: `<ID>@<IP>:<PORT>`.
  13. We will attempt to connect to the peer at IP:PORT, and verify,
  14. via authenticated encryption, that it is in possession of the private key
  15. corresponding to `<ID>`. This prevents man-in-the-middle attacks on the peer layer.
  16. Peers can also be connected to without specifying an ID, ie. `<IP>:<PORT>`.
  17. In this case, the peer cannot be authenticated and other means, such as a VPN,
  18. must be used.
  19. ## Connections
  20. All p2p connections use TCP.
  21. Upon establishing a successful TCP connection with a peer,
  22. two handhsakes are performed: one for authenticated encryption, and one for Tendermint versioning.
  23. Both handshakes have configurable timeouts (they should complete quickly).
  24. ### Authenticated Encryption Handshake
  25. Tendermint implements the Station-to-Station protocol
  26. using ED25519 keys for Diffie-Helman key-exchange and NACL SecretBox for encryption.
  27. It goes as follows:
  28. - generate an emphemeral ED25519 keypair
  29. - send the ephemeral public key to the peer
  30. - wait to receive the peer's ephemeral public key
  31. - compute the Diffie-Hellman shared secret using the peers ephemeral public key and our ephemeral private key
  32. - generate nonces to use for encryption
  33. - TODO
  34. - all communications from now on are encrypted using the shared secret
  35. - generate a common challenge to sign
  36. - sign the common challenge with our persistent private key
  37. - send the signed challenge and persistent public key to the peer
  38. - wait to receive the signed challenge and persistent public key from the peer
  39. - verify the signature in the signed challenge using the peers persistent public key
  40. If this is an outgoing connection (we dialed the peer) and we used a peer ID,
  41. then finally verify that the `peer.PubKey` corresponds to the peer ID we dialed,
  42. ie. `peer.PubKey.Address() == <ID>`.
  43. The connection has now been authenticated. All traffic is encrypted.
  44. Note that only the dialer can authenticate the identity of the peer,
  45. but this is what we care about since when we join the network we wish to
  46. ensure we have reached the intended peer (and are not being MITMd).
  47. ### Peer Filter
  48. Before continuing, we check if the new peer has the same ID has ourselves or
  49. an existing peer. If so, we disconnect.
  50. We also check the peer's address and public key against
  51. an optional whitelist which can be managed through the ABCI app -
  52. if the whitelist is enabled and the peer is not on it, the connection is
  53. terminated.
  54. ### Tendermint Version Handshake
  55. The Tendermint Version Handshake allows the peers to exchange their NodeInfo, which contains:
  56. ```
  57. type NodeInfo struct {
  58. PubKey crypto.PubKey `json:"pub_key"`
  59. Moniker string `json:"moniker"`
  60. Network string `json:"network"`
  61. RemoteAddr string `json:"remote_addr"`
  62. ListenAddr string `json:"listen_addr"` // accepting in
  63. Version string `json:"version"` // major.minor.revision
  64. Channels []int8 `json:"channels"` // active reactor channels
  65. Other []string `json:"other"` // other application specific data
  66. }
  67. ```
  68. The connection is disconnected if:
  69. - `peer.NodeInfo.PubKey != peer.PubKey`
  70. - `peer.NodeInfo.Version` is not formatted as `X.X.X` where X are integers known as Major, Minor, and Revision
  71. - `peer.NodeInfo.Version` Major is not the same as ours
  72. - `peer.NodeInfo.Version` Minor is not the same as ours
  73. - `peer.NodeInfo.Network` is not the same as ours
  74. At this point, if we have not disconnected, the peer is valid and added to the switch,
  75. so it is added to all reactors.
  76. ### Connection Activity