Skip to content

Commit 0ea729e

Browse files
committed
Fix VLESS config generation error
1 parent 617a807 commit 0ea729e

2 files changed

Lines changed: 53 additions & 35 deletions

File tree

src/generator/config/subexport.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,9 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
611611
break;
612612
case ProxyType::VLESS:
613613
singleproxy["type"] = "vless";
614-
singleproxy["packet-encoding"] = "xudp";
615614
singleproxy["tls"] = true;
615+
if (udp)
616+
singleproxy["packet-encoding"] = "xudp";
616617
if (!x.UUID.empty())
617618
singleproxy["uuid"] = x.UUID;
618619
if (!x.SNI.empty())
@@ -621,14 +622,15 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
621622
singleproxy["alpn"] = x.Alpn;
622623
if (!x.Fingerprint.empty())
623624
singleproxy["fingerprint"] = x.Fingerprint;
624-
if (!x.Flow.empty())
625-
singleproxy["flow"] = x.Flow;
626625
if (x.XTLS == 2) {
627626
singleproxy["flow"] = "xtls-rprx-vision";
627+
} else if (!x.Flow.empty()) {
628+
singleproxy["flow"] = x.Flow;
628629
}
629630
if (!x.PublicKey.empty() && !x.ShortID.empty()) {
630631
singleproxy["reality-opts"]["public-key"] = x.PublicKey;
631632
singleproxy["reality-opts"]["short-id"] = x.ShortID;
633+
singleproxy["client-fingerprint"] = "random";
632634
}
633635
if (!scv.is_undef())
634636
singleproxy["skip-cert-verify"] = scv.get();
@@ -2626,9 +2628,11 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
26262628
if (!x.SNI.empty())
26272629
proxy.AddMember("sni", rapidjson::StringRef(x.SNI.c_str()), allocator);
26282630

2629-
if (!x.Flow.empty())
2631+
if (x.XTLS == 2) {
2632+
proxy.AddMember("flow", rapidjson::StringRef("xtls-rprx-vision"), allocator);
2633+
} else if (!x.Flow.empty()) {
26302634
proxy.AddMember("flow", rapidjson::StringRef(x.Flow.c_str()), allocator);
2631-
2635+
}
26322636
// TLS 配置
26332637
rapidjson::Value tls(rapidjson::kObjectType);
26342638
tls.AddMember("enabled", true, allocator);
@@ -2643,16 +2647,21 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
26432647
alpn.PushBack(rapidjson::StringRef(item.c_str()), allocator);
26442648
tls.AddMember("alpn", alpn, allocator);
26452649
}
2646-
if (x.XTLS == 2){
2647-
if (!x.PublicKey.empty() && !x.ShortID.empty()) {
2648-
rapidjson::Value reality(rapidjson::kObjectType);
2649-
reality.AddMember("enabled", true, allocator);
2650-
if (!x.PublicKey.empty())
2651-
reality.AddMember("public_key", rapidjson::StringRef(x.PublicKey.c_str()), allocator);
2652-
if (!x.ShortID.empty())
2653-
reality.AddMember("short_id", rapidjson::StringRef(x.ShortID.c_str()), allocator);
2654-
tls.AddMember("reality", reality, allocator);
2655-
}
2650+
2651+
if (!x.PublicKey.empty() && !x.ShortID.empty()) {
2652+
rapidjson::Value reality(rapidjson::kObjectType);
2653+
reality.AddMember("enabled", true, allocator);
2654+
if (!x.PublicKey.empty())
2655+
reality.AddMember("public_key", rapidjson::StringRef(x.PublicKey.c_str()), allocator);
2656+
if (!x.ShortID.empty())
2657+
reality.AddMember("short_id", rapidjson::StringRef(x.ShortID.c_str()), allocator);
2658+
tls.AddMember("reality", reality, allocator);
2659+
2660+
rapidjson::Value utls(rapidjson::kObjectType);
2661+
utls.AddMember("enable",true,allocator);
2662+
std::array<std::string, 6> fingerprints = {"chrome", "firefox", "safari", "ios", "edge", "qq"};
2663+
utls.AddMember("fingerprint", rapidjson::Value(fingerprints[rand() % fingerprints.size()].c_str(), allocator), allocator);
2664+
tls.AddMember("utls", utls, allocator);
26562665
}
26572666

26582667
proxy.AddMember("tls", tls, allocator);

src/parser/subparser.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ void explodeStdAnyTLS(std::string anytls, Proxy &node) {
18291829
// 其他参数
18301830
sni = getUrlArg(addition, "peer");
18311831
alpn = getUrlArg(addition, "alpn");
1832-
fingerprint = getUrlArg(addition, "hpkp");
1832+
fingerprint = urlDecode(getUrlArg(addition, "hpkp"));
18331833
tfo = tribool(getUrlArg(addition, "tfo"));
18341834
scv = tribool(getUrlArg(addition, "insecure"));
18351835

@@ -1871,35 +1871,44 @@ void explodeStdVLESS(std::string vless, Proxy &node) {
18711871
vless.erase(pos);
18721872
}
18731873

1874-
decoded = urlSafeBase64Decode(vless);
1875-
1876-
// 尝试从URL参数中获取uuid
1877-
uuid = getUrlArg(addition, "uuid");
1874+
pos = vless.find("@");
1875+
if (pos != vless.npos) {
1876+
// 直接从URL中提取UUID
1877+
uuid = vless.substr(0, pos);
1878+
hostinfo = vless.substr(pos + 1);
1879+
if (regGetMatch(hostinfo, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0)
1880+
return;
1881+
} else {
1882+
decoded = urlSafeBase64Decode(vless);
1883+
uuid = getUrlArg(addition, "uuid");
18781884

1879-
// 如果URL参数中没有uuid,尝试从decoded中解析
1880-
if (uuid.empty() && strFind(decoded, "@") && strFind(decoded, ":")) {
1881-
userinfo = decoded.substr(0, decoded.find('@'));
1882-
hostinfo = decoded.substr(decoded.find('@') + 1);
1885+
if (uuid.empty() && strFind(decoded, "@") && strFind(decoded, ":")) {
1886+
userinfo = decoded.substr(0, decoded.find('@'));
1887+
hostinfo = decoded.substr(decoded.find('@') + 1);
18831888

1884-
if (strFind(userinfo, ":")) {
1885-
user_parts = split(userinfo, ":");
1886-
if (user_parts.size() >= 2) {
1887-
uuid = user_parts[1];
1889+
if (strFind(userinfo, ":")) {
1890+
user_parts = split(userinfo, ":");
1891+
if (user_parts.size() >= 2) {
1892+
uuid = user_parts[1];
1893+
}
1894+
} else {
1895+
uuid = userinfo;
18881896
}
1889-
} else {
1890-
uuid = userinfo;
1891-
}
18921897

1893-
if (regGetMatch(hostinfo, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0)
1898+
if (regGetMatch(hostinfo, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0)
1899+
return;
1900+
} else if (regGetMatch(vless, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0) {
18941901
return;
1895-
} else if (regGetMatch(vless, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0) {
1896-
return;
1902+
}
18971903
}
18981904

18991905
if (uuid.empty()) return;
19001906

19011907
if (!addition.empty()) {
1902-
sni = getUrlArg(addition, "peer");
1908+
sni = getUrlArg(addition, "sni");
1909+
if (sni.empty()) {
1910+
sni = getUrlArg(addition, "peer");
1911+
}
19031912
alpn = getUrlArg(addition, "alpn");
19041913
fingerprint = getUrlArg(addition, "hpkp");
19051914
flow = getUrlArg(addition, "flow");

0 commit comments

Comments
 (0)