FIx Trojan

This commit is contained in:
Hellojack
2022-06-07 08:12:52 +08:00
committed by GitHub
parent d3b3759f48
commit 47e98dc359
4 changed files with 47 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ public class TrojanForm : ServerForm
Server = server; Server = server;
CreateTextBox("Password", "Password", s => true, s => server.Password = s, server.Password); CreateTextBox("Password", "Password", s => true, s => server.Password = s, server.Password);
CreateTextBox("Host", "Host", s => true, s => server.Host = s, server.Host); CreateTextBox("Host", "Host", s => true, s => server.Host = s, server.Host);
CreateComboBox("TLSSecure", "TLS Secure", VLESSGlobal.TLSSecure, s => server.TLSSecureType = s, server.TLSSecureType);
} }
protected override string TypeName { get; } = "Trojan"; protected override string TypeName { get; } = "Trojan";

View File

@@ -20,4 +20,19 @@ public class TrojanServer : Server
/// 伪装域名 /// 伪装域名
/// </summary> /// </summary>
public string? Host { get; set; } public string? Host { get; set; }
/// <summary>
/// TLS 底层传输安全
/// </summary>
public string TLSSecureType
{
get => _tlsSecureType;
set
{
if (value == "")
value = "none";
_tlsSecureType = value;
}
}
} }

View File

@@ -32,7 +32,7 @@ public class TrojanUtil : IServerUtil
public string GetShareLink(Server s) public string GetShareLink(Server s)
{ {
var server = (TrojanServer)s; var server = (TrojanServer)s;
return $"trojan://{HttpUtility.UrlEncode(server.Password)}@{server.Hostname}:{server.Port}#{server.Remark}"; return $"trojan://{HttpUtility.UrlEncode(server.Password)}@{server.Hostname}:{server.Port}?sni={server.Host}#{server.Remark}";
} }
public IServerController GetController() public IServerController GetController()
@@ -61,8 +61,13 @@ public class TrojanUtil : IServerUtil
var peer = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("peer")); var peer = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("peer"));
if (peer != null) if (peer != null) {
data.Host = peer; data.Host = peer;
} else {
peer = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("sni"));
if (peer != null)
data.Host = peer;
}
text = regmatch.Groups["data"].Value; text = regmatch.Groups["data"].Value;
} }

View File

@@ -192,6 +192,30 @@ public static class V2rayConfigUtils
password = trojan.Password password = trojan.Password
} }
}; };
var streamSettings = new StreamSettings
{
network = "tcp",
security = server.TLSSecureType
};
if (server.TLSSecureType != "none")
{
var tlsSettings = new TlsSettings
{
allowInsecure = Global.Settings.V2RayConfig.AllowInsecure,
serverName = server.Host ?? ""
};
switch (server.TLSSecureType)
{
case "tls":
outbound.streamSettings.tlsSettings = tlsSettings;
break;
case "xtls":
outbound.streamSettings.xtlsSettings = tlsSettings;
break;
}
}
break; break;
} }