feat: whitelists bypass methods

This commit is contained in:
fufsob committed 2026-09-25 02:24:05 +00:00
1 parent 11c44deb61
commit f3e9140f62
22 files changed
+716 -3

No files matched your search

+12
View File
@@ -47,6 +47,7 @@ in
xray = import ../../pkgs/xray.nix { pkgs = upstream; };
# AWG 3.1 userspace; its kernel module has to match the system's kernel instead.
amneziaWg = import ../../pkgs/amneziawg.nix { pkgs = upstream; };
whitelist-bypass = import ../../pkgs/whitelist-bypass.nix { pkgs = upstream; };
inherit (upstream) sing-box;
};
}
@@ -138,6 +139,17 @@ in
}
))
(lib.mkIf cfg.whitelistBypass.enable (
import ./whitelist-bypass.nix {
inherit
lib
pkgs
cfg
derived
;
}
))
(lib.mkIf derived.ruleSetsEnabled (
import ./rulesets.nix {
inherit
+17
View File
@@ -117,6 +117,19 @@ let
torOutboundEnabled = torCfg.enable && torCfg.asOutbound;
torRouteOnion = torOutboundEnabled && torCfg.routeOnion && proxyEnabled;
# Joiners in name order, each an outbound on a loopback SOCKS listener of its own.
whitelistBypassCfg = cfg.whitelistBypass;
whitelistBypassJoiners = lib.optionals whitelistBypassCfg.enable (
lib.imap0 (
i: tag:
whitelistBypassCfg.joiners.${tag}
// {
inherit tag;
port = 18700 + i;
}
) (builtins.attrNames whitelistBypassCfg.joiners)
);
# Two ports per "singBox" or "userspace" AmneziaWG outbound, above the autoProxy prober's own
# listeners (proxy.autoProxy.probeBasePort, 18540 by default, one per exit):
# both bind loopback, so an overlap leaves whichever unit starts second dead.
@@ -290,6 +303,7 @@ let
++ lib.optional sshProxyOutboundEnabled sshProxyOutboundTag
++ lib.optional warpOutboundEnabled warpOutboundTag
++ lib.optional torOutboundEnabled torOutboundTag
++ map (j: j.tag) whitelistBypassJoiners
++ map (ob: ob.tag) awgOutbounds;
subscriptionTags = map (sub: sub.tag) proxyCfg.subscriptions;
@@ -301,6 +315,7 @@ let
|| sshProxyOutboundEnabled
|| warpOutboundEnabled
|| torOutboundEnabled
|| whitelistBypassJoiners != [ ]
|| awgOutbounds != [ ];
collapseNamedOutbounds = selectionMode == "first";
# Always on with sing-box: `proxy-ctl proxy outbounds test` needs it in every selection mode.
@@ -509,6 +524,8 @@ in
torOutboundTag
torOutboundEnabled
torRouteOnion
whitelistBypassCfg
whitelistBypassJoiners
torOnionEnabled
torOnionInbounds
proxyInboundOnionCapable
+1
View File
@@ -17,6 +17,7 @@
./warp.nix
./tor.nix
./tg-ws-proxy.nix
./whitelist-bypass.nix
./geodata.nix
./gui.nix
./tui.nix
@@ -0,0 +1,137 @@
{ lib, proxySuiteUpstream, ... }:
let
inherit (lib) mkEnableOption mkOption types;
joinerType = types.submodule {
options = {
platform = mkOption {
type = types.enum [
"wbstream"
"telemost"
"dion"
"bitrix"
];
description = "Call platform the creator on the other end uses. VK has no Linux joiner.";
example = "wbstream";
};
linkFile = mkOption {
type = types.str;
description = ''
Runtime path to the call link the creator printed (or wrote to its state directory):
a WB Stream room id, a Telemost link, a DION event slug or a Bitrix conference link.
'';
example = "/run/secrets/whitelist-bypass-link";
};
};
};
creatorType = types.submodule {
options = {
platform = mkOption {
type = types.enum [
"wbstream"
"telemost"
"dion"
"bitrix"
"vk"
];
description = ''
Call platform. Every one needs an account: "vk" only serves the upstream Android app,
the rest a joiner of this module too.
'';
example = "wbstream";
};
cookiesFile = mkOption {
type = types.str;
description = ''
Runtime path to the platform's cookies, as the upstream desktop Creator exports them.
Copied into the state directory on first start only: DION and Bitrix rotate their
refresh token into that copy, and a stale one would kill the session. Delete
`<stateDir>/whitelist-bypass/<name>.cookies.json` to take a new export.
'';
example = "/run/secrets/whitelist-bypass-cookies-wbstream.json";
};
linkFile = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Runtime path to the call to rejoin. Null rejoins the last call written to
`<stateDir>/whitelist-bypass/<name>.link`, and creates one on first start: the link
stays the same across restarts, so the joiner needs it only once.
'';
example = "/run/secrets/whitelist-bypass-link";
};
upstream = mkOption {
type = types.enum [
"direct"
"proxy"
];
default = "direct";
description = ''
Where the joiner's traffic leaves.
- "direct": from this host, past TUN and TProxy (it runs as proxy-suite-daemon).
- "proxy": through the local proxy listener (proxy.listener, with its auth), and so
its outbounds and routing.
'';
};
resources = mkOption {
type = types.enum [
"moderate"
"default"
"unlimited"
];
default = "moderate";
description = "Buffer sizes and Go memory limit: 64, 128 or 256 MB.";
};
};
};
in
{
options.services.proxy-suite.whitelistBypass = {
enable = mkEnableOption ''
tunnels through the media servers of video calls, which mobile internet whitelists let
through ([whitelist-bypass](https://github.com/kulikov0/whitelist-bypass)). A creator on a
free host serves exactly one joiner on a censored one'';
package = mkOption {
type = types.package;
default = proxySuiteUpstream.whitelist-bypass;
defaultText = lib.literalMD "proxy-suite's `whitelist-bypass` (`pkgs/whitelist-bypass.nix`)";
description = "whitelist-bypass package with the headless creators and joiners.";
};
joiners = mkOption {
type = types.attrsOf joinerType;
default = { };
description = ''
Joiners, each an outbound tagged with its name: a loopback SOCKS5 listener that tunnels
through the call. Needs proxy.enable.
'';
example = {
wl = {
platform = "wbstream";
linkFile = "/run/secrets/whitelist-bypass-link";
};
};
};
creators = mkOption {
type = types.attrsOf creatorType;
default = { };
description = "Creators, one per joiner device. The link each uses is in its log.";
example = {
phone = {
platform = "wbstream";
cookiesFile = "/run/secrets/whitelist-bypass-cookies-wbstream.json";
upstream = "proxy";
};
};
};
};
}
@@ -78,6 +78,7 @@ let
ob.directPort
]) derived.awgTunnelOutbounds
++ lib.optional derived.torOutboundEnabled derived.torCfg.socksPort
++ map (j: j.port) derived.whitelistBypassJoiners
++ lib.optionals derived.proxyInboundsEnabled (
map (listener: listener.internalPort) derived.proxyInboundsAwg
);
@@ -889,6 +890,21 @@ let
torOnionVirtualPorts = map (
ib: if ib.listener.sharePort != null then ib.listener.sharePort else ib.listener.port
) derived.torOnionInbounds;
whitelistBypassCfg = cfg.whitelistBypass;
whitelistBypassAssertions = [
(requireEnabled (
derived.whitelistBypassJoiners != [ ]
) proxyEnabled "proxy-suite: whitelistBypass.joiners requires proxy.enable = true")
(requireEnabled
(
whitelistBypassCfg.enable
&& lib.any (c: c.upstream == "proxy") (builtins.attrValues whitelistBypassCfg.creators)
)
proxyEnabled
''proxy-suite: whitelistBypass.creators.<name>.upstream = "proxy" requires proxy.enable = true''
)
];
torSnowflake = lib.any (line: lib.hasPrefix "snowflake " line) torCfg.bridges.lines;
torAssertions = [
(mkAssertion (
@@ -959,6 +975,7 @@ in
rootlessAssertions
++ featureAssertions
++ torAssertions
++ whitelistBypassAssertions
++ perAppRoutingAssertions
++ localProxyAuthAssertions
++ secretAssertions
+18
View File
@@ -72,6 +72,24 @@ in
ROUTE_MODE_STATE_FILE = routeModeStateFile;
DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
WL_FILE = toString (
pkgs.writeText "proxy-suite-control" (
builtins.toJSON (
lib.optionals cfg.whitelistBypass.enable (
lib.mapAttrsToList (name: c: {
inherit name;
inherit (c) platform;
role = "creator";
}) cfg.whitelistBypass.creators
++ lib.mapAttrsToList (name: j: {
inherit name;
inherit (j) platform;
role = "joiner";
}) cfg.whitelistBypass.joiners
)
)
)
);
INBOUNDS_ENABLED = flag proxyInboundsEnabled;
INBOUNDS_LINKS_FILE = proxyInboundsLinksFile;
INBOUNDS_STATS_FILE = constants.inboundStatsFile;
@@ -6,6 +6,7 @@
sshProxyCfg,
warpCfg,
torCfg,
whitelistBypassJoiners,
awgOutbounds,
constants,
pureXrayEnabled,
@@ -588,6 +589,9 @@ let
torBlock = lib.optionalString torOutboundEnabled (
mkTunnelOutboundBlock "proxy-suite-tor" "tor" "tor" torCfg.socksPort
);
whitelistBypassBlocks = lib.concatMapStrings (
j: mkTunnelOutboundBlock "proxy-suite-wb-joiner-${j.tag}" "whitelist-bypass" j.tag j.port
) whitelistBypassJoiners;
awgBlocks = lib.concatMapStrings (mkAwgOutboundBlock routingMark) awgOutbounds;
wrapperBlock =
@@ -666,6 +670,7 @@ let
+ sshProxyBlock
+ warpBlock
+ torBlock
+ whitelistBypassBlocks
+ awgBlocks
+ detourBlock
+ requireOutboundsBlock
+1
View File
@@ -125,6 +125,7 @@ let
sshProxyCfg
warpCfg
torCfg
whitelistBypassJoiners
awgOutbounds
constants
pureXrayEnabled
+3 -1
View File
@@ -20,6 +20,7 @@ let
sshProxyUnitEnabled
torOutboundEnabled
torOnionEnabled
whitelistBypassJoiners
proxyInboundsEnabled
proxyInboundsNeedLocalProxy
scripts
@@ -88,7 +89,8 @@ let
"network-online.target"
]
++ lib.optional (sshProxyOutboundEnabled && sshProxyUnitEnabled) "proxy-suite-ssh-proxy.service"
++ lib.optional torOutboundEnabled "proxy-suite-tor.service";
++ lib.optional torOutboundEnabled "proxy-suite-tor.service"
++ map (j: "proxy-suite-wb-joiner-${j.tag}.service") whitelistBypassJoiners;
wantedBy = [ "multi-user.target" ];
execStart = scripts.startSocks;
runtimeDirectory = serviceNames.socks;
+108
View File
@@ -0,0 +1,108 @@
# whitelist-bypass: joiners, the loopback SOCKS listeners behind their outbounds, and
# creators, the free ends of the calls they tunnel through.
{
lib,
pkgs,
cfg,
derived,
}:
let
w = derived.whitelistBypassCfg;
inherit (derived.constants) unprivilegedServiceConfig;
inherit (derived.localProxy) auth;
# Every flag that takes the call, joiner and creator alike.
linkFlag = {
wbstream = "--room";
dion = "--room";
bitrix = "--room";
telemost = "--tm-link";
vk = "--vk-link";
};
joinerLinkFlag = linkFlag // {
bitrix = "--link";
};
passwordSource =
if auth.passwordFile != null then
auth.passwordFile
else if auth.password != null then
pkgs.writeText "proxy-suite-wb-creator" auth.password
else
null;
# Restart=always must not trip the start limit while the network or the platform is down.
mkUnit = description: serviceConfig: {
inherit description;
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
startLimitIntervalSec = 0;
serviceConfig =
unprivilegedServiceConfig [ ]
// {
Restart = "always";
RestartSec = 5;
}
// serviceConfig;
};
mkJoiner =
j:
lib.nameValuePair "proxy-suite-wb-joiner-${j.tag}" (
mkUnit "proxy-suite - whitelist-bypass joiner ${j.tag}" {
ExecStart = pkgs.writeShellScript "proxy-suite-wb-joiner-${j.tag}" ''
set -euo pipefail
link=$(tr -d '[:space:]' < "$CREDENTIALS_DIRECTORY/link")
exec ${w.package}/bin/headless-${j.platform}-joiner \
${joinerLinkFlag.${j.platform}} "$link" --socks-port ${toString j.port}
'';
LoadCredential = [ "link:${j.linkFile}" ];
}
);
mkCreator =
name: c:
let
viaProxy = c.upstream == "proxy";
withProxyAuth = viaProxy && derived.localProxy.authEnabled;
unit = mkUnit "proxy-suite - whitelist-bypass creator ${name}" {
ExecStart = pkgs.writeShellScript "proxy-suite-wb-creator-${name}" ''
set -euo pipefail
cookies="$STATE_DIRECTORY/${name}.cookies.json"
links="$STATE_DIRECTORY/${name}.link"
[ -e "$cookies" ] || install -m 600 "$CREDENTIALS_DIRECTORY/cookies" "$cookies"
args=(--cookies "$cookies" --write-file "$links" --resources ${c.resources})
${
if c.linkFile != null then
''link=$(tr -d '[:space:]' < "$CREDENTIALS_DIRECTORY/link")''
else
''link=$(tail -n 1 "$links" 2>/dev/null || true)''
}
[ -z "$link" ] || args+=(${linkFlag.${c.platform}} "$link")
${lib.optionalString viaProxy ''
args+=(--upstream-socks ${derived.localProxy.hostPart}:${toString cfg.proxy.listener.port})
''}${lib.optionalString withProxyAuth ''
args+=(--upstream-user ${lib.escapeShellArg auth.username} --upstream-pass "$(< "$CREDENTIALS_DIRECTORY/proxy-password")")
''}
exec ${w.package}/bin/headless-${c.platform}-creator "''${args[@]}"
'';
StateDirectory = "proxy-suite/whitelist-bypass";
StateDirectoryMode = "0700";
LoadCredential = [
"cookies:${c.cookiesFile}"
]
++ lib.optional (c.linkFile != null) "link:${c.linkFile}"
++ lib.optional withProxyAuth "proxy-password:${passwordSource}";
};
in
lib.nameValuePair "proxy-suite-wb-creator-${name}" (
unit // lib.optionalAttrs viaProxy { after = unit.after ++ [ "proxy-suite-socks.service" ]; }
);
in
{
services.proxy-suite.internal.services = lib.listToAttrs (
map mkJoiner derived.whitelistBypassJoiners ++ lib.mapAttrsToList mkCreator w.creators
);
}