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

TCPHiddenServiceEndpoint.listen not respecting local_port #347

Open
AdamISZ opened this issue Dec 29, 2020 · 1 comment
Open

TCPHiddenServiceEndpoint.listen not respecting local_port #347

AdamISZ opened this issue Dec 29, 2020 · 1 comment

Comments

@AdamISZ
Copy link

AdamISZ commented Dec 29, 2020

Hi,
I have previously used this codebase to start up ephemeral onion services with no issues, however I encountered an issue when using it to start a persistent onion service. In my torrc I have configured HiddenServicePort in the usual way; 80 for the public port, and a specific chosen port is entered (say 8080) for the local port.

When I ran a test using the example code, but setting my endpoint string like this:

"onion:80:controlPort=9051:localPort=8080:hiddenServiceDir=/my/hidserv/dir"

... I found that the local port is generated randomly, rather than being 8080. In the code for TCPHiddenServiceEndpoint.listen() it's clear why:

# XXX - perhaps allow the user to pass in an endpoint
# descriptor and make this one the default? Then would
# probably want to check for "is a local interface or not" and
# at *least* warn if it's not local...
self.tcp_endpoint = serverFromString(
self._reactor,
'tcp:0:interface=127.0.0.1',
)

The variable self.local_port was set in the constructor as intended (here, to 8080) but the string used in the serverFromString call just puts 0 so we get a fresh port. I verified that this could be fixed with something like:

        if self.local_port is None:
            serverstring = 'tcp:0:interface=127.0.0.1'
        else:
            serverstring = 'tcp:{}:interface=127.0.0.1'.format(self.local_port)
        self.tcp_endpoint = serverFromString(
            self._reactor,
            serverstring,
        )

... not that that is more than a testing patch, but just to concretize the point. It works fine after that (i.e. the hidden service is accessible).

@meejah
Copy link
Owner

meejah commented Apr 1, 2021

Thanks for the clear report! This does indeed sound like a bug.

(Sorry for the delay responding. I believe I now have a better way to pay attention to github notifications...)

If you're up for trying a PR, that'd be great!

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

No branches or pull requests

2 participants