Fix VLESS config generation error

This commit is contained in:
riolurs 2025-06-13 20:54:39 +08:00
parent 617a807187
commit 7af8bf572e
2 changed files with 54 additions and 39 deletions

View File

@ -611,8 +611,9 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
break; break;
case ProxyType::VLESS: case ProxyType::VLESS:
singleproxy["type"] = "vless"; singleproxy["type"] = "vless";
singleproxy["packet-encoding"] = "xudp";
singleproxy["tls"] = true; singleproxy["tls"] = true;
if (udp)
singleproxy["packet-encoding"] = "xudp";
if (!x.UUID.empty()) if (!x.UUID.empty())
singleproxy["uuid"] = x.UUID; singleproxy["uuid"] = x.UUID;
if (!x.SNI.empty()) if (!x.SNI.empty())
@ -621,14 +622,15 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
singleproxy["alpn"] = x.Alpn; singleproxy["alpn"] = x.Alpn;
if (!x.Fingerprint.empty()) if (!x.Fingerprint.empty())
singleproxy["fingerprint"] = x.Fingerprint; singleproxy["fingerprint"] = x.Fingerprint;
if (!x.Flow.empty())
singleproxy["flow"] = x.Flow;
if (x.XTLS == 2) { if (x.XTLS == 2) {
singleproxy["flow"] = "xtls-rprx-vision"; singleproxy["flow"] = "xtls-rprx-vision";
} else if (!x.Flow.empty()) {
singleproxy["flow"] = x.Flow;
} }
if (!x.PublicKey.empty() && !x.ShortID.empty()) { if (!x.PublicKey.empty() && !x.ShortID.empty()) {
singleproxy["reality-opts"]["public-key"] = x.PublicKey; singleproxy["reality-opts"]["public-key"] = x.PublicKey;
singleproxy["reality-opts"]["short-id"] = x.ShortID; singleproxy["reality-opts"]["short-id"] = x.ShortID;
singleproxy["client-fingerprint"] = "random";
} }
if (!scv.is_undef()) if (!scv.is_undef())
singleproxy["skip-cert-verify"] = scv.get(); singleproxy["skip-cert-verify"] = scv.get();
@ -2626,9 +2628,11 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
if (!x.SNI.empty()) if (!x.SNI.empty())
proxy.AddMember("sni", rapidjson::StringRef(x.SNI.c_str()), allocator); proxy.AddMember("sni", rapidjson::StringRef(x.SNI.c_str()), allocator);
if (!x.Flow.empty()) if (x.XTLS == 2) {
proxy.AddMember("flow", rapidjson::StringRef("xtls-rprx-vision"), allocator);
} else if (!x.Flow.empty()) {
proxy.AddMember("flow", rapidjson::StringRef(x.Flow.c_str()), allocator); proxy.AddMember("flow", rapidjson::StringRef(x.Flow.c_str()), allocator);
}
// TLS 配置 // TLS 配置
rapidjson::Value tls(rapidjson::kObjectType); rapidjson::Value tls(rapidjson::kObjectType);
tls.AddMember("enabled", true, allocator); tls.AddMember("enabled", true, allocator);
@ -2643,16 +2647,21 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
alpn.PushBack(rapidjson::StringRef(item.c_str()), allocator); alpn.PushBack(rapidjson::StringRef(item.c_str()), allocator);
tls.AddMember("alpn", alpn, allocator); tls.AddMember("alpn", alpn, allocator);
} }
if (x.XTLS == 2){
if (!x.PublicKey.empty() && !x.ShortID.empty()) { if (!x.PublicKey.empty() && !x.ShortID.empty()) {
rapidjson::Value reality(rapidjson::kObjectType); rapidjson::Value reality(rapidjson::kObjectType);
reality.AddMember("enabled", true, allocator); reality.AddMember("enabled", true, allocator);
if (!x.PublicKey.empty()) if (!x.PublicKey.empty())
reality.AddMember("public_key", rapidjson::StringRef(x.PublicKey.c_str()), allocator); reality.AddMember("public_key", rapidjson::StringRef(x.PublicKey.c_str()), allocator);
if (!x.ShortID.empty()) if (!x.ShortID.empty())
reality.AddMember("short_id", rapidjson::StringRef(x.ShortID.c_str()), allocator); reality.AddMember("short_id", rapidjson::StringRef(x.ShortID.c_str()), allocator);
tls.AddMember("reality", reality, allocator); tls.AddMember("reality", reality, allocator);
}
rapidjson::Value utls(rapidjson::kObjectType);
utls.AddMember("enable",true,allocator);
std::array<std::string, 6> fingerprints = {"chrome", "firefox", "safari", "ios", "edge", "qq"};
utls.AddMember("fingerprint", rapidjson::Value(fingerprints[rand() % fingerprints.size()].c_str(), allocator), allocator);
tls.AddMember("utls", utls, allocator);
} }
proxy.AddMember("tls", tls, allocator); proxy.AddMember("tls", tls, allocator);

View File

@ -1829,7 +1829,7 @@ void explodeStdAnyTLS(std::string anytls, Proxy &node) {
// 其他参数 // 其他参数
sni = getUrlArg(addition, "peer"); sni = getUrlArg(addition, "peer");
alpn = getUrlArg(addition, "alpn"); alpn = getUrlArg(addition, "alpn");
fingerprint = getUrlArg(addition, "hpkp"); fingerprint = urlDecode(getUrlArg(addition, "hpkp"));
tfo = tribool(getUrlArg(addition, "tfo")); tfo = tribool(getUrlArg(addition, "tfo"));
scv = tribool(getUrlArg(addition, "insecure")); scv = tribool(getUrlArg(addition, "insecure"));
@ -1871,35 +1871,41 @@ void explodeStdVLESS(std::string vless, Proxy &node) {
vless.erase(pos); vless.erase(pos);
} }
decoded = urlSafeBase64Decode(vless); // 支持 uuid@host:port 格式
if (strFind(vless, "@")) {
// 尝试从URL参数中获取uuid if (regGetMatch(vless, R"(^(.*?)@(.*?):(\d+)$)", 4, 0, &uuid, &add, &port))
uuid = getUrlArg(addition, "uuid");
// 如果URL参数中没有uuid尝试从decoded中解析
if (uuid.empty() && strFind(decoded, "@") && strFind(decoded, ":")) {
userinfo = decoded.substr(0, decoded.find('@'));
hostinfo = decoded.substr(decoded.find('@') + 1);
if (strFind(userinfo, ":")) {
user_parts = split(userinfo, ":");
if (user_parts.size() >= 2) {
uuid = user_parts[1];
}
} else {
uuid = userinfo;
}
if (regGetMatch(hostinfo, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0)
return; return;
} else if (regGetMatch(vless, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0) { } else {
return; decoded = urlSafeBase64Decode(vless);
uuid = getUrlArg(addition, "uuid");
if (uuid.empty() && strFind(decoded, "@") && strFind(decoded, ":")) {
userinfo = decoded.substr(0, decoded.find('@'));
hostinfo = decoded.substr(decoded.find('@') + 1);
if (strFind(userinfo, ":")) {
user_parts = split(userinfo, ":");
if (user_parts.size() >= 2) {
uuid = user_parts[1];
}
} else {
uuid = userinfo;
}
if (regGetMatch(hostinfo, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0)
return;
} else if (regGetMatch(vless, R"(^(.*?):(\d+)$)", 3, 0, &add, &port) != 0) {
return;
}
} }
if (uuid.empty()) return; if (uuid.empty()) return;
if (!addition.empty()) { if (!addition.empty()) {
sni = getUrlArg(addition, "peer"); sni = getUrlArg(addition, "sni");
if (sni.empty()) {
sni = getUrlArg(addition, "peer");
}
alpn = getUrlArg(addition, "alpn"); alpn = getUrlArg(addition, "alpn");
fingerprint = getUrlArg(addition, "hpkp"); fingerprint = getUrlArg(addition, "hpkp");
flow = getUrlArg(addition, "flow"); flow = getUrlArg(addition, "flow");