mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 11:05:02 +03:00
feat(amneziawg): support persistent keepalive ranges (#6881)
AmneziaWG clients accept a randomised PersistentKeepalive range such as 15-25, which makes keepalive timing harder to fingerprint; the panel only stored a single number. A client's keepalive may now be a range, validated the way AmneziaWG parses it. The downloadable .conf and vpn:// profile carry the range, Clash/Mihomo output gets its lower bound, and plain WireGuard stays scalar-only. The range lives in an additive wg_keep_alive_range column, so the integer column and an older panel binary keep working after a rollback.
This commit is contained in:
@@ -228,6 +228,24 @@ func TestAmneziaWGConfigTextPeerFieldOrder(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("range keepalive is preserved in native config", func(t *testing.T) {
|
||||
keepAlive := model.KeepAliveValue("15-25")
|
||||
client := &model.Client{PrivateKey: "clientPriv", AllowedIPs: []string{"10.8.1.2/32"}, KeepAlive: &keepAlive}
|
||||
conf := amneziaWGConfigText(server, client, "203.0.113.7", 51820, "remark")
|
||||
if !strings.Contains(conf, "PersistentKeepalive = 15-25") {
|
||||
t.Fatalf("native config lost keepalive range:\n%s", conf)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("legacy negative keepalive is omitted", func(t *testing.T) {
|
||||
keepAlive := model.KeepAliveValue("-1")
|
||||
client := &model.Client{PrivateKey: "clientPriv", AllowedIPs: []string{"10.8.1.2/32"}, KeepAlive: &keepAlive}
|
||||
conf := amneziaWGConfigText(server, client, "203.0.113.7", 51820, "remark")
|
||||
if strings.Contains(conf, "PersistentKeepalive") {
|
||||
t.Fatalf("native config emitted invalid legacy keepalive:\n%s", conf)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no preshared key or keepalive", func(t *testing.T) {
|
||||
client := &model.Client{PrivateKey: "clientPriv", AllowedIPs: []string{"10.8.1.2/32"}}
|
||||
conf := amneziaWGConfigText(server, client, "203.0.113.7", 51820, "remark")
|
||||
@@ -364,7 +382,7 @@ func TestGetSubs_PreservesPerInboundAmneziaWGIdentity(t *testing.T) {
|
||||
rec := &model.ClientRecord{
|
||||
Email: email, SubID: subID, Enable: true,
|
||||
PrivateKey: mergedPriv, AllowedIPs: mergedAddr,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: 25,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: model.KeepAliveValue("25"),
|
||||
}
|
||||
if err := db.Create(rec).Error; err != nil {
|
||||
t.Fatalf("create client: %v", err)
|
||||
@@ -452,7 +470,7 @@ func TestGetSubs_AmneziaWGUnavailableSettingsEmitNoSharedConfig(t *testing.T) {
|
||||
rec := &model.ClientRecord{
|
||||
Email: email, SubID: subID, Enable: true,
|
||||
PrivateKey: mergedPriv, AllowedIPs: mergedAddr,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: 25,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: model.KeepAliveValue("25"),
|
||||
}
|
||||
if err := db.Create(rec).Error; err != nil {
|
||||
t.Fatalf("create client: %v", err)
|
||||
@@ -515,7 +533,7 @@ func TestGetSubs_AmneziaWGEmptyOptionalTunnelFieldsDoNotInheritShared(t *testing
|
||||
rec := &model.ClientRecord{
|
||||
Email: email, SubID: subID, Enable: true,
|
||||
PrivateKey: mergedPriv, AllowedIPs: mergedAddr,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: 25,
|
||||
PreSharedKey: "sharedpsk", KeepAlive: model.KeepAliveValue("25"),
|
||||
}
|
||||
if err := db.Create(rec).Error; err != nil {
|
||||
t.Fatalf("create client: %v", err)
|
||||
@@ -580,7 +598,7 @@ func TestMatchingClients_TunnelMetadataStaysNormalized(t *testing.T) {
|
||||
Email: email, SubID: subID, UUID: freshID, Enable: true,
|
||||
TotalGB: 5, ExpiryTime: expiry, Comment: "vip", LimitIP: 3,
|
||||
PrivateKey: sharedKey, PublicKey: "shared-pub", AllowedIPs: "10.9.9.9/32",
|
||||
PreSharedKey: "shared-psk", KeepAlive: 99,
|
||||
PreSharedKey: "shared-psk", KeepAlive: model.KeepAliveValue("99"),
|
||||
}
|
||||
other := &model.ClientRecord{
|
||||
Email: "other-sub@awg", SubID: "other-sub", UUID: "22222222-2222-4333-8444-555555555555", Enable: true,
|
||||
|
||||
Reference in New Issue
Block a user