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

Consider cross platform managed http to socks proxy #36

Closed
AbeniMatteo opened this issue Sep 7, 2019 · 7 comments
Closed

Consider cross platform managed http to socks proxy #36

AbeniMatteo opened this issue Sep 7, 2019 · 7 comments

Comments

@AbeniMatteo
Copy link
Contributor

I'm currently using https://github.com/MihaZupan/HttpToSocks5Proxy on Android as http to socks proxy to replace Privoxy.

This solution is completely managed and cross platform as it just works with sockets.
I'm suggesting to consider this type of solution not requesting the integration.

@joelverhagen
Copy link
Owner

Yeah in general I like this idea whole lot. When I first started the project I couldn't find any well-established project that did this. I'll investigate this as another approach maybe even as an alternate option to what we already do with Privoxy.

@AbeniMatteo
Copy link
Contributor Author

Hi Joel, just saw the new label. This is what i'm currently doing:

var socksPort = 10_001;
var httpToSocksPort = 10_002; // Replaces privoxy http port

var settings = new TorSharpSettings
{
    TorSettings = new TorSharpTorSettings
    {
        SocksPort = socksPort,
    },
    PrivoxySettings = new TorSharpPrivoxySettings
    {
        // NOTE: New setting
        Disable = true,
    }
};

var torSharpProxy = new TorSharpProxy(settings);
await torSharpProxy.ConfigureAndStartAsync();

// NOTE: Instead of using a WebProxy with privoxy's address and port, you can use the http proxy you want
// In this case i'm using HttpToSocks5Proxy
var httpToSocksProxy = new HttpToSocks5Proxy("127.0.0.1", socksPort, httpToSocksPort);

var httpClient = new HttpClient(new HttpClientHandler
{
    UseProxy = true,
    Proxy = httpToSocksProxy
});

Pros:

  • No new dependencies for TorSharp base package
  • Backward compatible
  • Minimal changes (one new setting just that disables part of the current workflow (update and startup for privoxy), no new things)
  • Adds the ability to swap the http proxy

Cons:

  • Must be documented (is this a con?)

@joelverhagen
Copy link
Owner

Hey @AbeniMatteo, this is really awesome! Just so I understand, HttpToSocks5Proxy is code you wrote and included in the project?

Ages ago I was working on an HTTP to SOCKS implementation but I got distracted by other things (this projects, for example). I'm really happy to see this come to fruition. Privoxy is cool but reducing complexity and the "fetcher" work is very good.

No new dependencies for TorSharp base package

Sounds great, but TBH I was even considering doing this by adding a dependency to one of the existing packages out there. If we can get a bundled SOCKS proxy, that's even better.

Backward compatible

❤️

Must be documented (is this a con?)

My docs are pretty minimal as is. However now that there's two ways to do something (two different "bridges" from your C# HttpClient to Tor) it probably warrants some explanation. As the Zen of Python says:

There should be one-- and preferably only one --obvious way to do it.

Are you interested in contributing the code back to the TorSharp by making a PR? You can even provide an unpolished version and I can work on plumping the options where they need to go. One example I am thinking of is when Privoxy.Disable is true, the tool fetcher should only download Tor, not Privoxy.

@AbeniMatteo
Copy link
Contributor Author

AbeniMatteo commented Jan 18, 2021

Hey @AbeniMatteo, this is really awesome! Just so I understand, HttpToSocks5Proxy is code you wrote and included in the project?

No, not my code. HttpToSocks5Proxy it's one of your suggested packages (see quote below).

Sounds great, but TBH I was even considering doing this by adding a dependency to one of the existing packages out there. If we can get a bundled SOCKS proxy, that's even better.

You can add the dependency directly to TorSharp and maybe expose a custom IWebProxy but it's not necessary.

What i did was just add a bunch of if (!Privoxy.Disabled) around, later i'll open the PR.

@AbeniMatteo
Copy link
Contributor Author

AbeniMatteo commented Jun 19, 2021

@kzu
Copy link
Contributor

kzu commented Aug 10, 2021

And it works like a charm and is trivial to use, see https://til.cazzulino.com/dotnet/accessing-tor-via-httpclient-with-.net6

@joelverhagen
Copy link
Owner

This is enabled in version 2.10.0 and a sample is added to the repo:
https://github.com/joelverhagen/TorSharp/blob/release/samples/NativeSocksProxy/Program.cs

Since SOCKS5 support is built into .NET 6, all TorSharp needs to do is allow Privoxy to be disabled, which is done.

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

3 participants