mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-28 12:22:37 +00:00
Fix the issue of missing sni parameters in vless, hysteria, and hysteria2. Fix the problem of dirty data during Singbox conversion. (#4)
This commit is contained in:
@@ -446,8 +446,8 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
|
||||
singleproxy["fast-open"] = tfo.get();}
|
||||
if (!x.FakeType.empty())
|
||||
singleproxy["protocol"] = x.FakeType;
|
||||
if (!x.Host.empty())
|
||||
singleproxy["sni"] = x.Host;
|
||||
if (!x.ServerName.empty())
|
||||
singleproxy["sni"] = x.ServerName;
|
||||
if (!scv.is_undef())
|
||||
singleproxy["skip-cert-verify"] = scv.get();
|
||||
if (x.Insecure == "1")
|
||||
@@ -461,12 +461,12 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
|
||||
singleproxy["type"] = "hysteria2";
|
||||
singleproxy["password"] = x.Password;
|
||||
singleproxy["auth"] = x.Password;
|
||||
if (!x.ServerName.empty())
|
||||
singleproxy["sni"] = x.ServerName;
|
||||
if (!x.UpMbps.empty())
|
||||
singleproxy["up"] = x.UpMbps;
|
||||
if (!x.DownMbps.empty())
|
||||
singleproxy["down"] = x.DownMbps;
|
||||
if (!x.Host.empty())
|
||||
singleproxy["sni"] = x.Host;
|
||||
if (!scv.is_undef())
|
||||
singleproxy["skip-cert-verify"] = scv.get();
|
||||
if (!x.Alpn.empty())
|
||||
@@ -484,8 +484,6 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
|
||||
singleproxy["tfo"] = tfo.get();
|
||||
if (xudp && udp)
|
||||
singleproxy["xudp"] = true;
|
||||
if (!x.Host.empty())
|
||||
singleproxy["servername"] = x.Host;
|
||||
if (!x.Flow.empty())
|
||||
singleproxy["flow"] = x.Flow;
|
||||
if (!scv.is_undef())
|
||||
@@ -493,6 +491,8 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
|
||||
if (!x.PublicKey.empty()) {
|
||||
singleproxy["reality-opts"]["public-key"] = x.PublicKey;
|
||||
}
|
||||
if (!x.ServerName.empty())
|
||||
singleproxy["servername"] = x.ServerName;
|
||||
if (!x.ShortId.empty()) {
|
||||
singleproxy["reality-opts"]["short-id"] = x.ShortId;
|
||||
}
|
||||
@@ -2334,6 +2334,9 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::vector
|
||||
auto alpns = stringArrayToJsonArray(x.Alpn, ",", allocator);
|
||||
tls.AddMember("alpn", alpns, allocator);
|
||||
}
|
||||
if (!x.ServerName.empty()) {
|
||||
tls.AddMember("server_name", rapidjson::StringRef(x.ServerName.c_str()), allocator);
|
||||
}
|
||||
tls.AddMember("insecure", buildBooleanValue(scv), allocator);
|
||||
proxy.AddMember("tls", tls, allocator);
|
||||
}
|
||||
@@ -2349,6 +2352,8 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::vector
|
||||
if (!x.TLSSecure) {
|
||||
rapidjson::Value tls(rapidjson::kObjectType);
|
||||
tls.AddMember("enabled", true, allocator);
|
||||
if (!x.ServerName.empty())
|
||||
tls.AddMember("server_name", rapidjson::StringRef(x.ServerName.c_str()), allocator);
|
||||
if (!x.Alpn.empty()) {
|
||||
auto alpns = stringArrayToJsonArray(x.Alpn, ",", allocator);
|
||||
tls.AddMember("alpn", alpns, allocator);
|
||||
@@ -2401,10 +2406,6 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::vector
|
||||
if (x.Type == ProxyType::VLESS) {
|
||||
rapidjson::Value reality(rapidjson::kObjectType);
|
||||
if (!x.PublicKey.empty() || !x.ShortId.empty()) {
|
||||
if (!x.Host.empty()) {
|
||||
tls.EraseMember("server_name");
|
||||
tls.AddMember("server_name", rapidjson::StringRef(x.Host.c_str()), allocator);
|
||||
}
|
||||
rapidjson::Value utls(rapidjson::kObjectType);
|
||||
utls.AddMember("enabled", true, allocator);
|
||||
utls.AddMember("fingerprint", rapidjson::StringRef("chrome"), allocator);
|
||||
|
||||
@@ -160,7 +160,8 @@ void hysteriaConstruct(Proxy &node, const std::string &group, const std::string
|
||||
const std::string &port, const std::string &type, const std::string &auth,
|
||||
const std::string &auth_str,
|
||||
const std::string &host, const std::string &up, const std::string &down, const std::string &alpn,
|
||||
const std::string &obfsParam, const std::string &insecure, const std::string &ports, tribool udp,
|
||||
const std::string &obfsParam, const std::string &insecure, const std::string &ports,
|
||||
const std::string &sni, tribool udp,
|
||||
tribool tfo, tribool scv,
|
||||
tribool tls13) {
|
||||
commonConstruct(node, ProxyType::Hysteria, group, remarks, add, port, udp, tfo, scv, tls13);
|
||||
@@ -174,6 +175,7 @@ void hysteriaConstruct(Proxy &node, const std::string &group, const std::string
|
||||
node.FakeType = type;
|
||||
node.AuthStr = auth_str;
|
||||
node.Ports = ports;
|
||||
node.ServerName = sni;
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +183,8 @@ void vlessConstruct(Proxy &node, const std::string &group, const std::string &re
|
||||
const std::string &port, const std::string &type, const std::string &id, const std::string &aid,
|
||||
const std::string &net, const std::string &cipher, const std::string &flow, const std::string &mode,
|
||||
const std::string &path, const std::string &host, const std::string &edge, const std::string &tls,
|
||||
const std::string &pbk, const std::string &sid, const std::string &fp, tribool udp, tribool tfo,
|
||||
const std::string &pbk, const std::string &sid, const std::string &fp, const std::string &sni,
|
||||
tribool udp, tribool tfo,
|
||||
tribool scv, tribool tls13) {
|
||||
commonConstruct(node, ProxyType::VLESS, group, remarks, add, port, udp, tfo, scv, tls13);
|
||||
node.UserId = id.empty() ? "00000000-0000-0000-0000-000000000000" : id;
|
||||
@@ -195,6 +198,7 @@ void vlessConstruct(Proxy &node, const std::string &group, const std::string &re
|
||||
node.PublicKey = pbk;
|
||||
node.ShortId = sid;
|
||||
node.Fingerprint = fp;
|
||||
node.ServerName = sni;
|
||||
switch (hash_(net)) {
|
||||
case "grpc"_hash:
|
||||
node.Host = host;
|
||||
@@ -216,7 +220,8 @@ void vlessConstruct(Proxy &node, const std::string &group, const std::string &re
|
||||
void hysteria2Construct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add,
|
||||
const std::string &port, const std::string &password, const std::string &host,
|
||||
const std::string &up, const std::string &down, const std::string &alpn,
|
||||
const std::string &obfsParam, const std::string &obfsPassword, tribool udp, tribool tfo,
|
||||
const std::string &obfsParam, const std::string &obfsPassword, const std::string &sni,
|
||||
tribool udp, tribool tfo,
|
||||
tribool scv) {
|
||||
commonConstruct(node, ProxyType::Hysteria2, group, remarks, add, port, udp, tfo, scv, tribool());
|
||||
node.Password = password;
|
||||
@@ -226,6 +231,7 @@ void hysteria2Construct(Proxy &node, const std::string &group, const std::string
|
||||
node.Alpn = alpn;
|
||||
node.OBFSParam = obfsParam;
|
||||
node.OBFSPassword = obfsPassword;
|
||||
node.ServerName = sni;
|
||||
}
|
||||
|
||||
void explodeVmess(std::string vmess, Proxy &node) {
|
||||
@@ -1306,7 +1312,7 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes) {
|
||||
singleproxy["flow"] >>= flow;
|
||||
|
||||
vlessConstruct(node, XRAY_DEFAULT_GROUP, ps, server, port, type, id, aid, net, "auto", flow, mode, path,
|
||||
host, "", tls, pbk, sid, fp);
|
||||
host, "", tls, pbk, sid, fp, sni);
|
||||
break;
|
||||
case "hysteria"_hash:
|
||||
group = HYSTERIA_DEFAULT_GROUP;
|
||||
@@ -1325,9 +1331,9 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes) {
|
||||
singleproxy["alpn"][0] >> alpn;
|
||||
singleproxy["protocol"] >> insecure;
|
||||
singleproxy["ports"] >> ports;
|
||||
|
||||
sni = host;
|
||||
hysteriaConstruct(node, group, ps, server, port, type, auth, "", host, up, down, alpn, obfsParam,
|
||||
insecure, ports,
|
||||
insecure, ports, sni,
|
||||
udp, tfo, scv);
|
||||
break;
|
||||
case "hysteria2"_hash:
|
||||
@@ -1341,9 +1347,9 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes) {
|
||||
singleproxy["obfs-password"] >>= obfsPassword;
|
||||
singleproxy["sni"] >>= host;
|
||||
singleproxy["alpn"][0] >>= alpn;
|
||||
|
||||
sni = host;
|
||||
hysteria2Construct(node, group, ps, server, port, password, host, up, down, alpn, obfsParam,
|
||||
obfsPassword, udp, tfo, scv);
|
||||
obfsPassword, sni, udp, tfo, scv);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
@@ -1397,7 +1403,7 @@ void explodeStdVMess(std::string vmess, Proxy &node) {
|
||||
|
||||
|
||||
void explodeStdHysteria(std::string hysteria, Proxy &node) {
|
||||
std::string add, port, type, auth, host, insecure, up, down, alpn, obfsParam, remarks, auth_str;
|
||||
std::string add, port, type, auth, host, insecure, up, down, alpn, obfsParam, remarks, auth_str, sni;
|
||||
std::string addition;
|
||||
hysteria = hysteria.substr(11);
|
||||
string_size pos;
|
||||
@@ -1419,17 +1425,19 @@ void explodeStdHysteria(std::string hysteria, Proxy &node) {
|
||||
down = getUrlArg(addition, "downmbps");
|
||||
alpn = getUrlArg(addition, "alpn");
|
||||
obfsParam = getUrlArg(addition, "obfsParam");
|
||||
sni = getUrlArg(addition, "peer");
|
||||
|
||||
if (remarks.empty())
|
||||
remarks = add + ":" + port;
|
||||
|
||||
hysteriaConstruct(node, HYSTERIA_DEFAULT_GROUP, remarks, add, port, type, auth, auth_str, host, up, down, alpn,
|
||||
obfsParam,
|
||||
insecure, "");
|
||||
insecure, "", sni);
|
||||
return;
|
||||
}
|
||||
|
||||
void explodeStdHysteria2(std::string hysteria2, Proxy &node) {
|
||||
std::string add, port, password, host, insecure, up, down, alpn, obfsParam, obfsPassword, remarks;
|
||||
std::string add, port, password, host, insecure, up, down, alpn, obfsParam, obfsPassword, remarks, sni;
|
||||
std::string addition;
|
||||
tribool scv;
|
||||
hysteria2 = hysteria2.substr(12);
|
||||
@@ -1469,18 +1477,18 @@ void explodeStdHysteria2(std::string hysteria2, Proxy &node) {
|
||||
obfsParam = getUrlArg(addition, "obfs");
|
||||
obfsPassword = getUrlArg(addition, "obfs-password");
|
||||
host = getUrlArg(addition, "sni");
|
||||
|
||||
sni = getUrlArg(addition, "sni");
|
||||
if (remarks.empty())
|
||||
remarks = add + ":" + port;
|
||||
|
||||
hysteria2Construct(node, HYSTERIA2_DEFAULT_GROUP, remarks, add, port, password, host, up, down, alpn, obfsParam,
|
||||
obfsPassword, tribool(), tribool(), scv);
|
||||
obfsPassword, host, tribool(), tribool(), scv);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void explodeStdVless(std::string vless, Proxy &node) {
|
||||
std::string add, port, type, id, aid, net, flow, pbk, sid, fp, mode, path, host, tls, remarks;
|
||||
std::string add, port, type, id, aid, net, flow, pbk, sid, fp, mode, path, host, tls, remarks, sni;
|
||||
std::string addition;
|
||||
vless = vless.substr(8);
|
||||
string_size pos;
|
||||
@@ -1525,9 +1533,9 @@ void explodeStdVless(std::string vless, Proxy &node) {
|
||||
|
||||
if (remarks.empty())
|
||||
remarks = add + ":" + port;
|
||||
|
||||
sni = getUrlArg(addition, "sni");
|
||||
vlessConstruct(node, XRAY_DEFAULT_GROUP, remarks, add, port, type, id, aid, net, "auto", flow, mode, path, host, "",
|
||||
tls, pbk, sid, fp);
|
||||
tls, pbk, sid, fp, sni);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2480,6 +2488,11 @@ void explodeSingboxTransport(rapidjson::Value &singboxNode, std::string &net, st
|
||||
path.clear();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
net = "tcp";
|
||||
host.clear();
|
||||
edge.clear();
|
||||
path.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2603,7 +2616,7 @@ void explodeSingbox(rapidjson::Value &outbounds, std::vector<Proxy> &nodes) {
|
||||
}
|
||||
}
|
||||
vlessConstruct(node, group, ps, server, port, type, id, aid, net, "auto", flow, mode, path,
|
||||
host, "", tls, pbk, sid, fp);
|
||||
host, "", tls, pbk, sid, fp, sni);
|
||||
break;
|
||||
case "http"_hash:
|
||||
password = GetMember(singboxNode, "password");
|
||||
@@ -2642,7 +2655,7 @@ void explodeSingbox(rapidjson::Value &outbounds, std::vector<Proxy> &nodes) {
|
||||
type = GetMember(singboxNode, "network");
|
||||
obfsParam = GetMember(singboxNode, "obfs");
|
||||
hysteriaConstruct(node, group, ps, server, port, type, auth, "", host, up, down, alpn,
|
||||
obfsParam, insecure, ports,
|
||||
obfsParam, insecure, ports, sni,
|
||||
udp, tfo, scv);
|
||||
break;
|
||||
case "hysteria2"_hash:
|
||||
@@ -2656,7 +2669,7 @@ void explodeSingbox(rapidjson::Value &outbounds, std::vector<Proxy> &nodes) {
|
||||
obfsPassword = GetMember(obfsOpt, "password");
|
||||
}
|
||||
hysteria2Construct(node, group, ps, server, port, password, host, up, down, alpn, obfsParam,
|
||||
obfsPassword, udp, tfo, scv);
|
||||
obfsPassword, sni, udp, tfo, scv);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
|
||||
@@ -19,9 +19,9 @@ enum class ConfType
|
||||
SUB,
|
||||
Local
|
||||
};
|
||||
void hysteriaConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &auth, const std::string &auth_str, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &insecure,const std::string &ports,tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void hysteria2Construct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &password, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &obfsPassword, const std::string &insecure ,tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void vlessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &flow, const std::string &mode, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls,const std::string &pkd, const std::string &sid, const std::string &fp, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void hysteriaConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &auth, const std::string &auth_str, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &insecure,const std::string &ports,const std::string &sni,tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void hysteria2Construct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &password, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &obfsPassword, const std::string &sni, const std::string &insecure ,tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void vlessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &flow, const std::string &mode, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls,const std::string &pkd, const std::string &sid, const std::string &fp,const std::string &sni, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, const std::string &sni, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
void ssrConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &protocol, const std::string &method, const std::string &obfs, const std::string &password, const std::string &obfsparam, const std::string &protoparam, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool());
|
||||
void ssConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &password, const std::string &method, const std::string &plugin, const std::string &pluginopts, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
|
||||
|
||||
Reference in New Issue
Block a user