meejah / txtorcon

Twisted-based asynchronous Tor control protocol implementation. Includes unit-tests, examples, state-tracking code and configuration abstraction.
http://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/
MIT License
250 stars 72 forks source link

'twist web -p onion:80' doesn't always log the allocated .onion address #244

Closed warner closed 6 years ago

warner commented 7 years ago

Running twist web -p onion:80 --path . is a quick way to expose a directory to a newly-allocated .onion address. When you run this, txtorcon always launches a new Tor instance, and when the descriptor is published, it logs the new .onion address to twistd.log, so you can tell where to connect:

$ twist web -p onion:18832 --path src
...
2017-08-15T22:48:43-0700 [TorControlProtocol,client] 100% At least one descriptor uploaded.
2017-08-15T22:48:43-0700 [TorControlProtocol,client] Started hidden service port 18832
2017-08-15T22:48:43-0700 [TorControlProtocol,client]   listening on ewrfksney6ycxnhx.onion.onion

(the double .onion.onion is weird, and should be fixed, but that's not the point of this bug)

However, if you want to use a system Tor (e.g. on a linux box where Tor is already running), then you use something like -p "onion:80:controlPort=unix\:/var/run/tor/control". And in that case, the final listening on line is never printed, so there's no easy way to discover what address has been allocated:

$ twist web -p "onion:18832:controlPort=unix\:/var/run/tor/control" --path src
2017-08-15T22:50:42-0700 [-] Will delete "/tmp/tortmpD2k0_W" at shutdown.
2017-08-15T22:50:42-0700 [twisted.application.runner._runner.Runner#info] Starting reactor...
2017-08-15T22:50:43-0700 [TorControlProtocol,client] Site starting on 44173
2017-08-15T22:50:43-0700 [twisted.web.server.Site#info] Starting factory <twisted.web.server.Site instance at 0x7fe14f5ba368>
2017-08-15T22:50:43-0700 [TorControlProtocol,client] 100% Waiting for descriptor upload...
2017-08-15T22:51:18-0700 [TorControlProtocol,client] 100% At least one descriptor uploaded.
2017-08-15T22:51:18-0700 [TorControlProtocol,client] Started hidden service port 18832

I'm pretty sure I managed to trigger this case without appending the controlPort= clause (since I didn't remember that was even possible until meejah just reminded me of it), but I don't know what I might have done to cause it.

Maybe the print-the-address callback is only being attached to the Deferred chain in one of the (many) ways to launch a Tor daemon.

meejah commented 7 years ago

I have definitely seen this with controlPort=unix\:/var/run/tor/control so there's a bug somewhere for sure...

meejah commented 7 years ago

There's a missing log statement when failing to read the hostname.

In this case, though, it seems like there really is no hostname file to read (the tempdir it created is empty). I haven't seen anything obvious from Tor yet (it is uploading the descriptor though).

meejah commented 6 years ago

With a recent-ish Tor and lastest txtorcon I can't get the original issue to happen; if it's still a bug please re-open :)