From 7d0337401647555eda3bac98d07bdfe9d0b6dac1 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Tue, 21 Jan 2020 00:37:45 +0800 Subject: [PATCH] Bug fixes Fix incorrect format for exporting Quantumult VMess subscriptions. Fix parser not recognize over-tls obfs in Quantumult X VMess subscriptions. Fix potential compatibility issue for non-standard VMess subscriptions. Add basic support for acquiring headers during subscription download. --- src/speedtestutil.cpp | 2 ++ src/subexport.cpp | 11 +++++++++-- src/webget.cpp | 12 ++++++++++-- src/webget.h | 3 ++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index c6713f4..9ce32ab 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -1245,6 +1245,8 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st { if(itemVal == "ws") net = "ws"; + else if(itemVal == "over-tls") + tls = "tls"; } else if(itemName == "obfs-host") host = itemVal; diff --git a/src/subexport.cpp b/src/subexport.cpp index b5a45cc..5db4f25 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -69,6 +69,9 @@ std::string vmessConstruct(std::string add, std::string port, std::string type, host = add; if(!id.size()) id = "00000000-0000-0000-0000-000000000000"; //fill this field for node with empty id + host = trim(host); + path = trim(path); + rapidjson::StringBuffer sb; rapidjson::Writer writer(sb); writer.StartObject(); @@ -1273,12 +1276,12 @@ std::string netchToQuan(std::vector &nodes, extra_settings &ext) if(method == "auto") method = "chacha20-ietf-poly1305"; proxyStr = remark + " = vmess, " + hostname + ", " + port + ", " + method + ", \"" + id + "\", group=" + x.group; - if(transproto == "ws") - proxyStr += ", obfs=ws, obfs-path=" + path + ", obfs-header=\"Host: " + host + "\""; if(tlssecure) proxyStr += ", over-tls=true, tls-host=" + host; if(ext.skip_cert_verify) proxyStr += ", certificate=0"; + if(transproto == "ws") + proxyStr += ", obfs=ws, obfs-path=\"" + path + "\", obfs-header=\"Host: " + host + "\""; proxyStr = "vmess://" + urlsafe_base64_encode(proxyStr); break; case SPEEDTEST_MESSAGE_FOUNDSSR: @@ -1319,6 +1322,7 @@ std::string netchToQuanX(std::vector &nodes, extra_settings &ext) std::string id, transproto, host, path; std::string protocol, protoparam, obfs, obfsparam; std::string proxyStr, allLinks; + bool tlssecure; std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x) { @@ -1358,11 +1362,14 @@ std::string netchToQuanX(std::vector &nodes, extra_settings &ext) transproto = GetMember(json, "TransferProtocol"); host = GetMember(json, "Host"); path = GetMember(json, "Path"); + tlssecure = GetMember(json, "TLSSecure") == "true"; if(method == "auto") method = "chacha20-ietf-poly1305"; proxyStr = "vmess = " + hostname + ":" + port + ", method=" + method + ", password=" + id; if(transproto == "ws") proxyStr += ", obfs=ws, obfs-host=" + host + ", obfs-uri=" + path; + else if(tlssecure) + proxyStr += ", obfs=over-tls"; if(ext.skip_cert_verify) proxyStr += ", certificate=0"; break; diff --git a/src/webget.cpp b/src/webget.cpp index 36cad67..02cad2f 100644 --- a/src/webget.cpp +++ b/src/webget.cpp @@ -20,7 +20,7 @@ static int writer(char *data, size_t size, size_t nmemb, std::string *writerData return size * nmemb; } -std::string curlGet(std::string url, std::string proxy) +std::string curlGet(std::string url, std::string proxy, std::string &response_headers) { CURL *curl_handle; std::string data; @@ -38,6 +38,8 @@ std::string curlGet(std::string url, std::string proxy) curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, user_agent_str.data()); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &data); + curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, writer); + curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, &response_headers); if(proxy != "") curl_easy_setopt(curl_handle, CURLOPT_PROXY, proxy.data()); @@ -54,9 +56,15 @@ std::string buildSocks5ProxyString(std::string addr, int port, std::string usern return proxystr; } +std::string webGet(std::string url, std::string proxy, std::string &response_headers) +{ + return curlGet(url, proxy, response_headers); +} + std::string webGet(std::string url, std::string proxy) { - return curlGet(url, proxy); + std::string dummy; + return curlGet(url, proxy, dummy); } int curlPost(std::string url, std::string data, std::string proxy, std::string auth_token, std::string *retData) diff --git a/src/webget.h b/src/webget.h index dcfd664..af98e18 100644 --- a/src/webget.h +++ b/src/webget.h @@ -9,7 +9,8 @@ #include "misc.h" -std::string webGet(std::string url, std::string proxy = ""); +std::string webGet(std::string url, std::string proxy); +std::string webGet(std::string url, std::string proxy, std::string &response_headers); std::string httpGet(std::string host, std::string addr, std::string uri); std::string httpsGet(std::string host, std::string addr, std::string uri); int curlPost(std::string url, std::string data, std::string proxy, std::string auth_token, std::string *retData);