/// <summary> /// Initializes an instance of the proxy controller. /// </summary> /// <param name="settings">The settings to dictate the proxy's behavior.</param> public TorSharpProxy(TorSharpSettings settings) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _torPasswordHasher = new TorPasswordHasher(new RandomFactory()); switch (settings.ToolRunnerType) { case ToolRunnerType.Simple: _toolRunner = new SimpleToolRunner(); break; case ToolRunnerType.VirtualDesktop: if (settings.OSPlatform != TorSharpOSPlatform.Windows) { settings.RejectRuntime($"use the {nameof(ToolRunnerType.VirtualDesktop)} tool runner"); } _toolRunner = new VirtualDesktopToolRunner(); break; default: throw new NotImplementedException($"The '{settings.ToolRunnerType}' tool runner is not supported."); } }
public static ToolSettings GetPrivoxyToolSettings(TorSharpSettings settings) { if (settings.OSPlatform == TorSharpOSPlatform.Windows) { return(new ToolSettings { Name = PrivoxyName, Prefix = "privoxy-win32", ExecutablePath = "privoxy.exe", WorkingDirectory = ".", ConfigurationPath = "config.txt", GetArguments = t => new[] { '\"' + t.ConfigurationPath + '\"' }, GetEnvironmentVariables = t => new Dictionary <string, string>(), ZippedToolFormat = ZippedToolFormat.Zip, GetEntryPath = e => { var firstSeperatorIndex = e.IndexOfAny(new[] { '/', '\\' }); if (firstSeperatorIndex >= 0) { return e.Substring(firstSeperatorIndex + 1); } return e; }, }); } else if (settings.OSPlatform == TorSharpOSPlatform.Linux) { var prefix = default(string); if (settings.Architecture == TorSharpArchitecture.X86) { prefix = "privoxy-linux32-"; } else if (settings.Architecture == TorSharpArchitecture.X64) { prefix = "privoxy-linux64-"; } else { settings.RejectRuntime("determine Linux Privoxy prefix"); } return(new ToolSettings { Name = PrivoxyName, Prefix = prefix, ExecutablePath = Path.Combine("usr", "sbin", "privoxy"), WorkingDirectory = Path.Combine("usr", "sbin"), ConfigurationPath = Path.Combine("usr", "share", "privoxy", "config"), GetArguments = t => new[] { "--no-daemon", '\"' + t.ConfigurationPath + '\"' }, GetEnvironmentVariables = t => new Dictionary <string, string>(), ZippedToolFormat = ZippedToolFormat.Deb, GetEntryPath = e => { if (e.StartsWith("./usr/sbin")) { return e; } else if (e.StartsWith("./usr/share/privoxy")) { return e; } else if (e.StartsWith("./etc/privoxy")) { if (e.StartsWith("./etc/privoxy/templates")) { return null; } return e; } else { return null; } }, }); } else { settings.RejectRuntime("run Privoxy"); } throw new NotImplementedException(); }
public static ToolSettings GetTorToolSettings(TorSharpSettings settings) { if (settings.OSPlatform == TorSharpOSPlatform.Windows) { return(new ToolSettings { Name = TorName, Prefix = "tor-win32-", ExecutablePath = Path.Combine(TorName, "tor.exe"), WorkingDirectory = TorName, ConfigurationPath = Path.Combine("Data", TorName, "torrc"), GetArguments = t => new[] { "-f", '\"' + t.ConfigurationPath + '\"' }, GetEnvironmentVariables = t => new Dictionary <string, string>(), ZippedToolFormat = ZippedToolFormat.Zip, GetEntryPath = e => e, }); } else if (settings.OSPlatform == TorSharpOSPlatform.Linux) { var prefix = default(string); if (settings.Architecture == TorSharpArchitecture.X86) { prefix = "tor-linux32-"; } else if (settings.Architecture == TorSharpArchitecture.X64) { prefix = "tor-linux64-"; } else { settings.RejectRuntime("determine Linux Tor prefix"); } return(new ToolSettings { Name = TorName, Prefix = prefix, ExecutablePath = Path.Combine(TorName, "tor"), WorkingDirectory = TorName, ConfigurationPath = Path.Combine("Data", TorName, "torrc"), GetArguments = t => new[] { "-f", '\"' + t.ConfigurationPath + '\"' }, GetEnvironmentVariables = t => { var output = new Dictionary <string, string>(); const string ldLibraryPathKey = "LD_LIBRARY_PATH"; var ldLibraryPath = Environment.GetEnvironmentVariable(ldLibraryPathKey); var addedPath = Path.GetDirectoryName(t.ExecutablePath); if (string.IsNullOrWhiteSpace(ldLibraryPath)) { ldLibraryPath = addedPath; } else { ldLibraryPath += ":" + addedPath; } output[ldLibraryPathKey] = ldLibraryPath; return output; }, ZippedToolFormat = ZippedToolFormat.TarXz, GetEntryPath = e => { const string entryPrefix = "tor-browser_en-US/Browser/TorBrowser/"; if (e.StartsWith(entryPrefix + "Data/Tor/")) { return e.Substring(entryPrefix.Length); } else if (e.StartsWith(entryPrefix + "Tor/")) { if (e.StartsWith(entryPrefix + "Tor/PluggableTransports/")) { return null; } else { return e.Substring(entryPrefix.Length); } } else { return null; } }, }); } else { settings.RejectRuntime("run Tor"); } throw new NotImplementedException(); }