Publish Zonghengjia Windows 0.3.13 client source
This commit is contained in:
@@ -9,7 +9,7 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
{
|
||||
var checks = new Dictionary<string, bool>();
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
PrivateAuxiliaryNode Node(string slug = "jinan-private", string address = "192.168.50.111", int contract = 1,
|
||||
PrivateAuxiliaryNode Node(string slug = "jinan-private", string address = "172.16.0.111", int contract = 1,
|
||||
DateTimeOffset? expiry = null, string status = "candidate") => new() {
|
||||
Slug = slug, Name = "优创未来·济南办", Region = "济南", ProbeIpv4 = address, TlsLeafSha256 = new string('a', 64),
|
||||
Contract = contract, ExpiresAt = expiry ?? now.AddMinutes(3), Status = status };
|
||||
@@ -22,8 +22,8 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
var profile = ProfileOf();
|
||||
var grants = PrivateAuxiliaryRouting.Eligible(profile, now);
|
||||
checks["valid_separate_grant"] = grants.Count == 1;
|
||||
checks["phone_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "192.168.50.170")]), now).Count == 1;
|
||||
checks["phone_tailnet_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "100.64.0.4")]), now).Count == 1;
|
||||
checks["phone_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "192.168.8.170")]), now).Count == 1;
|
||||
checks["phone_tailnet_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "100.84.199.104")]), now).Count == 1;
|
||||
checks["not_in_public_list"] = profile.Nodes.All(n => n.Slug != grants[0].Slug);
|
||||
checks["legacy_profile_has_no_auxiliary"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([]), now).Count == 0;
|
||||
checks["external_account_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(identity: "external"), now).Count == 0;
|
||||
@@ -48,9 +48,9 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
Task<bool> Yes(PrivateAuxiliaryNode n, CancellationToken t) { probes++; return Task.FromResult(true); }
|
||||
Task<bool> No(PrivateAuxiliaryNode n, CancellationToken t) { probes++; return Task.FromResult(false); }
|
||||
var empty = new HashSet<string>(StringComparer.Ordinal);
|
||||
var slow = Node("slow", "192.168.50.111");
|
||||
var fast = Node("fast", "100.64.0.4");
|
||||
var dead = Node("dead", "192.168.50.170");
|
||||
var slow = Node("slow", "172.16.0.111");
|
||||
var fast = Node("fast", "100.84.199.104");
|
||||
var dead = Node("dead", "192.168.8.170");
|
||||
var measured = 0;
|
||||
Task<long?> Measure(PrivateAuxiliaryNode n, CancellationToken t) {
|
||||
measured++; return Task.FromResult<long?>(n.Slug == "fast" ? 12 : n.Slug == "slow" ? 90 : null);
|
||||
@@ -77,33 +77,42 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
[slow, fast], empty, Tie, default)).SequenceEqual([slow, fast]);
|
||||
var domain = new PrivateAuxiliaryNode { Slug = "same-site", Name = "济南(博翠明湖)", Status = "candidate",
|
||||
Contract = 1, ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64),
|
||||
ProbeIpv4 = "192.0.2.1", ConnectAddress = "vpn.example.invalid", ProbePort = 11080 };
|
||||
ProbeIpv4 = "59.110.91.17", ConnectAddress = "vpn.toplc.cn", ProbePort = 11080 };
|
||||
Task<long?> PublicFast(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n == domain ? 1 : 90);
|
||||
checks["internal_priority_even_when_domain_ping_is_faster"] = (await PrivateAuxiliaryRouting.RankByLatencyAsync(
|
||||
[domain, slow], empty, PublicFast, default)).SequenceEqual([slow, domain]);
|
||||
var oneSite = new PrivateAuxiliaryNode { Slug = "same-site", Name = domain.Name, Status = "candidate",
|
||||
Contract = 1, ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64),
|
||||
ProbeIpv4 = "100.64.0.4", ConnectionEndpoints = [
|
||||
new() { Address = "100.64.0.4", ProbeIpv4 = "100.64.0.4", Port = 18081 },
|
||||
new() { Address = "vpn.example.invalid", ProbeIpv4 = "192.0.2.1", Port = 11080 }] };
|
||||
ProbeIpv4 = "100.84.199.104", ConnectionEndpoints = [
|
||||
new() { Address = "100.84.199.104", ProbeIpv4 = "100.84.199.104", Port = 18081 },
|
||||
new() { Address = "vpn.toplc.cn", ProbeIpv4 = "59.110.91.17", Port = 11080 }] };
|
||||
Task<long?> Both(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n.ProbePort == 11080 ? 1 : 90);
|
||||
var fixedSite = ConnectionSelection.Create(true, "same-site", ["same-site"]);
|
||||
var sameSiteRanking = await PrivateAuxiliaryRouting.RankForSelectionAsync(fixedSite, [oneSite], empty, false, Both, default);
|
||||
checks["two_transports_still_one_authorized_node"] = sameSiteRanking.Count == 2
|
||||
&& sameSiteRanking.All(n => n.Slug == "same-site") && sameSiteRanking[0].ProbeIpv4 == "100.64.0.4";
|
||||
&& sameSiteRanking.All(n => n.Slug == "same-site") && sameSiteRanking[0].ProbeIpv4 == "100.84.199.104";
|
||||
checks["manual_can_fallback_transport_not_node"] = ConnectionAttemptPlanner.CreateRanked(fixedSite, sameSiteRanking, 3)
|
||||
.All(a => a.IsPrivate && a.Slug == "same-site");
|
||||
checks["manual_exact_site_attempts_tailnet_then_public_without_search"] = PrivateAuxiliaryRouting
|
||||
.ManualEndpoints("same-site", [oneSite, fast], now).Select(n => n.ProbeIpv4)
|
||||
.SequenceEqual(["100.84.199.104", "59.110.91.17"]);
|
||||
var discoveryTargets = new List<string>();
|
||||
await PrivateAuxiliaryRouting.RankForSelectionAsync(auto, [slow, oneSite], empty, false,
|
||||
(node, _) => { discoveryTargets.Add(node.ProbeIpv4); return Task.FromResult<long?>(90); },
|
||||
default, tailnetOnly: true);
|
||||
checks["automatic_private_discovery_only_probes_granted_tailnet_endpoint"] =
|
||||
discoveryTargets.SequenceEqual(["100.84.199.104"]);
|
||||
var renewal = PrivateAuxiliaryRouting.ForRenewal(oneSite, domain);
|
||||
checks["renewal_keeps_working_domain_not_preferred_tailnet"] = renewal.EndpointHost == "vpn.example.invalid"
|
||||
checks["renewal_keeps_working_domain_not_preferred_tailnet"] = renewal.EndpointHost == "vpn.toplc.cn"
|
||||
&& renewal.ProbePort == 11080 && renewal.ExpiresAt == oneSite.ExpiresAt;
|
||||
checks["renewal_keeps_working_internal_endpoint"] = PrivateAuxiliaryRouting.ForRenewal(oneSite, sameSiteRanking[0]).ProbeIpv4 == "100.64.0.4";
|
||||
checks["renewal_keeps_working_internal_endpoint"] = PrivateAuxiliaryRouting.ForRenewal(oneSite, sameSiteRanking[0]).ProbeIpv4 == "100.84.199.104";
|
||||
checks["renewal_revoked_transport_rejected"] = Reject(() => PrivateAuxiliaryRouting.ForRenewal(oneSite, Node()));
|
||||
checks["renewal_legacy_endpoint_preserved"] = PrivateAuxiliaryRouting.ForRenewal(grants[0], grants[0]) == grants[0];
|
||||
Task<long?> OnlyDomain(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n.ProbePort == 11080 ? 30 : null);
|
||||
checks["failed_internal_selects_same_site_domain"] = (await PrivateAuxiliaryRouting.RankForSelectionAsync(
|
||||
fixedSite, [oneSite], empty, false, OnlyDomain, default)).Single().EndpointHost == "vpn.example.invalid";
|
||||
fixedSite, [oneSite], empty, false, OnlyDomain, default)).Single().EndpointHost == "vpn.toplc.cn";
|
||||
var domainConfig = Config(mutate: r => {
|
||||
r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = "vpn.example.invalid";
|
||||
r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = "vpn.toplc.cn";
|
||||
r["outbounds"]![0]!["settings"]!["servers"]![0]!["port"] = 11080;
|
||||
});
|
||||
// The fixture config helper is defined below; domain validation is checked there.
|
||||
@@ -146,7 +155,7 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
ConfigResponse Config(string scope = "private_auxiliary", int contract = 3, string slug = "jinan-private",
|
||||
string route = "smart", GatewayInfo? gateway = null, Action<JsonNode>? mutate = null, DateTimeOffset? expiry = null) {
|
||||
var root = JsonNode.Parse("""
|
||||
{"inbounds":[],"outbounds":[{"tag":"proxy","protocol":"socks","settings":{"servers":[{"address":"192.168.50.111","port":18081,"users":[{"user":"device-fixture","pass":"synthetic-fixture-not-a-real-device-credential"}]}]},"streamSettings":{"security":"tls","network":"tcp","tlsSettings":{"serverName":"zero3-test","pinnedPeerCertSha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}},{"tag":"direct","protocol":"freedom"}],"routing":{"rules":[]}}
|
||||
{"inbounds":[],"outbounds":[{"tag":"proxy","protocol":"socks","settings":{"servers":[{"address":"172.16.0.111","port":18081,"users":[{"user":"device-fixture","pass":"synthetic-fixture-not-a-real-device-credential"}]}]},"streamSettings":{"security":"tls","network":"tcp","tlsSettings":{"serverName":"zero3-test","pinnedPeerCertSha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}},{"tag":"direct","protocol":"freedom"}],"routing":{"rules":[]}}
|
||||
""")!;
|
||||
mutate?.Invoke(root);
|
||||
return new() { ConnectionScope = scope, ConfigContract = contract, Node = new() { Slug = slug },
|
||||
@@ -154,11 +163,11 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
}
|
||||
checks["compatible_private_config_accepted"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(), "smart"));
|
||||
var sameSlugDomain = new PrivateAuxiliaryNode { Slug = "jinan-private", Status = "candidate", Contract = 1,
|
||||
ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64), ProbeIpv4 = "192.0.2.1",
|
||||
ConnectAddress = "vpn.example.invalid", ProbePort = 11080 };
|
||||
ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64), ProbeIpv4 = "59.110.91.17",
|
||||
ConnectAddress = "vpn.toplc.cn", ProbePort = 11080 };
|
||||
checks["authorized_domain_mapping_config_accepted"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(sameSlugDomain, domainConfig, "smart"));
|
||||
checks["domain_runtime_keeps_real_hostname"] = PrivateAuxiliaryRuntime.Address(domainConfig.GetRuntimeConfigJson()) == "vpn.example.invalid";
|
||||
foreach (var address in new[] { "192.168.50.170", "100.64.0.4" }) {
|
||||
checks["domain_runtime_keeps_real_hostname"] = PrivateAuxiliaryRuntime.Address(domainConfig.GetRuntimeConfigJson()) == "vpn.toplc.cn";
|
||||
foreach (var address in new[] { "192.168.8.170", "100.84.199.104" }) {
|
||||
var phoneGrant = Node(address: address);
|
||||
var phoneConfig = Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = address);
|
||||
checks[$"registered_endpoint_config_{address}"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(phoneGrant, phoneConfig, "smart"));
|
||||
@@ -183,7 +192,7 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
checks["direct_mode_not_private"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(route: "direct"), "direct"));
|
||||
var privateJson = Config().GetRuntimeConfigJson();
|
||||
var privateRuntime = JsonNode.Parse(TunConfigBuilder.Build(privateJson, "Ethernet-fixture", false))!;
|
||||
checks["actual_socks_endpoint_discovered"] = TunConfigBuilder.GetProxyServerHosts(privateJson).SequenceEqual(["192.168.50.111"]);
|
||||
checks["actual_socks_endpoint_discovered"] = TunConfigBuilder.GetProxyServerHosts(privateJson).SequenceEqual(["172.16.0.111"]);
|
||||
checks["private_preserves_lan_or_tailscale_socket_route"] = privateRuntime["outbounds"]![0]!["streamSettings"]!["sockopt"]!["interface"] is null;
|
||||
checks["direct_traffic_keeps_physical_interface"] = privateRuntime["outbounds"]![1]!["streamSettings"]!["sockopt"]!["interface"]!.GetValue<string>() == "Ethernet-fixture";
|
||||
checks["private_dns_is_https_inside_proxy"] = privateRuntime["dns"]!["servers"]!.AsArray().All(n => n!.GetValue<string>().StartsWith("https://", StringComparison.Ordinal))
|
||||
@@ -199,15 +208,15 @@ internal static class PrivateAuxiliaryRoutingSelfTest
|
||||
var nic = new HashSet<int> { 12, 34 };
|
||||
checks["lan_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.255.0", "0.0.0.0", 12)], nic);
|
||||
checks["phone_ethernet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||||
[new("192.168.8.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.50.170");
|
||||
[new("192.168.8.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.8.170");
|
||||
checks["phone_tailnet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||||
[new("100.64.0.4", "255.255.255.255", "0.0.0.0", 34)], nic, "100.64.0.4");
|
||||
[new("100.84.199.104", "255.255.255.255", "0.0.0.0", 34)], nic, "100.84.199.104");
|
||||
checks["old_zero3_route_cannot_stand_in_for_phone"] = !PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||||
[new("172.16.0.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.50.170");
|
||||
[new("172.16.0.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.8.170");
|
||||
checks["phone_tailnet_default_route_not_accepted"] = !PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||||
[new("0.0.0.0", "0.0.0.0", "192.168.50.1", 12)], nic, "100.64.0.4");
|
||||
[new("0.0.0.0", "0.0.0.0", "192.168.8.1", 12)], nic, "100.84.199.104");
|
||||
checks["tailscale_subnet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.0.0", "0.0.0.0", 34)], nic);
|
||||
checks["tailscale_host_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("192.168.50.111", "255.255.255.255", "100.100.100.100", 34)], nic);
|
||||
checks["tailscale_host_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.111", "255.255.255.255", "100.100.100.100", 34)], nic);
|
||||
checks["default_route_not_manufactured_as_site"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("0.0.0.0", "0.0.0.0", "172.16.0.1", 12)], nic);
|
||||
checks["tun_or_down_interface_excluded"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.0.0", "0.0.0.0", 99)], nic);
|
||||
checks["other_lan_not_matched"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.17.0.0", "255.255.0.0", "0.0.0.0", 12)], nic);
|
||||
|
||||
Reference in New Issue
Block a user