windows: AmneziaWG as a system-wide VPN
Each profile without asOutbound is a tunnel service of its own, AmneziaWGTunnel$<interface>, as amneziawg-windows's client installs one: amneziawg-go on Wintun, its routes and DNS, and for one peer that takes everything its firewall blocking what would leave outside the tunnel. It runs awg-tunnel.exe, amneziawg-windows built from its pinned commit with a main of ours (its Run(), its log in a file) instead of its tunnel.dll, beside Wintun's signed DLL (tools/build-amneziawg.sh). The service writes each profile's .conf below its state root, registers the tunnel (unrestricted service SID, which its firewall exempts it by), starts the autostart ones with itself, and removes the tunnels of profiles gone, and all of them on uninstall. proxy-ctl awg list|on|off|log, and the app's AmneziaWG page: profiles (a system-wide one switched on and off, its log), one added from a vpn:// link or a .conf, or removed. tools/lib.sh: clone_commit, and fetch_pinned, which fetches in pieces a download that stalls (some networks cut TLS after about 16 KB, as wintun.net's here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95ec15e14a
commit
5cf3a237e6
30 files changed
+916
-12
No files matched your search
@@ -268,6 +268,40 @@ pub fn remove_wl(c: &mut Value, role: &str, name: &str) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An AmneziaWG profile from an AmneziaVPN `vpn://` link or a `.conf`'s text: `kind` "vpn"
|
||||
/// (system-wide), "userspace" or "singBox" (an outbound of the proxy).
|
||||
pub fn add_awg_profile(c: &mut Value, name: &str, text: &str, kind: &str) -> Result<()> {
|
||||
if !ps_core::config::path_name_ok(name) || name.len() > 32 {
|
||||
bail!("a profile name takes up to 32 letters, digits, '.', '_' and '-', and no leading dot");
|
||||
}
|
||||
let text = text.trim();
|
||||
let mut profile = if text.starts_with("vpn://") {
|
||||
json!({ "vpn": text })
|
||||
} else if text.contains("[Interface]") {
|
||||
json!({ "config": text })
|
||||
} else {
|
||||
bail!("paste an AmneziaVPN vpn:// link or a .conf (with its [Interface])");
|
||||
};
|
||||
match kind {
|
||||
"vpn" => {}
|
||||
"userspace" | "singBox" => profile["asOutbound"] = kind.into(),
|
||||
_ => bail!("a profile is a system-wide VPN or an outbound (userspace, singBox)"),
|
||||
}
|
||||
if c["amneziaWg"]["profiles"].get(name).is_some() {
|
||||
bail!("there is a profile '{name}' already");
|
||||
}
|
||||
set_path(c, &["amneziaWg", "profiles", name], profile);
|
||||
set_path(c, &["amneziaWg", "enable"], true.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_awg_profile(c: &mut Value, name: &str) -> Result<()> {
|
||||
match c.get_mut("amneziaWg").and_then(|w| w.get_mut("profiles")).and_then(Value::as_object_mut).and_then(|o| o.remove(name)) {
|
||||
Some(_) => Ok(()),
|
||||
None => bail!("no AmneziaWG profile '{name}'"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The sites an engine also handles and those it leaves alone: for `zapret-discord-youtube`
|
||||
/// beside its release's lists, for `zapret2` beside its strategies' own.
|
||||
pub fn set_zapret_sites(c: &mut Value, engine: &str, domains: &[String], exclude: &[String]) -> Result<()> {
|
||||
@@ -292,6 +326,21 @@ pub fn set_zapret_sites(c: &mut Value, engine: &str, domains: &[String], exclude
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn amneziawg_profiles_come_from_links_or_confs() {
|
||||
let mut c = json!({});
|
||||
add_awg_profile(&mut c, "home", "vpn://AAAA", "vpn").unwrap();
|
||||
add_awg_profile(&mut c, "exit", "[Interface]\nPrivateKey = x\n", "userspace").unwrap();
|
||||
assert_eq!(c["amneziaWg"]["profiles"]["home"], json!({ "vpn": "vpn://AAAA" }));
|
||||
assert_eq!(c["amneziaWg"]["profiles"]["exit"]["asOutbound"], "userspace");
|
||||
assert_eq!(c["amneziaWg"]["enable"], true);
|
||||
assert!(add_awg_profile(&mut c, "home", "vpn://B", "vpn").is_err());
|
||||
assert!(add_awg_profile(&mut c, "x", "hello", "vpn").is_err());
|
||||
assert!(add_awg_profile(&mut c, "a/b", "vpn://B", "vpn").is_err());
|
||||
remove_awg_profile(&mut c, "home").unwrap();
|
||||
assert!(remove_awg_profile(&mut c, "home").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitelist_bypass_entries_are_added_once_and_removed() {
|
||||
let mut c = json!({});
|
||||
|
||||
Reference in new issue
Block a user