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

Refactor Tor process handling and use control port #4501

Closed
1 of 4 tasks
molnard opened this issue Oct 6, 2020 · 17 comments
Closed
1 of 4 tasks

Refactor Tor process handling and use control port #4501

molnard opened this issue Oct 6, 2020 · 17 comments
Assignees
Projects

Comments

@molnard
Copy link
Collaborator

molnard commented Oct 6, 2020

Is your feature request related to a problem?

Tor process handling was written in the early stages of the software. Since then a lot of stuff happened and it is time to revisit Tor handling and what can be done with the control port.

Concept of steps

  • Execute Tor from the installation directory instead of copying it to datadir. Similarly like we do with hwi and bitcoind. Tor data-folder handled like before.

  • Use custom ports, Wasabi should always run it's own Tor instance.

  • Use the control port to ask the Tor instance to quit.

  • Unleash the power of the control port, make optimizations if possible, like checking Tor status on control port instead of trying to figure out the problem by checking exceptions in WasabiSynchronizer.

@kiminuo
Copy link
Collaborator

kiminuo commented Oct 6, 2020

Approach ACK.

I'm not sure about details, like:

Execute Tor from the installation directory instead of copying it to datadir.

Do you have writing permission there? I'm not sure probably yes, but it needs to be checked.

Use custom ports, Wasabi should always run it's own Tor instance.

Using own Tor is good to make implementation & testing easier. Not sure whether it has downsides. @lontivero and @nopara73 may probably know more about this subject.

@molnard
Copy link
Collaborator Author

molnard commented Oct 6, 2020

Approach ACK.

I'm not sure about details, like:

Execute Tor from the installation directory instead of copying it to datadir.

Do you have writing permission there? I'm not sure probably yes, but it needs to be checked.

The installer put the files there similarly like with hwi and bitcoind. From Wasabi we are not writing anything.

@nopara73
Copy link
Contributor

nopara73 commented Oct 6, 2020

Not sure whether it has downsides. @lontivero and @nopara73 may probably know more about this subject.

It adds an extra Tor layer on torified OSs like Tails or Whonix. Nothing biggie.

@molnard
Copy link
Collaborator Author

molnard commented Oct 14, 2020

@kiminuo can you take this from here?

@kiminuo
Copy link
Collaborator

kiminuo commented Oct 14, 2020

Yes.

@molnard
Copy link
Collaborator Author

molnard commented Oct 14, 2020

Sources to research:

@lontivero
Copy link
Collaborator

In this PR you can find a naive payjoin receiver implementation where I controlled Tor using the tor control port in order to create hidden services on the fly.


About Torino, it allows to create/list/destroy hidden services, listen for all kind of events, measure the bandwidth used by circuit/stream/total, stop/pause tor, get info tor (version, PID, user, auth method, etc), reload configuration, change/save configuration, change the guards among other things. It doesn't support cookie authentication (the one we should use) but I think it is a two lines of code change.


Use the control port to ask the Tor instance to quit.

This is not necessary because Tor will close automatically once the connection with the tor control port is closed. This is a very clever design and it is the behavior by default.

@PulpCattel
Copy link
Contributor

PulpCattel commented Nov 2, 2020

@nopara73

It adds an extra Tor layer on torified OSs like Tails or Whonix. Nothing biggie.

Tor over Tor is discouraged by both Tor and Whonix developers.

https://torproject.org/docs/faq.html.en#ChoosePathLength
https://whonix.org/wiki/DoNot#Allow_Tor_over_Tor_Scenarios

The TL;DR quotes:

We don't want to encourage people to use paths longer than this — it increases load on the network without (as far as we can tell) providing any more security.
[...]
Also, using paths longer than 3 could harm anonymity.

However, it is not guaranteed that the three additional hops received are different; the user could end up with the same hops, possibly in reverse or mixed order.
[...]
Therefore, Tor over Tor configurations are strongly discouraged.

A simple very bad example I can imagine is if, as sometimes happens, the onion service of the coordinator goes down and the clients start connecting to the clearnet site. In a Tor over Tor scenario a client could get his guard node also as exit node (the guard node of e.g., Whonix will turn out to be the same node used by Wasabi Tor as exit), which is kinda one of the worst possible thing for a Tor user.

There are not many users that use torified OSs, and Wasabi uses mostly onion services (which should alleviate some of the problems), but those users should have the option to opt-out and not use the Wasabi Tor instance.

@davidanthoff
Copy link

Use custom ports

I just took a bit of a look on how to do that, and my impression is that the "official" way to do this is as follows:

  • Start tor with SocksPorts auto, ControlPort auto and ControlPortWriteToFile SOME_TEMP_PATH where SOME_TEMP_PATH is some temporary filename.
  • Read the control port from the file that tor wrote to SOME_TEMP_PATH.
  • Connect to the control port.
  • Query tor for the SOCKS port via the control port command GETINFO.

The main benefit of this approach seems to be that one can't run into already used port issues ever because the ports to be used are not hard coded, but tor instead can always pick some ports that are free.

@nopara73
Copy link
Contributor

We should not use external Tor anymore, that leaves room for a bunch of issues. If we do that, then we can easily have control port. If we'll want to keep supporting external Tor, then that's problematic.

@nopara73
Copy link
Contributor

Also guys a few years ago I wrote a Tor control port implementation and even a CodeProject tutorial for it, feel free to check it out.

This is the Tor that eventually ended up in Wasabi.

@lontivero
Copy link
Collaborator

@davidanthoff yes, that's the way. In fact the process can be improved even a bit more:

  • Start tor with SocksPort auto, ControlPort auto, CookieAuthentication 1 and ControlPortWriteToFile SOME_TEMP_PATH
  • Read the control port from the file that tor wrote to SOME_TEMP_PATH.
  • Connect to the control port.
  • Query tor for the protocol info (authentication method & cookie file path) via the control port command GETINFO.
  • Read the control cookie file from protocolInfo.
  • Authenticate with it.

@kiminuo
Copy link
Collaborator

kiminuo commented Mar 31, 2021

@davidanthoff Do you plan to work on this? If so maybe kiminuo@43bb42d contains some useful bits too.

@kiminuo
Copy link
Collaborator

kiminuo commented May 11, 2021

btw: Does anyone know an answer for this: https://tor.stackexchange.com/questions/22342/how-to-correctly-read-the-control-port-when-tor-is-started-with-controlport-a/22380?

@davidanthoff friendly ping :)

@kiminuo
Copy link
Collaborator

kiminuo commented Sep 6, 2021

@molnard Is there anything left to do or can we close it?

@davidanthoff
Copy link

Sorry for not responding, too much other stuff going on. I won't have the bandwidth to work on this.

@kiminuo
Copy link
Collaborator

kiminuo commented Sep 8, 2021

Sorry for not responding, too much other stuff going on. I won't have the bandwidth to work on this.

No problem. Thanks for chiming in anyway!

I think this issue is solved now. Obviously, I have many ideas to improve it but the main task is done. Please re-open if I'm wrong.

@kiminuo kiminuo closed this as completed Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Valhalla
  
To do
Development

No branches or pull requests

6 participants