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

[Tor] Towards Whonix & Tails (take 2) #12991

Merged
merged 3 commits into from May 14, 2024

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented May 7, 2024

Contributes to #12848
Alternative to #12979

This PR changes --UseTor command line option to be the following enum:

/// <summary>
/// Modes for how we interact with Tor.
/// </summary>
public enum TorMode
{
	/// <summary>Tor is disabled. Clearnet is used instead.</summary>
	[FriendlyName("Disabled")]
	Disabled,

	/// <summary>Use running Tor or start a new Tor process if it is not running.</summary>
	/// <remarks>In this mode, Wasabi app is the owner of its Tor process.</remarks>
	[FriendlyName("Enabled")]
	Enabled,

	/// <summary>Use only running Tor process.</summary>
	/// <remarks>
	/// In this mode, Wasabi app is not the owner of its Tor process
	/// <para>Useful for distributions like Whonix or Tails where starting a new Tor process is not a good option.</para>
	/// </remarks>
	[FriendlyName("Enabled (connect-only mode)")]
	EnabledConnectToRunning,
}
  • WW2 should be compatible with Whonix or Tails1 then because it is not possible to spin up a new Tor instance in these distributions because Tor-over-Tor problem would occur.
  • To facilitate this, --UseTor=EnabledConnectToRunning does not rely on Tor control port2.

UX

In the UI settings, it looks like this then:

image

How to test

On master branch, start WW, disable "terminate Tor on exit" in settings, start WW again and turn it off -> you should have a Tor process running on port 37150

On the PR's branch, connect to TorSocksPort=37150 and set a made up port for TorControlPort to make sure it CANNOT be used.

dotnet build && dotnet run --framework net8.0 -- --TorSocksPort=37150 --TorControlPort=63999 --UseTor=EnabledOnlyRunning

You should be able to do a coinjoin or just use your wallet normally without a hiccup.

Footnotes

  1. That was a goal for a long time.

  2. It seems it works but the cost is that we do not use TorMonitor.

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from 64b9fe7 to f86a4dd Compare May 7, 2024 12:50
yahiheb

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch 3 times, most recently from d3307b9 to b173d8c Compare May 8, 2024 15:14
@kiminuo

This comment was marked as outdated.

@kiminuo

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@kiminuo

This comment was marked as outdated.

@kiminuo

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from b173d8c to 73b61e4 Compare May 9, 2024 10:49
@kiminuo

This comment was marked as outdated.

@yahiheb

This comment was marked as outdated.

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from 73b61e4 to 79e407e Compare May 9, 2024 19:22
@kiminuo
Copy link
Collaborator Author

kiminuo commented May 9, 2024

In the latest version of the PR, when I set an invalid TorSocksPort, I can see:

2024-05-10 06:20:06.128 [9] DEBUG       TorProcessManager.StartAsync (87)       Attempt #1 to start Tor.
2024-05-10 06:20:08.185 [9] DEBUG       TorProcessManager.StartAsync (87)       Attempt #2 to start Tor.
2024-05-10 06:20:20.243 [7] DEBUG       TorProcessManager.StartAsync (87)       Attempt #3 to start Tor.
2024-05-10 06:20:32.298 [11] TRACE      Global.InitializeNoWalletAsync (271)    Initialization finished.
2024-05-10 06:20:32.300 [1] TRACE       TerminateService.Terminate (145)        Terminate was called from ThreadId: 1
2024-05-10 06:20:32.301 [1] DEBUG       TerminateService.Terminate (157)        Start shutting down the application.

Copy link
Collaborator

@yahiheb yahiheb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If UseTor=EnabledOnlyRunning and no Tor is already running Wasabi is kinda stuck, Tor is not running, the backend is not connected, and the wallet cannot be loaded.

Now Wasabi crashes: System.InvalidOperationException: No attempt to start Tor was successful.

Logs
2024-05-11 22:35:19.256 [1] INFO        WasabiApplication.BeforeStarting (85)   Wasabi GUI started (6f4ee334-6570-45e3-903f-541f6523600c).
2024-05-11 22:35:20.474 [1] INFO        FileSystemBlockRepository.Prune (78)    Blocks folder was over 300 MB. Deleted 279 blocks.
2024-05-11 22:35:20.885 [1] INFO        P2pNetwork..ctor (55)   Loaded AddressManager from `C:\Users\User\AppData\Roaming\WalletWasabi\Client\BitcoinP2pNetwork\AddressManagerTestNet.dat`.
2024-05-11 22:35:21.423 [1] INFO        Program.RunAsGuiAsync (166)     Wasabi GUI started.
2024-05-11 22:35:22.967 [12] WARNING    SpecificNodeBlockProvider.ReconnectingLoopAsync (135)   Failed to establish a connection to the node '127.0.0.1:18333'. Exception: System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at NBitcoin.Protocol.Connectors.DefaultEndpointConnector.ConnectSocket(Socket socket, EndPoint endpoint, NodeConnectionParameters nodeConnectionParameters, CancellationToken cancellationToken)
   at NBitcoin.Protocol.Node.ConnectAsync(Network network, EndPoint endpoint, NetworkAddress peer, NodeConnectionParameters parameters)
   at WalletWasabi.Wallets.SpecificNodeBlockProvider.ConnectAsync(CancellationToken cancellationToken) in WalletWasabi\Wallets\SpecificNodeBlockProvider.cs:line 193
   at WalletWasabi.Wallets.SpecificNodeBlockProvider.ReconnectingLoopAsync() in WalletWasabi\Wallets\SpecificNodeBlockProvider.cs:line 101
2024-05-11 22:35:49.398 [14] INFO       WasabiApplication.TerminateApplicationAsync (132)       Wasabi GUI stopped gracefully (6f4ee334-6570-45e3-903f-541f6523600c).
2024-05-11 22:35:49.401 [14] WARNING    Global.DisposeAsync (438)       Process is exiting.
2024-05-11 22:35:49.403 [14] INFO       Global.DisposeAsync (447)       WalletManager is stopped.
2024-05-11 22:35:49.404 [14] INFO       Global.DisposeAsync (455)       UpdateManager is stopped.
2024-05-11 22:35:49.407 [14] INFO       Global.DisposeAsync (469)       BlockDownloadService is disposed.
2024-05-11 22:35:49.409 [8] INFO        Global.DisposeAsync (475)       SpecificNodeBlockProvider is disposed.
2024-05-11 22:35:49.409 [8] INFO        Global.DisposeAsync (487)       Disposed LegalChecker.
2024-05-11 22:35:49.411 [14] INFO       HostedServices.StopAllAsync (89)        Stopped Wasabi Synchronizer.
2024-05-11 22:35:49.411 [12] INFO       HostedServices.StopAllAsync (89)        Stopped Software Update Checker.
2024-05-11 22:35:49.492 [8] INFO        P2pNetwork.StopAsync (160)      AddressManager is saved to `C:\Users\User\AppData\Roaming\WalletWasabi\Client\BitcoinP2pNetwork\AddressManagerTestNet.dat`.
2024-05-11 22:35:49.495 [12] INFO       HostedServices.StopAllAsync (89)        Stopped Bitcoin P2P Network.
2024-05-11 22:35:49.495 [14] INFO       HostedServices.StopAllAsync (89)        Stopped Blockstream.info Fee Provider.
2024-05-11 22:35:49.497 [14] INFO       HostedServices.StopAllAsync (89)        Stopped Third Party Fee Provider.
2024-05-11 22:35:49.498 [14] INFO       HostedServices.StopAllAsync (89)        Stopped Hybrid Fee Provider.
2024-05-11 22:35:49.498 [8] INFO        HostedServices.StopAllAsync (89)        Stopped Unconfirmed Transaction Chain Provider.
2024-05-11 22:35:49.499 [8] INFO        HostedServices.Dispose (148)    Disposed Wasabi Synchronizer.
2024-05-11 22:35:49.499 [8] INFO        HostedServices.Dispose (148)    Disposed Software Update Checker.
2024-05-11 22:35:49.500 [8] INFO        HostedServices.Dispose (148)    Disposed Bitcoin P2P Network.
2024-05-11 22:35:49.500 [8] INFO        HostedServices.Dispose (148)    Disposed Blockstream.info Fee Provider.
2024-05-11 22:35:49.500 [8] INFO        HostedServices.Dispose (148)    Disposed Third Party Fee Provider.
2024-05-11 22:35:49.501 [8] INFO        HostedServices.Dispose (148)    Disposed Unconfirmed Transaction Chain Provider.
2024-05-11 22:35:49.501 [8] INFO        Global.DisposeAsync (495)       Stopped background services.
2024-05-11 22:35:49.501 [8] INFO        Global.DisposeAsync (499)       Disposed RoundStateUpdaterCircuit.
2024-05-11 22:35:49.503 [14] INFO       Global.DisposeAsync (504)       HttpClientFactory is disposed.
2024-05-11 22:35:49.503 [14] INFO       Global.DisposeAsync (508)       CoordinatorHttpClientFactory is disposed.
2024-05-11 22:35:49.504 [14] INFO       Global.DisposeAsync (525)       TorStatusChecker is stopped.
2024-05-11 22:35:54.513 [12] WARNING    Global.DisposeAsync (574)       System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at WalletWasabi.Daemon.Global.DisposeAsync() in WalletWasabi.Daemon\Global.cs:line 531
2024-05-11 22:35:54.514 [1] INFO        TerminateService.Terminate (192)        Wasabi stopped gracefully (6f4ee334-6570-45e3-903f-541f6523600c).
2024-05-11 22:35:54.525 [1] INFO        WasabiApplication.BeforeStopping (98)   Wasabi GUI stopped gracefully (6f4ee334-6570-45e3-903f-541f6523600c).
2024-05-11 22:35:54.556 [1] CRITICAL    Program.Main (79)       System.InvalidOperationException: No attempt to start Tor was successful.
   at WalletWasabi.Tor.TorProcessManager.StartAsync(Int32 attempts, CancellationToken cancellationToken) in WalletWasabi\Tor\TorProcessManager.cs:line 99
   at WalletWasabi.Daemon.Global.StartTorProcessManagerAsync(CancellationToken cancellationToken) in WalletWasabi.Daemon\Global.cs:line 320
   at WalletWasabi.Daemon.Global.InitializeNoWalletAsync(Boolean initializeSleepInhibitor, TerminateService terminateService, CancellationToken cancellationToken) in WalletWasabi.Daemon\Global.cs:line 217
   at WalletWasabi.Fluent.Desktop.WasabiAppExtensions.<>c__DisplayClass0_1.<<RunAsGuiAsync>b__6>d.MoveNext() in WalletWasabi.Fluent.Desktop\Program.cs:line 178
--- End of stack trace from previous location ---
   at WalletWasabi.Fluent.App.<OnFrameworkInitializationCompleted>b__6_1() in WalletWasabi.Fluent\App.axaml.cs:line 66
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore()
   at Avalonia.Threading.DispatcherOperation.Execute()
   at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job)
   at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback)
   at Avalonia.Threading.Dispatcher.Signaled()
   at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at WalletWasabi.Fluent.Desktop.WasabiAppExtensions.<>c__DisplayClass0_0.<RunAsGuiAsync>b__0() in WalletWasabi.Fluent.Desktop\Program.cs:line 194
   at WalletWasabi.Daemon.WasabiApplication.RunAsync(Func`1 afterStarting) in WalletWasabi.Daemon\WasabiApplication.cs:line 71
   at WalletWasabi.Fluent.Desktop.WasabiAppExtensions.RunAsGuiAsync(WasabiApplication app) in WalletWasabi.Fluent.Desktop\Program.cs:line 151
   at WalletWasabi.Fluent.Desktop.Program.Main(String[] args) in WalletWasabi.Fluent.Desktop\Program.cs:line 62

WalletWasabi/Models/TorMode.cs Outdated Show resolved Hide resolved
@kiminuo
Copy link
Collaborator Author

kiminuo commented May 11, 2024

Now Wasabi crashes: System.InvalidOperationException: No attempt to start Tor was successful.

The message is incorrect because it is not starting Tor but other than that it's an expected result, or not?

@yahiheb
Copy link
Collaborator

yahiheb commented May 11, 2024

The message is incorrect because it is not starting Tor but other than that it's an expected result, or not?

Yes this is the expected behavior imo.

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from 79e407e to c19640e Compare May 12, 2024 16:16
@kiminuo
Copy link
Collaborator Author

kiminuo commented May 12, 2024

The message is incorrect because it is not starting Tor but other than that it's an expected result, or not?

Yes this is the expected behavior imo.

I added the following modification: https://github.com/zkSNACKs/WalletWasabi/compare/c19640e5de3551d532424d8e25a283e279204a68..5a9ee63a5755958d2af931bc6fbfe1dbbf8d0564

@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from c19640e to 5a9ee63 Compare May 12, 2024 16:19
@kiminuo kiminuo marked this pull request as ready for review May 12, 2024 16:26
@kiminuo kiminuo force-pushed the feature/2024-05-06-UseTor-as-string branch from 5a9ee63 to 4a5a025 Compare May 12, 2024 16:26
Copy link
Collaborator

@yahiheb yahiheb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, LGTM.

@kiminuo kiminuo requested a review from turbolay May 13, 2024 11:32
Copy link
Member

@MaxHillebrand MaxHillebrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 4a5a025 on Qubes & Whonix, this is awesome, well done!

@kiminuo kiminuo merged commit 1be84e5 into zkSNACKs:master May 14, 2024
7 of 8 checks passed
@kiminuo kiminuo deleted the feature/2024-05-06-UseTor-as-string branch May 14, 2024 06:07
@@ -45,10 +46,17 @@

<DockPanel>
<TextBlock Text="Network anonymization (Tor)" />
<ToggleSwitch IsChecked="{Binding Settings.UseTor}" />
<ComboBox HorizontalAlignment="Stretch" ItemsSource="{Binding TorModes}" SelectedItem="{Binding Settings.UseTor}" Width="250">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tooltip would have been helpful about what connect-only mode is.

@@ -45,10 +46,17 @@

<DockPanel>
<TextBlock Text="Network anonymization (Tor)" />
<ToggleSwitch IsChecked="{Binding Settings.UseTor}" />
<ComboBox HorizontalAlignment="Stretch" ItemsSource="{Binding TorModes}" SelectedItem="{Binding Settings.UseTor}" Width="250">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiminuo The selection here doesn't even seem to be working. When I try to change it, it doesn't pop the restart message, and after restarting the software it resets back.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me the pop up does show and restarting the software keeps the right selection

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is clearly wrong, at least on Windows.

Original value: Disabled
Disabled -> Enabled. No restart message (there should be)
Enabled -> Enabled connect only restart message pops
Enabled connect only -> Disabled restart message stays (since Disabled is the original it should have been hidden)
Disabled -> Enabled no restart message (there should be)

Wasabi.Wallet.2024-05-22.11-50-19.mp4

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that also happened to me a few days ago.
my comment #12991 (comment), was a quick try just now, setting it from enabled to disabled which worked ok

@@ -92,7 +93,7 @@ public ApplicationSettings(string persistentConfigFilePath, PersistentConfig per
: FeeDisplayUnit.Satoshis;
_runOnSystemStartup = _uiConfig.RunOnSystemStartup;
_hideOnClose = _uiConfig.HideOnClose;
_useTor = _startupConfig.UseTor;
_useTor = config.UseTor;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soosr Regarding your comments: I guess this line might be wrong and causes what you said.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were several iterations with how this new feature was implemented. I guess it was forgotten in one of those.

I created #13074 as that's what I would expect how it should be done. I don't have time to test it right now I'll test it later on.

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

Successfully merging this pull request may close these issues.

None yet

5 participants