From 5870ab238686da18ce04430ac38ded74f88f726b Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Sat, 4 Jan 2020 17:29:44 +0800 Subject: [PATCH] Enhancements Add skip-cert-verify flag for HTTPS / Socks 5 nodes in Clash / Surge subscriptions. Tweaked keys order in Clash subscriptions. Optimize codes. --- src/speedtestutil.cpp | 32 ++++++++++++++++++++----------- src/subexport.cpp | 44 ++++++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index ed0cacc..85909ef 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -840,11 +840,11 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v if(singleproxy["tls"].IsDefined()) tls = singleproxy["tls"].as() == "true" ? "tls" : ""; else - tls = ""; + tls.clear(); if(singleproxy["ws-headers"].IsDefined()) singleproxy["ws-headers"]["Host"] >> host; else - host = ""; + host.clear(); node.linkType = SPEEDTEST_MESSAGE_FOUNDVMESS; @@ -867,7 +867,7 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v if(singleproxy["plugin-opts"]["host"].IsDefined()) singleproxy["plugin-opts"]["host"] >> pluginopts_host; else - pluginopts_host = ""; + pluginopts_host.clear(); } } else if(singleproxy["plugin"].as() == "v2ray-plugin") @@ -879,19 +879,19 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v if(singleproxy["plugin-opts"]["host"].IsDefined()) singleproxy["plugin-opts"]["host"] >> pluginopts_host; else - pluginopts_host = ""; + pluginopts_host.clear(); if(singleproxy["plugin-opts"]["tls"].IsDefined()) tls = singleproxy["plugin-opts"]["tls"].as() ? "tls;" : ""; else - tls = ""; + tls.clear(); if(singleproxy["plugin-opts"]["path"].IsDefined()) singleproxy["plugin-opts"]["path"] >> path; else - path = ""; + path.clear(); if(singleproxy["plugin-opts"]["mux"].IsDefined()) pluginopts_mux = singleproxy["plugin-opts"]["mux"].as() ? "mux=4;" : ""; else - pluginopts_mux = ""; + pluginopts_mux.clear(); } } } @@ -903,7 +903,7 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v singleproxy["obfs-host"] >> pluginopts_host; } else - plugin = ""; + plugin.clear(); if(plugin == "simple-obfs") { @@ -921,7 +921,7 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v pluginopts += "mux=" + pluginopts_mux + ";"; } else - pluginopts = ""; + pluginopts.clear(); //support for go-shadowsocks2 if(cipher == "AEAD_CHACHA20_POLY1305") @@ -944,6 +944,11 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v singleproxy["username"] >> user; singleproxy["password"] >> password; } + else + { + user.clear(); + password.clear(); + } node.linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS; node.proxyStr = socksConstruct(ps, server, port, user, password); @@ -971,6 +976,11 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v singleproxy["username"] >> user; singleproxy["password"] >> password; } + else + { + user.clear(); + password.clear(); + } node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP; node.proxyStr = httpConstruct(ps, server, port, user, password); @@ -1140,7 +1150,7 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st port = custom_port == "" ? trim(configs[2]) : custom_port; method = trim(configs[3]); password = trim(configs[4]); - plugin = ""; + plugin.clear(); for(i = 6; i < configs.size(); i++) { @@ -1174,7 +1184,7 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st { server = trim(configs[1]); port = custom_port == "" ? trim(configs[2]) : custom_port; - plugin = ""; + plugin.clear(); for(i = 3; i < configs.size(); i++) { diff --git a/src/subexport.cpp b/src/subexport.cpp index b1c6625..eefc2de 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -535,6 +535,10 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr password = GetMember(json, "Password"); method = GetMember(json, "EncryptMethod"); + singleproxy["name"] = remark; + singleproxy["server"] = hostname; + singleproxy["port"] = (unsigned short)stoi(port); + if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSS) { //latest clash core removed support for chacha20 encryption @@ -544,6 +548,7 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr pluginopts = replace_all_distinct(GetMember(json, "PluginOption"), ";", "&"); singleproxy["type"] = "ss"; singleproxy["cipher"] = method; + singleproxy["password"] = password; if(plugin == "simple-obfs" || plugin == "obfs-local") { singleproxy["plugin"] = "obfs"; @@ -602,6 +607,7 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr obfsparam = GetMember(json, "OBFSParam"); singleproxy["type"] = "ssr"; singleproxy["cipher"] = method; + singleproxy["password"] = password; singleproxy["protocol"] = protocol; singleproxy["protocolparam"] = protoparam; singleproxy["obfs"] = obfs; @@ -611,19 +617,22 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr { singleproxy["type"] = "socks5"; singleproxy["username"] = username; + singleproxy["password"] = password; + if(ext.skip_cert_verify) + singleproxy["skip-cert-verify"] = true; } else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDHTTP) { singleproxy["type"] = "http"; singleproxy["username"] = username; + singleproxy["password"] = password; singleproxy["tls"] = type == "HTTPS"; + if(ext.skip_cert_verify) + singleproxy["skip-cert-verify"] = true; } else continue; - singleproxy["password"] = password; - singleproxy["name"] = remark; - singleproxy["server"] = hostname; - singleproxy["port"] = (unsigned short)stoi(port); + if(ext.udp) singleproxy["udp"] = true; singleproxy.SetStyle(YAML::EmitterStyle::Flow); @@ -654,6 +663,9 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr if(vArray.size() < 3) continue; + singlegroup["name"] = vArray[0]; + singlegroup["type"] = vArray[1]; + if(vArray[1] == "select") { rules_upper_bound = vArray.size(); @@ -675,8 +687,6 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, string_arr if(!filtered_nodelist.size()) filtered_nodelist.emplace_back("DIRECT"); - singlegroup["name"] = vArray[0]; - singlegroup["type"] = vArray[1]; singlegroup["proxies"] = filtered_nodelist; //singlegroup.SetStyle(YAML::EmitterStyle::Flow); @@ -783,7 +793,7 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s username = GetMember(json, "Username"); password = GetMember(json, "Password"); method = GetMember(json, "EncryptMethod"); - proxy = ""; + proxy.clear(); if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSS) { @@ -851,16 +861,16 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s } else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSOCKS) { - proxy = "socks5, " + hostname + ", " + port; - if(username.size() && password.size()) - proxy += ", " + username + ", " + password; + proxy = "socks5, " + hostname + ", " + port + ", " + username + ", " + password; + if(ext.skip_cert_verify) + proxy += ", skip-cert-verify=1"; } else if(type == "HTTP" || type == "HTTPS") { - proxy = "http," + hostname + "," + port; - if(username != "" && password != "") - proxy += ", " + username + ", " + password; + proxy = "http," + hostname + "," + port + ", " + username + ", " + password; proxy += std::string(", tls=") + (type == "HTTPS" ? "true" : "false"); + if(ext.skip_cert_verify) + proxy += ", skip-cert-verify=1"; } else continue; @@ -887,8 +897,8 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s { eraseElements(filtered_nodelist); unsigned int rules_upper_bound = 0; - url = ""; - proxy = ""; + url.clear(); + proxy.clear(); vArray = split(x, "`"); if(vArray.size() < 3) @@ -1539,8 +1549,8 @@ void netchToMellow(std::vector &nodes, INIReader &ini, std::vector