feat(tunnel): параметры обфускации awg 3+

This commit is contained in:
samosvalishe committed 2026-08-25 15:44:16 +03:00
1 parent c6fc903c25
commit 77fbdec707
6 files changed
+285

No files matched your search

+39
View File
@@ -123,12 +123,51 @@ func applyInterface(cfg *tunnel.Config, key, value string) error {
case "i1", "i2", "i3", "i4", "i5":
idx := int(key[1] - '1')
cfg.Amnezia.I[idx] = value
case "headerprotectionkey":
k, err := parseKey(value)
if err != nil {
return fmt.Errorf("headerprotectionkey: %w", err)
}
cfg.Amnezia.HeaderProtectionKey = k
case "contentpaddingaddition", "rekeyaftertime", "rekeytimeout",
"rejectaftertime", "keepalivetimeout", "maxhandshakeattempts":
if err := tunnel.ValidateRange(value); err != nil {
return fmt.Errorf("%s: %w", key, err)
}
setAmneziaRange(&cfg.Amnezia, key, value)
case "randomtrailers", "disablecookies":
b, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("%s: %w", key, err)
}
if key == "randomtrailers" {
cfg.Amnezia.RandomTrailers = b
} else {
cfg.Amnezia.DisableCookies = b
}
default:
return fmt.Errorf("unknown [Interface] key %q", key)
}
return nil
}
func setAmneziaRange(p *tunnel.AmneziaParams, key, value string) {
switch key {
case "contentpaddingaddition":
p.ContentPaddingAddition = value
case "rekeyaftertime":
p.RekeyAfterTime = value
case "rekeytimeout":
p.RekeyTimeout = value
case "rejectaftertime":
p.RejectAfterTime = value
case "keepalivetimeout":
p.KeepaliveTimeout = value
case "maxhandshakeattempts":
p.MaxHandshakeAttempts = value
}
}
func setAmneziaInt(p *tunnel.AmneziaParams, key string, n int) {
switch key {
case "jc":
+53
View File
@@ -202,3 +202,56 @@ func TestParseFeedsUAPI(t *testing.T) {
t.Errorf("UAPI() = %s", uapi)
}
}
func TestParseAWG3Params(t *testing.T) {
hpKey := base64.StdEncoding.EncodeToString(bytesOf(0x04))
text := "[Interface]\nPrivateKey = " + privKey + "\nAddress = 10.8.0.2/32\n" +
"S1 = 12\nS2 = 12\nS3 = 12\nS4 = 12\n" +
"HeaderProtectionKey = " + hpKey + "\n" +
"ContentPaddingAddition = 10-40\n" +
"RekeyAfterTime = 90-140\nRekeyTimeout = 5\nRejectAfterTime = 180\n" +
"KeepaliveTimeout = 10-15\nMaxHandshakeAttempts = 18\n" +
"RandomTrailers = true\nDisableCookies = 1\n\n" +
"[Peer]\nPublicKey = " + pubKey + "\nAllowedIPs = 0.0.0.0/0\n"
cfg, err := Parse(text)
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
p := cfg.Amnezia
if p.HeaderProtectionKey != tunnel.Key(bytesOf(0x04)) {
t.Error("HeaderProtectionKey not parsed")
}
for _, kv := range []struct{ got, want string }{
{p.ContentPaddingAddition, "10-40"},
{p.RekeyAfterTime, "90-140"},
{p.RekeyTimeout, "5"},
{p.RejectAfterTime, "180"},
{p.KeepaliveTimeout, "10-15"},
{p.MaxHandshakeAttempts, "18"},
} {
if kv.got != kv.want {
t.Errorf("range = %q, want %q", kv.got, kv.want)
}
}
if !p.RandomTrailers || !p.DisableCookies {
t.Errorf("bool flags = %v/%v, want true/true", p.RandomTrailers, p.DisableCookies)
}
}
func TestParseAWG3Errors(t *testing.T) {
base := "[Interface]\nPrivateKey = " + privKey + "\nAddress = 10.8.0.2/32\n"
peer := "\n[Peer]\nPublicKey = " + pubKey + "\nAllowedIPs = 0.0.0.0/0\n"
for name, line := range map[string]string{
"bad range": "RekeyTimeout = 40-10\n",
"non-numeric": "KeepaliveTimeout = soon\n",
"bad bool": "RandomTrailers = maybe\n",
"short hp key": "HeaderProtectionKey = " + base64.StdEncoding.EncodeToString([]byte("short")) + "\n",
"hp without pad": "HeaderProtectionKey = " + base64.StdEncoding.EncodeToString(bytesOf(0x04)) + "\n",
} {
if _, err := Parse(base + line + peer); err == nil {
t.Errorf("%s: Parse() = nil, want error", name)
}
}
}