Knapcode.TorSharp
2.7.0
Prefix Reserved
See the version list below for details.
dotnet add package Knapcode.TorSharp --version 2.7.0
NuGet\Install-Package Knapcode.TorSharp -Version 2.7.0
<PackageReference Include="Knapcode.TorSharp" Version="2.7.0" />
paket add Knapcode.TorSharp --version 2.7.0
#r "nuget: Knapcode.TorSharp, 2.7.0"
// Install Knapcode.TorSharp as a Cake Addin #addin nuget:?package=Knapcode.TorSharp&version=2.7.0 // Install Knapcode.TorSharp as a Cake Tool #tool nuget:?package=Knapcode.TorSharp&version=2.7.0
TorSharp
Use Tor for your C# HTTP clients. Tor + Privoxy = ❤️
All you need is client code that can use a simple HTTP proxy.
Notice
This product is produced independently from the Tor® anonymity software and carries no guarantee from The Tor Project about quality, suitability or anything else.
Details
- Supports:
- .NET Core (.NET Standard 2.0 and later)
- .NET Framework (.NET Framework 4.5 and later)
- Windows
- ✔️ Windows 10 version 1903
- Older Windows should work too
- Linux
- ✔️ Ubuntu 18.04
- ✔️ Ubuntu 16.04
- ✔️ Debian 10
- ⚠️ Debian 9 (confirmed by a user but may have issues)
- ⚠️ CentOS 7 supported via
ExecutablePathOverride
(see below)
- ❌ Mac OS X support is not planned. I don't have a Mac 😕
- Uses Privoxy to redirect HTTP proxy traffic to Tor.
- Uses virtual desktops to manage Tor and Privoxy processes.
- Optionally downloads the latest version of Tor and Privoxy.
Install
Install-Package Knapcode.TorSharp
Example
// configure
var settings = new TorSharpSettings
{
ZippedToolsDirectory = Path.Combine(Path.GetTempPath(), "TorZipped"),
ExtractedToolsDirectory = Path.Combine(Path.GetTempPath(), "TorExtracted"),
PrivoxySettings = { Port = 1337 },
TorSettings =
{
SocksPort = 1338,
ControlPort = 1339,
ControlPassword = "foobar",
},
};
// download tools
await new TorSharpToolFetcher(settings, new HttpClient()).FetchAsync();
// execute
var proxy = new TorSharpProxy(settings);
var handler = new HttpClientHandler
{
Proxy = new WebProxy(new Uri("http://localhost:" + settings.PrivoxySettings.Port))
};
var httpClient = new HttpClient(handler);
await proxy.ConfigureAndStartAsync();
Console.WriteLine(await httpClient.GetStringAsync("http://api.ipify.org"));
await proxy.GetNewIdentityAsync();
Console.WriteLine(await httpClient.GetStringAsync("http://api.ipify.org"));
proxy.Stop();
FAQ
The tool fetcher is throwing an exception. What do I do?
This most likely is happening because the URLs where we fetch Tor or Privoxy from are down or have changed. I would recommend:
Open an issue so I can look into it.
Work around the issue by setting up the tools manually and not using
TorSharpToolFetcher
. See below.Investigate the issue yourself. The TorSharp.Sandbox project is helpful for this. Pull requests accepted 🏆.
How do I set up the tools manually?
If you don't want to use the TorSharpToolFetcher
to download the latest version of the tools for you or if you want to use a specific version of Tor and Privoxy, follow these steps.
- Make a directory that will hold the zipped Tor and Privoxy binaries.
- Put a Tor Win32 ZIP in that folder with the file name like:
tor-win32-{version}.zip
{version}
must be parsable as aSystem.Version
meaning it ismajor.minor[.build[.revision]]
.- Example:
tor-win32-0.3.5.8.zip
- The ZIP is expected to have
Tor\tor.exe
.
- Put a Privoxy Win32 ZIP in that folder with a file name like:
privoxy-win32-{version}.zip
- Again,
{version}
must be parsable as aSystem.Version
. - Example:
privoxy-win32-3.0.26.zip
- The ZIP is expected to have
privoxy.exe
.
- Again,
- Initialize a
TorSharpSettings
instance whereZippedToolsDirectory
is the directory created above. - Pass this settings instance to the
TorSharpProxy
constructor.
Privoxy fetched by TorSharp fails to start? Try installing missing dependencies.
It's possible some expected shared libraries aren't there. Try to look at the error message and judge which library needs to be installed from your distro's package repository.
Debian 10
This includes Microsoft's .NET Core 3.1 runtime image mcr.microsoft.com/dotnet/core/runtime:3.1
and Microsoft's .NET 5.0 runtime image mcr.microsoft.com/dotnet/runtime:5.0
.
Problem: On Debian 10 the following errors may appear:
/tmp/TorExtracted/privoxy-linux64-3.0.29/usr/sbin/privoxy: error while loading shared libraries: libbrotlidec.so.1: cannot open shared object file: No such file or directory
/tmp/TorExtracted/privoxy-linux64-3.0.29/usr/sbin/privoxy: error while loading shared libraries: libmbedtls.so.12: cannot open shared object file: No such file or directory
Solution: install two missing dependencies. Thanks for the heads up, @cod3rshotout!
[joel@debian10]$ sudo apt-get install -y libbrotli1 libmbedtls-dev
Privoxy fetched by TorSharp fails to start? Try ExecutablePathOverride
.
On Linux, the Privoxy binaries fetched seem to be built for the latest Debian and Ubuntu distributions. I can confirm that some other distributions don't work.
I'm no Linux expert but my guess is that there are missing shared libraries that are different on the running platform than the Debian platform that Privoxy was compiled for. The easiest workaround is to install Privoxy to your system and set the TorSharpSettings.PrivoxySetting.ExecutablePathOverride
configuration setting to "privoxy"
(i.e. use Privoxy from PATH).
After you install it, make sure privoxy
is in the PATH.
[joel@linux]$ which privoxy
/usr/sbin/privoxy
After this is done, just configure TorSharp to use the system Privoxy with the ExecutablePathOverride
setting:
var settings = new TorSharpSettings();
settings.PrivoxySettings.ExecutablePathOverride = "privoxy";
Note that you may encounter warning or error messages in the output due to new configuration being used with an older executable. I haven't ran into any problems with this myself but it's possible things could get weird.
CentOS 7
Problem: the following error appears:
/tmp/TorExtracted/privoxy-linux64-3.0.28/usr/sbin/privoxy: error while loading shared libraries: libpcre.so.3: cannot open shared object file: No such file or directory
Solution: install Privoxy. It is available on epel-release
.
[joel@centos]$ sudo yum install epel-release -y
...
[joel@centos]$ sudo yum install privoxy -y
Debian 9
This includes Microsoft's .NET Core 2.1 runtime image: mcr.microsoft.com/dotnet/core/runtime:2.1
.
Problem: the following errors may appear:
/tmp/TorExtracted/privoxy-linux64-3.0.29/usr/sbin/privoxy: error while loading shared libraries: libbrotlidec.so.1: cannot open shared object file: No such file or directory
/tmp/TorExtracted/privoxy-linux64-3.0.29/usr/sbin/privoxy: error while loading shared libraries: libmbedtls.so.12: cannot open shared object file: No such file or directory
Solution: install Privoxy. It is available in the default source lists.
[joel@debian9]$ sudo apt-get install privoxy -y
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- sharpcompress (>= 0.24.0)
- System.ServiceModel.Syndication (>= 4.5.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Knapcode.TorSharp:
Package | Downloads |
---|---|
ATS-Common
Package Description |
|
TorHttpClientExecutor
Make HttpClient requests from Tor Network |
|
VL.TorSharp
Allows to make HTTP requests using the TOR network in VL |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.15.0 | 8,685 | 10/24/2023 |
2.14.0 | 10,387 | 3/5/2023 |
2.13.0 | 2,309 | 2/2/2023 |
2.12.0 | 829 | 1/8/2023 |
2.11.0 | 341 | 1/5/2023 |
2.10.0 | 2,510 | 12/23/2022 |
2.9.0 | 337 | 12/23/2022 |
2.8.1 | 9,886 | 6/17/2021 |
2.8.0 | 808 | 5/26/2021 |
2.7.0 | 848 | 5/20/2021 |
2.6.0 | 1,686 | 3/7/2021 |
2.5.0 | 4,862 | 12/16/2020 |
2.4.0 | 940 | 11/28/2020 |
2.3.0 | 629 | 11/20/2020 |
2.2.0 | 16,067 | 11/24/2019 |
2.1.0 | 738 | 11/11/2019 |
2.0.1 | 745 | 10/5/2019 |
2.0.0 | 736 | 9/10/2019 |
2.0.0-beta1 | 492 | 9/7/2019 |
1.9.1 | 755 | 8/31/2019 |
1.9.0 | 749 | 7/22/2019 |
1.8.6 | 710 | 7/6/2019 |
1.8.5 | 1,350 | 1/23/2019 |
1.8.4 | 1,163 | 10/13/2018 |
1.8.3 | 1,537 | 3/28/2018 |
1.8.2 | 1,174 | 3/4/2018 |
1.8.1 | 1,086 | 3/3/2018 |
1.8.0 | 1,196 | 2/11/2018 |
1.7.0 | 1,283 | 12/31/2017 |
1.6.2 | 1,330 | 11/20/2017 |
1.6.1 | 1,363 | 7/29/2017 |
1.6.0 | 1,512 | 12/3/2016 |
1.5.3 | 1,555 | 7/17/2016 |
1.5.2 | 1,404 | 4/23/2016 |
1.5.1 | 1,111 | 4/20/2016 |
1.5.0 | 2,938 | 2/14/2016 |
1.4.0 | 1,184 | 2/9/2016 |
1.3.1 | 1,420 | 12/4/2015 |
1.3.0 | 1,278 | 8/24/2015 |
1.2.0 | 1,175 | 8/23/2015 |
1.1.0 | 1,165 | 8/22/2015 |
1.0.0 | 1,702 | 8/4/2015 |
* 2.7.0 Separate proxy Configure and Start steps, support old behavior with extension method.
* 2.6.0 Make SendCommandAsync public and add AdditionalSocksPorts.
* 2.5.0 Don't try to use virtual desktops on Windows 7 or earlier.
* 2.4.0 Add support for custom Tor bridges, allow configurable max Privoxy connections.
* 2.3.0 Add support for Tor bridges (e.g. obfs4).
* 2.2.0 Add Tor control methods to get traffic read and written, fix config bug.
* 2.1.0 Allow override of executable paths (enables using tools from PATH).
* 2.0.1 Fix bug in Windows Privoxy zipped tool prefix (was "win32", should be "win32-").
* 2.0.0 Add support .NET Core on Linux.
* 2.0.0-beta1 Add support for .NET Core on Windows.
* 1.9.1 Fix null reference exception in TorControlClient.Dispose().
* 1.9.0 Add UseExistingTools and CheckForUpdatesAsync so that TorSharpToolFetcher can not download so much.
* 1.8.6 Improve error experience when one of the tool ZIP files is invalid.
* 1.8.5 Add ListenAddress to TorSharpPrivoxySettings to allow external connections.
* 1.8.4 Improve missing tool message and don't fail due to a SecurityProtocolType not being supported.
* 1.8.3 Ignore version directories that don't just have digits.
* 1.8.2 Enable three different ways of downloading Privoxy. Fastest one wins.
* 1.8.1 Use Privoxy RSS feed for fetching tools instead of SourceForge.
* 1.8.0 Add support for HTTPS proxy in Tor and organize TorSettings.
* 1.7.0 Default Tor DataDirectory to a path relative to the Tor executable.
* 1.6.2 Fix a bug where ToolRunnerType.VirtualDesktop was breaking on Windows 10 (version 1709).
* 1.6.1 Fix a bug in the Tor fetcher caused by Tor versions with no Windows build.
* 1.6.0 Add configuration API for tor exit nodes.
* 1.5.3 Fix P/Invoke stubs to work on x64 so ToolRunnerType.VirtualDesktop works.
* 1.5.2 Paths now fully work when they have spaces in them.
* 1.5.1 Fix bug where usernames with spaces in them are not supported.
* 1.5.0 Hash Tor passwords in process (by duplicating the hash algorithm).
* 1.4.0 Add tool runner without jobs, configure Tor data directory, fix file system race condition.
* 1.3.1 Fix dispose issue in TorControlClient.
* 1.3.0 Extract interfaces and rename ToolFetcher to TorSharpToolFetcher.
* 1.2.0 Add tool to download the latest Tor and Privoxy.
* 1.1.0 Target .NET 4.5 instead of .NET 4.5.2.
* 1.0.0 Initial release.