mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-04 17:37:19 +00:00
fix(sub): emit VLESS encryption in Clash configs (#5053)
Co-authored-by: jq <fs187438@gmail.com>
This commit is contained in:
@@ -221,8 +221,11 @@ func (s *SubClashService) buildProxy(inbound *model.Inbound, client model.Client
|
|||||||
}
|
}
|
||||||
var inboundSettings map[string]any
|
var inboundSettings map[string]any
|
||||||
json.Unmarshal([]byte(inbound.Settings), &inboundSettings)
|
json.Unmarshal([]byte(inbound.Settings), &inboundSettings)
|
||||||
if encryption, ok := inboundSettings["encryption"].(string); ok && encryption != "" {
|
if encryption, ok := inboundSettings["encryption"].(string); ok {
|
||||||
proxy["packet-encoding"] = encryption
|
encryption = strings.TrimSpace(encryption)
|
||||||
|
if encryption != "" && encryption != "none" {
|
||||||
|
proxy["encryption"] = encryption
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case model.Trojan:
|
case model.Trojan:
|
||||||
proxy["type"] = "trojan"
|
proxy["type"] = "trojan"
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package sub
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mhsanaei/3x-ui/v3/database/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEnsureUniqueProxyNames(t *testing.T) {
|
func TestEnsureUniqueProxyNames(t *testing.T) {
|
||||||
@@ -113,3 +115,60 @@ func TestApplyTransport_HTTPUpgrade(t *testing.T) {
|
|||||||
t.Fatalf("headers.Host = %v, want example.com", headers["Host"])
|
t.Fatalf("headers.Host = %v, want example.com", headers["Host"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildProxy_VLESSPostQuantumEncryptionUsesMihomoEncryptionField(t *testing.T) {
|
||||||
|
svc := &SubClashService{SubService: &SubService{remarkModel: "-i"}}
|
||||||
|
encryption := "mlkem768x25519plus.native.0rtt.client"
|
||||||
|
inbound := &model.Inbound{
|
||||||
|
Listen: "203.0.113.1",
|
||||||
|
Port: 443,
|
||||||
|
Protocol: model.VLESS,
|
||||||
|
Remark: "pq",
|
||||||
|
Settings: `{"encryption":"` + encryption + `"}`,
|
||||||
|
}
|
||||||
|
client := model.Client{ID: "11111111-2222-4333-8444-555555555555"}
|
||||||
|
stream := map[string]any{
|
||||||
|
"network": "xhttp",
|
||||||
|
"xhttpSettings": map[string]any{
|
||||||
|
"path": "/",
|
||||||
|
"mode": "auto",
|
||||||
|
},
|
||||||
|
"security": "reality",
|
||||||
|
"realitySettings": map[string]any{
|
||||||
|
"publicKey": "pub",
|
||||||
|
"serverName": "example.com",
|
||||||
|
"shortId": "abcd",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy := svc.buildProxy(inbound, client, stream, "")
|
||||||
|
|
||||||
|
if proxy["encryption"] != encryption {
|
||||||
|
t.Fatalf("encryption = %v, want %q", proxy["encryption"], encryption)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildProxy_VLESSNoneEncryptionOmittedForClash(t *testing.T) {
|
||||||
|
svc := &SubClashService{SubService: &SubService{remarkModel: "-i"}}
|
||||||
|
inbound := &model.Inbound{
|
||||||
|
Listen: "203.0.113.1",
|
||||||
|
Port: 443,
|
||||||
|
Protocol: model.VLESS,
|
||||||
|
Remark: "plain",
|
||||||
|
Settings: `{"encryption":"none"}`,
|
||||||
|
}
|
||||||
|
client := model.Client{ID: "11111111-2222-4333-8444-555555555555"}
|
||||||
|
stream := map[string]any{
|
||||||
|
"network": "tcp",
|
||||||
|
"security": "none",
|
||||||
|
"tcpSettings": map[string]any{
|
||||||
|
"header": map[string]any{"type": "none"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy := svc.buildProxy(inbound, client, stream, "")
|
||||||
|
|
||||||
|
if _, ok := proxy["encryption"]; ok {
|
||||||
|
t.Fatalf("plain vless encryption should be omitted for mihomo: %#v", proxy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user