Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement BEP-42: DHT Security extension #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

joel-su
Copy link
Contributor

@joel-su joel-su commented Dec 16, 2018

This change implements BEP-42.

  • Decode the "ip" field in replies' top-level dictionnary
  • Implement a simple voting system for selecting the external IP address that will be used to compute the node id's prefix
  • Add a CRC32C implementation to compute the node id's prefix.
  • Include an "ip" field when replying to other nodes

Whenever the voting process terminates, we directly update the myid variable with the new prefix, the ID change will automatically be reflected in all new requests.

edit: some cleanups, split the change in multiple independent commits, add the enforcement (disabled by default).

@joel-su
Copy link
Contributor Author

joel-su commented Dec 20, 2018

@jech

Add the compute_prefix function to compute the 21bit prefix of a node ID from
its IP address.
Add a voting system to reliably discover our node's external IP address.
Once the node's external IP address has been reliably established, compute
the prefix and reset current node ID.
Do not accept a get_peer search response if the node ID prefix does not match
its external IP address.

Introduce DHT_BEP42_ENFORCE macro to enable enforcement (disabled by default).
@jech
Copy link
Owner

jech commented Jan 3, 2019

Your patch series looks good. The only thing I don't understand is what happens when the (external) IP address changes.

What's more, I'm not convinced that BEP-42 is a good idea: in IPv4, it implies that there can be only one DHT node behind a NAT, which breaks the DHT for e.g. multiple family members sharing an IP, or people suck behind a CGNAT. In IPv6, it's even worse — it prevents multiple nodes on a single /64.

Am I missing something?

@joel-su
Copy link
Contributor Author

joel-su commented Jan 6, 2019

@jech

Your patch series looks good. The only thing I don't understand is what happens when the (external) IP address changes.

With bep-42, your external IP address, as seen by other nodes of the network, is returned to you in a top-level "ip" field of each replies. If the address changes, the value contained in "ip" changes. Once the node has received enough replies with the same ip value, it regards the value as it's new external IP address and then recompute the node ID prefix.

What's more, I'm not convinced that BEP-42 is a good idea: in IPv4, it implies that there can be only one DHT node behind a NAT, which breaks the DHT for e.g. multiple family members sharing an IP, or people suck behind a CGNAT. In IPv6, it's even worse — it prevents multiple nodes on a single /64.

I'm quite unfamiliar with IPv6 so I cannot comment on that. However, bep-42 only restricts the first 21 most significant of the 160 bits of the node-id, which means that as much as 2^139 nodes can run behind a NAT. Besides, for each "external" IP address, there are 8 possible prefixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants