reality for trojan

This commit is contained in:
MHSanaei 2023-04-11 22:30:24 +03:30
parent 4e7ad9e6de
commit c38d75f3d9
2 changed files with 76 additions and 22 deletions

View file

@ -600,8 +600,20 @@ TlsStreamSettings.Settings = class extends XrayCommonClass {
}; };
class RealityStreamSettings extends XrayCommonClass { class RealityStreamSettings extends XrayCommonClass {
constructor(show = false,xver = 0, fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX, dest = 'github.io:443', serverNames = 'github.io,www.github.io,', privateKey = RandomUtil.randomX25519PrivateKey(), publicKey = '', minClient = '',
maxClient = '', maxTimediff = 0, shortIds = RandomUtil.randowShortId()) { constructor(
show = false,xver = 0,
fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX,
dest = 'yahoo.com:443',
serverNames = 'yahoo.com,www.yahoo.com',
privateKey = RandomUtil.randomX25519PrivateKey(),
publicKey = '',
minClient = '',
maxClient = '',
maxTimediff = 0,
shortIds = RandomUtil.randowShortId()
)
{
super(); super();
this.show = show; this.show = show;
this.xver = xver; this.xver = xver;
@ -614,10 +626,8 @@ class RealityStreamSettings extends XrayCommonClass {
this.maxClient = maxClient; this.maxClient = maxClient;
this.maxTimediff = maxTimediff; this.maxTimediff = maxTimediff;
this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds; this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds;
}
} static fromJson(json = {}) {
static fromJson(json = {}) {
return new RealityStreamSettings( return new RealityStreamSettings(
json.show, json.show,
json.xver, json.xver,
@ -631,9 +641,8 @@ class RealityStreamSettings extends XrayCommonClass {
json.maxTimediff, json.maxTimediff,
json.shortIds json.shortIds
); );
}
} toJson() {
toJson() {
return { return {
show: this.show, show: this.show,
xver: this.xver, xver: this.xver,
@ -646,22 +655,22 @@ class RealityStreamSettings extends XrayCommonClass {
maxClient: this.maxClient, maxClient: this.maxClient,
maxTimediff: this.maxTimediff, maxTimediff: this.maxTimediff,
shortIds: this.shortIds.split(/,||\s+/) shortIds: this.shortIds.split(/,||\s+/)
}; };
}
} }
}
class StreamSettings extends XrayCommonClass { class StreamSettings extends XrayCommonClass {
constructor(network='tcp', constructor(network='tcp',
security='none', security='none',
tlsSettings=new TlsStreamSettings(), tlsSettings=new TlsStreamSettings(),
realitySettings = new RealityStreamSettings(), realitySettings = new RealityStreamSettings(),
tcpSettings=new TcpStreamSettings(), tcpSettings=new TcpStreamSettings(),
kcpSettings=new KcpStreamSettings(), kcpSettings=new KcpStreamSettings(),
wsSettings=new WsStreamSettings(), wsSettings=new WsStreamSettings(),
httpSettings=new HttpStreamSettings(), httpSettings=new HttpStreamSettings(),
quicSettings=new QuicStreamSettings(), quicSettings=new QuicStreamSettings(),
grpcSettings=new GrpcStreamSettings(), grpcSettings=new GrpcStreamSettings(),
) { ) {
super(); super();
this.network = network; this.network = network;
this.security = security; this.security = security;
@ -1056,6 +1065,7 @@ class Inbound extends XrayCommonClass {
canEnableReality() { canEnableReality() {
switch (this.protocol) { switch (this.protocol) {
case Protocols.VLESS: case Protocols.VLESS:
case Protocols.TROJAN:
break; break;
default: default:
return false; return false;
@ -1379,6 +1389,26 @@ class Inbound extends XrayCommonClass {
} }
} }
if (this.reality) {
params.set("security", "reality");
if (!ObjectUtil.isArrEmpty(this.stream.reality.serverNames)) {
params.set("sni", this.stream.reality.serverNames.split(/,||\s+/)[0]);
}
if (this.stream.reality.publicKey != "") {
//params.set("pbk", Ed25519.getPublicKey(this.stream.reality.privateKey));
params.set("pbk", this.stream.reality.publicKey);
}
if (this.stream.network === 'tcp') {
params.set("flow", this.settings.trojans[clientIndex].flow);
}
if (this.stream.reality.shortIds != "") {
params.set("sid", this.stream.reality.shortIds);
}
if (this.stream.reality.fingerprint != "") {
params.set("fp", this.stream.reality.fingerprint);
}
}
if (this.XTLS) { if (this.XTLS) {
params.set("security", "xtls"); params.set("security", "xtls");
params.set("alpn", this.stream.tls.alpn); params.set("alpn", this.stream.tls.alpn);

View file

@ -442,6 +442,30 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
} }
} }
if security == "reality" {
params["security"] = "reality"
realitySetting, _ := stream["realitySettings"].(map[string]interface{})
realitySettings, _ := searchKey(realitySetting, "settings")
if realitySetting != nil {
if sniValue, ok := searchKey(realitySettings, "serverName"); ok {
params["sni"], _ = sniValue.(string)
}
if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok {
params["pbk"], _ = pbkValue.(string)
}
if sidValue, ok := searchKey(realitySettings, "shortIds"); ok {
params["sid"], _ = sidValue.(string)
}
if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok {
params["fp"], _ = fpValue.(string)
}
}
serverName, _ := realitySetting["serverName"].(string)
if serverName != "" {
address = serverName
}
}
if security == "xtls" { if security == "xtls" {
params["security"] = "xtls" params["security"] = "xtls"
xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{}) xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{})