feat: support warp config generators
This commit is contained in:
5 files changed
+56
-4
No files matched your search
@@ -12,7 +12,7 @@ in
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a WireGuard profile for WARP, as written by `wgcf register && wgcf generate`.
|
||||
Junk-packet lines (Jc, Jmin, Jmax) are honoured by the AmneziaWG profile only.
|
||||
AmneziaWG lines (Jc, S1-S4, H1-H4, I1-I5, AWG 3 timing) are honoured by the AmneziaWG profile only.
|
||||
|
||||
When null, proxy-suite-warp registers a device with wgcf (accepting Cloudflare's terms)
|
||||
into /var/lib/proxy-suite/warp, through the local proxy when proxy.enable is set, and
|
||||
@@ -21,6 +21,19 @@ in
|
||||
example = "/run/secrets/wgcf-profile.conf";
|
||||
};
|
||||
|
||||
generatorUrl = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
HTTPS URL of a WARP profile generator, fetched directly when wgcf registration fails
|
||||
(e.g. the Cloudflare API is blocked and there is no local proxy). It must return a
|
||||
WireGuard profile, or JSON with the base64 profile in `.content`.
|
||||
|
||||
The generator registers the device, so its operator sees the private key.
|
||||
'';
|
||||
example = "https://valokda-amnezia.vercel.app/api/warp?mode=awg2";
|
||||
};
|
||||
|
||||
asOutbound = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
|
||||
@@ -46,7 +46,20 @@ let
|
||||
[ -s wgcf-account.toml ] || wgcf register --accept-tos
|
||||
wgcf generate
|
||||
}
|
||||
${lib.optionalString (w.generatorUrl != null) ''
|
||||
|
||||
# Fallback: a third-party generator registers from abroad and hands the profile back.
|
||||
generate() {
|
||||
body=$(${pkgs.curl}/bin/curl --noproxy '*' -fsS --max-time 60 -A proxy-suite \
|
||||
${lib.escapeShellArg w.generatorUrl}) || return 1
|
||||
case "$body" in
|
||||
"[Interface]"*) printf '%s\n' "$body" ;;
|
||||
*) ${pkgs.jq}/bin/jq -er '.content | @base64d' <<< "$body" ;;
|
||||
esac > wgcf-profile.conf.tmp || return 1
|
||||
grep -q '^PrivateKey' wgcf-profile.conf.tmp || return 1
|
||||
mv wgcf-profile.conf.tmp wgcf-profile.conf
|
||||
}
|
||||
''}
|
||||
${
|
||||
if cfg.proxy.enable then
|
||||
''
|
||||
@@ -58,10 +71,12 @@ let
|
||||
done
|
||||
userinfo=
|
||||
${userinfo}
|
||||
HTTPS_PROXY="socks5://''${userinfo}${hostPart}:${toString listener.port}" register || register
|
||||
HTTPS_PROXY="socks5://''${userinfo}${hostPart}:${toString listener.port}" register || register${
|
||||
lib.optionalString (w.generatorUrl != null) " || generate"
|
||||
}
|
||||
''
|
||||
else
|
||||
"register"
|
||||
"register${lib.optionalString (w.generatorUrl != null) " || generate"}"
|
||||
}
|
||||
'';
|
||||
|
||||
|
||||
@@ -56,6 +56,16 @@ let
|
||||
configFile = null;
|
||||
};
|
||||
autoTunnel = tunnelOf auto;
|
||||
generator = mkFixture "sing-box" {
|
||||
asOutbound = true;
|
||||
configFile = null;
|
||||
generatorUrl = "https://gen.example.com/api/warp?mode=awg2";
|
||||
};
|
||||
registerOf =
|
||||
fixture:
|
||||
generated.readDerivation fixture.config.systemd.services."proxy-suite-warp".serviceConfig.ExecStart;
|
||||
autoRegister = registerOf auto;
|
||||
generatorRegister = registerOf generator;
|
||||
|
||||
amneziaWg = evalProxySuite [
|
||||
{
|
||||
@@ -185,6 +195,14 @@ in
|
||||
&& hasInfix "until [ -s \"$profile\" ]" autoTunnel;
|
||||
true
|
||||
)
|
||||
# A generator only backs up wgcf, fetched directly with the URL quoted.
|
||||
(
|
||||
assert
|
||||
hasInfix "register || register || generate" generatorRegister
|
||||
&& hasInfix "'https://gen.example.com/api/warp?mode=awg2'" generatorRegister
|
||||
&& !(hasInfix "generate()" autoRegister);
|
||||
true
|
||||
)
|
||||
(
|
||||
assert amneziaWg.config.services.proxy-suite.amneziaWg.profiles.warp.configFile == profile;
|
||||
true
|
||||
|
||||
@@ -33,6 +33,11 @@ class WarpOutboundTest(unittest.TestCase):
|
||||
self.assertEqual((ob["peers"][0]["address"], ob["peers"][0]["port"]), ("2606:4700:d0::a29f:c001", 500))
|
||||
self.assertNotIn("routing_mark", ob)
|
||||
|
||||
def test_awg3_keepalive_range(self):
|
||||
# Generator AWG 3 profiles range the keepalive; sing-box gets the lower bound.
|
||||
ob = build(WGCF.replace("[Peer]", "RekeyAfterTime = 100-120\n[Peer]\nPersistentKeepalive = 25-35"), "warp", None)
|
||||
self.assertEqual(ob["peers"][0]["persistent_keepalive_interval"], 25)
|
||||
|
||||
def test_rejects_missing_peer(self):
|
||||
with self.assertRaises(ConfigError):
|
||||
build(WGCF.split("[Peer]")[0], "warp", None)
|
||||
|
||||
@@ -54,7 +54,8 @@ def build(text: str, tag: str, routing_mark: int | None) -> dict[str, Any]:
|
||||
"allowed_ips": _split(peer.get("allowedips", "")) or ["0.0.0.0/0", "::/0"],
|
||||
}
|
||||
if peer.get("persistentkeepalive"):
|
||||
sb_peer["persistent_keepalive_interval"] = int(peer["persistentkeepalive"])
|
||||
# AWG 3 profiles give a range ("25-35"); sing-box takes one value.
|
||||
sb_peer["persistent_keepalive_interval"] = int(peer["persistentkeepalive"].split("-")[0])
|
||||
if peer.get("presharedkey"):
|
||||
sb_peer["pre_shared_key"] = peer["presharedkey"]
|
||||
endpoint: dict[str, Any] = {
|
||||
|
||||
Reference in new issue
Block a user