Files
proxy-suite-flake/windows/crates/ps-service/src/components.rs
T
faumarayandClaude Opus 5.5 40221e7981 windows: Tor
- tor: the Tor Project's Expert Bundle for Windows (15.0.26) as a
  component, pinned by the hash of the release whose signature was
  checked against the Tor Browser Developers' key; the installer takes
  gzipped tars now (plain files only: a link could point anywhere).
- The torrc upstream's tor.nix writes: SOCKS for the tor outbound,
  bridges with the bundle's lyrebird (obfs4, webtunnel, meek, snowflake)
  and conjure, the local proxy as upstream (upstream = "proxy") with its
  login, extraConfig. The control port is on loopback with cookie
  authentication (upstream's is a Unix socket only Tor's user opens).
  Values are quoted with control characters escaped: a newline in, say,
  the proxy's login would otherwise start a directive (one that runs a
  program, as SYSTEM).
- Tor's own connections go direct under the TUN unless upstream =
  "proxy". The onion service (for the inbounds) is still to come and is
  said to be.
- Checked: Windows' tor.exe, under Wine, takes a torrc of this shape,
  bridges and escaped values included; on Linux the service runs Tor and
  it bootstraps as far as this network lets it without bridges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 08:02:24 +03:00

70 lines
2.5 KiB
Rust

//! Where the backend programs are.
//!
//! The service installs each into `bin\<component>\` (the component manager); a program
//! found there wins. Elsewhere (development on Linux) the one on PATH is taken.
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::time::SystemTime;
pub struct Components {
bin: PathBuf,
/// Programs verified, by path, with the size and time they had then.
verified: Mutex<HashMap<PathBuf, (u64, SystemTime)>>,
}
impl Components {
pub fn new(bin: PathBuf) -> Self {
Self { bin, verified: Mutex::new(HashMap::new()) }
}
/// `find`, and for an installed one, the check that it is what was installed.
pub fn program(&self, component: &str, name: &str) -> anyhow::Result<PathBuf> {
let path = self
.find(component, name)
.ok_or_else(|| anyhow::anyhow!("{component} is not installed (proxy-ctl components install {component})"))?;
let dir = self.bin.join(component);
if path.starts_with(&dir) {
let meta = std::fs::metadata(&path)?;
let stamp = (meta.len(), meta.modified()?);
if self.verified.lock().unwrap().get(&path) != Some(&stamp) {
crate::install::verify(&dir, &path)?;
self.verified.lock().unwrap().insert(path.clone(), stamp);
}
}
Ok(path)
}
/// The program `name` (without `.exe`) of `component`. On Windows only the protected
/// `bin\` counts: what the service runs, it runs as SYSTEM, and PATH may hold a directory
/// any user can write.
pub fn find(&self, component: &str, name: &str) -> Option<PathBuf> {
let file = if cfg!(windows) { format!("{name}.exe") } else { name.to_owned() };
let installed = self.bin.join(component).join(&file);
if installed.is_file() {
return Some(installed);
}
if cfg!(windows) {
return None;
}
// Development: the system's program of that name (a bundle's "tor/tor" is "tor").
let bare = std::path::Path::new(&file).file_name()?.to_owned();
let path = std::env::var_os("PATH")?;
std::env::split_paths(&path).map(|dir| dir.join(&bare)).find(|p| p.is_file())
}
pub fn sing_box(&self) -> anyhow::Result<PathBuf> {
self.program("sing-box", "sing-box")
}
pub fn xray(&self) -> anyhow::Result<PathBuf> {
self.program("xray", "xray")
}
#[allow(dead_code)]
pub fn bin_dir(&self) -> &Path {
&self.bin
}
}