Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wireguard link support #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
if (!x.ShortId.empty())
singleproxy["reality-opts"]["short-id"] = x.ShortId;
}
singleproxy["client-fingerprint"] = "chrome";
if (!x.Fingerprint.empty())
singleproxy["client-fingerprint"] = x.Fingerprint;
if (x.Type != ProxyType::WireGuard){
singleproxy["client-fingerprint"] = "chrome";
if (!x.Fingerprint.empty())
singleproxy["client-fingerprint"] = x.Fingerprint;
}
switch (x.Type) {
case ProxyType::Shadowsocks:
//latest clash core removed support for chacha20 encryption
Expand Down Expand Up @@ -532,6 +534,21 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
if(std::all_of(x.Password.begin(), x.Password.end(), ::isdigit) && !x.Password.empty())
singleproxy["password"].SetTag("str");
break;
case ProxyType::WireGuard:
if (x.DNS.size() > 1)
singleproxy["dns"] = x.DNS;
singleproxy["group"] = x.Group;
singleproxy["ip"] = x.Host;
singleproxy["name"] = x.Remark;
singleproxy["port"] = x.Port;
singleproxy["private-key"] = x.WireGuardPrivateKey;
singleproxy["public-key"] = x.WireGuardPublicKey;
singleproxy["remote-dns-resolve"] = true;
singleproxy["server"] = x.Hostname;
singleproxy["type"] = getProxyTypeName(x.Type);
singleproxy["udp"] = true;
singleproxy["mtu"] = 1280;
break;
default:
continue;
}
Expand Down
8 changes: 7 additions & 1 deletion src/parser/config/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ enum ProxyType
Snell,
HTTP,
HTTPS,
SOCKS5
SOCKS5,
WireGuard,
};

inline String getProxyTypeName(int type)
Expand Down Expand Up @@ -49,6 +50,8 @@ inline String getProxyTypeName(int type)
return "HTTPS";
case ProxyType::SOCKS5:
return "SOCKS5";
case ProxyType::WireGuard:
return "wireguard";
default:
return "Unknown";
}
Expand Down Expand Up @@ -108,10 +111,13 @@ struct Proxy

String Fingerprint;
String PublicKey;
String WireGuardPublicKey;
String WireGuardPrivateKey;
String ShortId;

String OBFSPassword;

std::vector<String> DNS;
};

#define SS_DEFAULT_GROUP "SSProvider"
Expand Down
49 changes: 49 additions & 0 deletions src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ void trojanConstruct(Proxy &node, const std::string &group, const std::string &r
node.GRPCServiceName = path.empty() ? "/" : urlEncode(urlDecode(trim(path)));
}

void wireguardConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &privatekey, const std::string &publickey, tribool udp, std::string host, std::vector<std::string> dns)
{
commonConstruct(node, ProxyType::WireGuard, group, remarks, server, port, udp, tribool(), tribool(), tribool());
node.WireGuardPrivateKey = privatekey;
node.WireGuardPublicKey = publickey;
node.Host = host;
node.DNS = dns;
}

void snellConstruct(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 &obfs, const std::string &host, uint16_t version, tribool udp, tribool tfo, tribool scv)
{
commonConstruct(node, ProxyType::Snell, group, remarks, server, port, udp, tfo, scv, tribool());
Expand Down Expand Up @@ -879,6 +888,44 @@ void explodeTrojan(std::string trojan, Proxy &node)
trojanConstruct(node, group, remark, server, port, psk, network, mode, host, path, flow, tls, tribool(), tfo, scv);
}

void explodeWireGuard(std::string wireguard, Proxy &node)
{
std::string server, port, publicKey, privateKey, dns, ip, flag, name;
std::vector<std::string> dnsList;
tribool udp;
string_size pos = wireguard.find("#");
if(pos != wireguard.npos)
{
name = urlDecode(wireguard.substr(pos + 1));
wireguard = wireguard.substr(0, pos);
}

wireguard = wireguard.substr(5);
pos = wireguard.rfind(":");
if(pos == wireguard.npos)
{
return;
}
server = wireguard.substr(0, pos);
wireguard = wireguard.substr(pos + 1);
pos = wireguard.find("?");
if(pos == wireguard.npos)
{
return;
}
port = wireguard.substr(0, pos);
wireguard = wireguard.substr(pos + 1);

publicKey = getUrlArg(wireguard, "publicKey");
privateKey = getUrlArg(wireguard, "privateKey");
dns = getUrlArg(wireguard, "dns");
dnsList = split(dns, ",");
ip = getUrlArg(wireguard, "ip");
udp = getUrlArg(wireguard, "udp") == "1" ? true : false;
flag = getUrlArg(wireguard, "flag");
wireguardConstruct(node, flag, name, server, port, privateKey, publicKey, udp, ip, dnsList);
}

void explodeQuan(const std::string &quan, Proxy &node)
{
std::string strTemp, itemName, itemVal;
Expand Down Expand Up @@ -2441,6 +2488,8 @@ void explode(const std::string &link, Proxy &node)
explodeNetch(link, node);
else if(strFind(link, "trojan://") || strFind(link, "trojan-go://"))
explodeTrojan(link, node);
else if(strFind(link, "wg://"))
explodeWireGuard(link, node);
else if(isLink(link))
explodeHTTPSub(link, node);
}
Expand Down