From 0116c965fa2374ba5f9ae424556bf634ff49a545 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 2 Sep 2016 09:25:26 -0700 Subject: [PATCH] private-mode: reject legacy host:port locations --- src/allmydata/node.py | 10 +++++++++- src/allmydata/test/test_connections.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/allmydata/node.py b/src/allmydata/node.py index a2bedb0d9..d9065501f 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -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) diff --git a/src/allmydata/test/test_connections.py b/src/allmydata/test/test_connections.py index f0e0b0f73..4398da930 100644 --- a/src/allmydata/test/test_connections.py +++ b/src/allmydata/test/test_connections.py @@ -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") +