feat(web): vless encryption new modes (#5517)

* feat(web): add vless encryption new modes

* feat(web): add translations for vless encryption modes

* feat(translation): bring "vlessAuthX25519" and "vlessAuthMlkem768" to general form
This commit is contained in:
FunLay123
2026-06-24 21:22:42 +02:00
committed by GitHub
parent ae9bbdf267
commit 3ba43bd86d
17 changed files with 219 additions and 51 deletions
+24 -1
View File
@@ -2064,11 +2064,34 @@ func (s *ServerService) GetNewVlessEnc() (any, error) {
return nil, err
}
auths := parseVlessEncAuths(out.String())
auths = append(auths, deriveVlessEncModes(auths)...)
return map[string]any{
"auths": parseVlessEncAuths(out.String()),
"auths": auths,
}, nil
}
func deriveVlessEncModes(auths []map[string]string) []map[string]string {
var extra []map[string]string
for _, a := range auths {
for _, mode := range []string{"xorpub", "random"} {
dec := strings.Replace(a["decryption"], ".native.", "."+mode+".", 1)
enc := strings.Replace(a["encryption"], ".native.", "."+mode+".", 1)
if dec == a["decryption"] && enc == a["encryption"] {
continue
}
extra = append(extra, map[string]string{
"id": a["id"] + "_" + mode,
"label": a["label"] + " (" + mode + ")",
"decryption": dec,
"encryption": enc,
})
}
}
return extra
}
func parseVlessEncAuths(output string) []map[string]string {
lines := strings.Split(output, "\n")
var auths []map[string]string
@@ -80,3 +80,31 @@ Authentication: X25519, not Post-Quantum
t.Fatalf("encryption = %q, want client", auths[0]["encryption"])
}
}
func TestDeriveVlessEncModes(t *testing.T) {
base := []map[string]string{
{
"id": "x25519",
"label": "X25519, not Post-Quantum",
"decryption": "mlkem768x25519plus.native.600s.server-key",
"encryption": "mlkem768x25519plus.native.0rtt.client-key",
},
}
derived := deriveVlessEncModes(base)
if len(derived) != 2 {
t.Fatalf("expected 2 derived blocks, got %d", len(derived))
}
if derived[0]["id"] != "x25519_xorpub" {
t.Errorf("id = %q, want x25519_xorpub", derived[0]["id"])
}
if derived[0]["decryption"] != "mlkem768x25519plus.xorpub.600s.server-key" {
t.Errorf("decryption = %q", derived[0]["decryption"])
}
if derived[0]["encryption"] != "mlkem768x25519plus.xorpub.0rtt.client-key" {
t.Errorf("encryption = %q", derived[0]["encryption"])
}
if derived[1]["id"] != "x25519_random" {
t.Errorf("id = %q, want x25519_random", derived[1]["id"])
}
}