Skip to content

Commit

Permalink
Merge pull request #312 from meejah/non-local-onion-services
Browse files Browse the repository at this point in the history
Non local onion services
  • Loading branch information
meejah authored Sep 26, 2018
2 parents 8e75f83 + b03c07d commit 46675a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ unreleased
* fix parsing of Unix-sockets for SOCKS
* better handling of concurrent Web agent requests before SOCKS ports
are known
* allow fowarding to ip:port pairs for Onion services when using the
"list of 2-tuples" method of specifying the remote vs local
connections.


v18.0.2
Expand Down
32 changes: 32 additions & 0 deletions test/test_onion.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,38 @@ def test_ephemeral_v3_no_key(self):
self.assertEqual(u"ADD_ONION NEW:ED25519-V3 Port=80,127.0.0.1:80 Flags=Detach", cmd)
d.callback("PrivateKey={}\nServiceID={}".format(_test_private_key_blob, _test_onion_id))

def test_ephemeral_v3_ip_addr_tuple(self):
protocol = FakeControlProtocol([])
config = TorConfig(protocol)

# returns a Deferred we're ignoring
EphemeralOnionService.create(
Mock(),
config,
ports=[(80, "192.168.1.2:80")],
detach=True,
version=3,
)

cmd, d = protocol.commands[0]
self.assertEqual(u"ADD_ONION NEW:ED25519-V3 Port=80,192.168.1.2:80 Flags=Detach", cmd)
d.callback("PrivateKey={}\nServiceID={}".format(_test_private_key_blob, _test_onion_id))

@defer.inlineCallbacks
def test_ephemeral_v3_ip_addr_tuple_non_local(self):
protocol = FakeControlProtocol([])
config = TorConfig(protocol)

# returns a Deferred we're ignoring
with self.assertRaises(ValueError):
yield EphemeralOnionService.create(
Mock(),
config,
ports=[(80, "hostname:80")],
detach=True,
version=3,
)

@defer.inlineCallbacks
def test_ephemeral_v3_wrong_key_type(self):
protocol = FakeControlProtocol([])
Expand Down
19 changes: 14 additions & 5 deletions txtorcon/onion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,11 +1311,20 @@ def _validate_ports(reactor, ports):
try:
local = int(local)
except ValueError:
if not local.startswith('unix:/'):
raise ValueError(
"local port must be either an integer"
" or start with unix:/"
)
if local.startswith('unix:/'):
pass
else:
if ':' not in local:
raise ValueError(
"local port must be either an integer"
" or start with unix:/ or be an IP:port"
)
ip, port = local.split(':')
if not _is_non_public_numeric_address(ip):
log.msg(
"'{}' used as onion port doesn't appear to be a "
"local, numeric address".format(ip)
)
processed_ports.append(
"{} {}".format(remote, local)
)
Expand Down

0 comments on commit 46675a8

Please sign in to comment.