private-mode: reject legacy host:port locations

This commit is contained in:
Brian Warner 2016-09-02 09:25:26 -07:00
parent c17217699e
commit 0116c965fa
2 changed files with 17 additions and 1 deletions

View File

@ -373,7 +373,15 @@ class Node(service.MultiService):
for ip in local_addresses])
else:
if not self._reveal_ip:
hint_type = loc.split(":")[0]
# Legacy hints are "host:port". We use Foolscap's utility
# function to convert all hints into the modern format
# ("tcp:host:port") because that's what the receiving
# client will probably do. We test the converted hint for
# TCP-ness, but publish the original hint because that
# was the user's intent.
from foolscap.connections.tcp import convert_legacy_hint
converted_hint = convert_legacy_hint(loc)
hint_type = converted_hint.split(":")[0]
if hint_type == "tcp":
raise PrivacyError("tub.location includes tcp: hint")
new_locations.append(loc)

View File

@ -295,4 +295,12 @@ class Privacy(unittest.TestCase):
None, "tcp:hostname:1234")
self.assertEqual(str(e), "tub.location includes tcp: hint")
def test_tub_location_legacy_tcp(self):
n = FakeNode(BASECONFIG+"[node]\nreveal-IP-address = false\n")
n._portnumfile = "missing"
n.check_privacy()
e = self.assertRaises(PrivacyError, n.get_tub_portlocation,
None, "hostname:1234")
self.assertEqual(str(e), "tub.location includes tcp: hint")