mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-25 15:25:01 +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:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
|
||||
@@ -1537,3 +1538,27 @@ func TestMihomoCertFingerprintUsesFirstValidPin(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAmneziaWGProxyForClashProjectsKeepAliveRangeToLowerBound(t *testing.T) {
|
||||
keepAlive := model.KeepAliveValue("15-25")
|
||||
client := model.Client{Email: "range@awg", PrivateKey: "client-key", KeepAlive: &keepAlive}
|
||||
inbound := &model.Inbound{Protocol: model.AmneziaWG, Listen: "198.51.100.1", Port: 443, Settings: `{"server":{"privateKey":"server","publicKey":"server-pub","subnetIp":"10.8.1.0","subnetCidr":24},"clients":[]}`}
|
||||
svc := NewSubClashService(false, "", false, &SubService{})
|
||||
proxy := svc.buildProxy(svc.SubService, inbound, client, nil, nil)
|
||||
if proxy == nil || proxy["persistent-keepalive"] != 15 {
|
||||
t.Fatalf("Clash persistent-keepalive = %v, want range lower bound 15", proxy["persistent-keepalive"])
|
||||
}
|
||||
blob, err := marshalClashYAML(proxy)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal Clash proxy: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(blob), "persistent-keepalive: 15") {
|
||||
t.Fatalf("Clash YAML did not preserve lower-bound projection:\n%s", blob)
|
||||
}
|
||||
legacyNegative := model.KeepAliveValue("-1")
|
||||
client.KeepAlive = &legacyNegative
|
||||
proxy = svc.buildProxy(svc.SubService, inbound, client, nil, nil)
|
||||
if _, ok := proxy["persistent-keepalive"]; ok {
|
||||
t.Fatalf("Clash export emitted invalid legacy keepalive: %v", proxy["persistent-keepalive"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user