/// <summary> /// Starts the <see cref="PrivoxyProxy"/> service /// </summary> public void Start() { // Privoxy process is already started if (Process != null) { // Stop Privoxy process Dispose(); } // Refresh arguments and get them as a single string RefreshArguments(); string arguments = string.Join(" ", Settings.Arguments.ToList().Select(a => string.Format("{0} {1}", a.Key, a.Value))); // Write the configuration file File.WriteAllText(Path.Combine(Path.GetDirectoryName(PrivoxyExe), "trou_privoxy_config"), string.Join(Environment.NewLine, Settings.Configuration.ToList().Select(a => string.Format("{0} {1}", a.Key, a.Value)))); // Create hidden process Process = new HiddenProcess(Path.GetDirectoryName(PrivoxyExe), PrivoxyExe, arguments, HiddenProcess.PriorityClass.NORMAL_PRIORITY_CLASS, true); // Start hidden process if (!Process.Start()) { // Throw exception throw new Exception("start_failed: Privoxy process start failed"); } }
/// <summary> /// Starts the <see cref="TorProxy"/> service /// </summary> public void Start() { // Tor process is already started if (Process != null) { // Stop Tor process Dispose(); } // Refresh arguments and get them as a single string RefreshArguments(); string arguments = string.Join(" ", Settings.Arguments.ToList().Select(a => string.Format("{0} {1}", a.Key, a.Value))); // Create hidden process Process = new HiddenProcess(Path.GetDirectoryName(TorExe), TorExe, arguments, HiddenProcess.PriorityClass.NORMAL_PRIORITY_CLASS, true); // Set output event (forward to ForwardOuput function) Process.OnOutput += (sender, message) => ForwardOutput(message); // Start hidden process if (Process.Start()) { // Process already stopped (this is due to a critical error, like port already used..) if (Process.Process != null && Process.Process.HasExited) { // Throw exception throw new Exception("start_critical_error: Tor process start failed due to a critical error, check if the port isn't already used"); } } else { // Throw exception throw new Exception("start_failed: Tor process start failed, try increasing the privileges"); } }
/// <summary> /// Hash a password using the <see cref="TorExe"/> process /// </summary> public string HashPassword(string password) { // Password isn't empty if (!string.IsNullOrEmpty(password)) { // Create process runner (the process will stop itself) HiddenProcess runner = new HiddenProcess(null, TorExe, string.Format("--hash-password \"{0}\"", password), HiddenProcess.PriorityClass.NORMAL_PRIORITY_CLASS, false); // Process on output event (get password hash) string passwordHash = null; runner.OnOutput += (sender, message) => { // If it's the password hash if (message.StartsWith("16:")) { // Save password hash passwordHash = message; } }; // Start process runner.Start(); // Wait to get the password hash or wait for the end of the timeout Stopwatch timeout = Stopwatch.StartNew(); while (timeout.ElapsedMilliseconds < 5000 && passwordHash == null) { Thread.Sleep(500); } // Stop process runner.Dispose(); return(passwordHash); } return(null); }