Skip to content

Commit

Permalink
removed - XTLS Security
Browse files Browse the repository at this point in the history
because its too old and no one use it anymore
  • Loading branch information
MHSanaei committed Oct 29, 2024
1 parent 3b3bd3d commit e359b5c
Show file tree
Hide file tree
Showing 20 changed files with 3 additions and 395 deletions.
67 changes: 2 additions & 65 deletions sub/subService.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,38 +452,7 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
}
}

if security == "xtls" {
params["security"] = "xtls"
xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{})
alpns, _ := xtlsSetting["alpn"].([]interface{})
var alpn []string
for _, a := range alpns {
alpn = append(alpn, a.(string))
}
if len(alpn) > 0 {
params["alpn"] = strings.Join(alpn, ",")
}
if sniValue, ok := searchKey(xtlsSetting, "serverName"); ok {
params["sni"], _ = sniValue.(string)
}
xtlsSettings, _ := searchKey(xtlsSetting, "settings")
if xtlsSetting != nil {
if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok {
params["fp"], _ = fpValue.(string)
}
if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok {
if insecure.(bool) {
params["allowInsecure"] = "1"
}
}
}

if streamNetwork == "tcp" && len(clients[clientIndex].Flow) > 0 {
params["flow"] = clients[clientIndex].Flow
}
}

if security != "tls" && security != "reality" && security != "xtls" {
if security != "tls" && security != "reality" {
params["security"] = "none"
}

Expand Down Expand Up @@ -676,39 +645,7 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
}
}

if security == "xtls" {
params["security"] = "xtls"
xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{})
alpns, _ := xtlsSetting["alpn"].([]interface{})
var alpn []string
for _, a := range alpns {
alpn = append(alpn, a.(string))
}
if len(alpn) > 0 {
params["alpn"] = strings.Join(alpn, ",")
}
if sniValue, ok := searchKey(xtlsSetting, "serverName"); ok {
params["sni"], _ = sniValue.(string)
}

xtlsSettings, _ := searchKey(xtlsSetting, "settings")
if xtlsSetting != nil {
if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok {
params["fp"], _ = fpValue.(string)
}
if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok {
if insecure.(bool) {
params["allowInsecure"] = "1"
}
}
}

if streamNetwork == "tcp" && len(clients[clientIndex].Flow) > 0 {
params["flow"] = clients[clientIndex].Flow
}
}

if security != "tls" && security != "reality" && security != "xtls" {
if security != "tls" && security != "reality" {
params["security"] = "none"
}

Expand Down
199 changes: 0 additions & 199 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const SSMethods = {
BLAKE3_CHACHA20_POLY1305: '2022-blake3-chacha20-poly1305',
};

const XTLS_FLOW_CONTROL = {
ORIGIN: "xtls-rprx-origin",
DIRECT: "xtls-rprx-direct",
};

const TLS_FLOW_CONTROL = {
VISION: "xtls-rprx-vision",
VISION_UDP443: "xtls-rprx-vision-udp443",
Expand Down Expand Up @@ -120,7 +115,6 @@ const USERS_SECURITY = {

Object.freeze(Protocols);
Object.freeze(SSMethods);
Object.freeze(XTLS_FLOW_CONTROL);
Object.freeze(TLS_FLOW_CONTROL);
Object.freeze(TLS_VERSION_OPTION);
Object.freeze(TLS_CIPHER_OPTION);
Expand Down Expand Up @@ -755,137 +749,6 @@ TlsStreamSettings.Settings = class extends XrayCommonClass {
}
};

class XtlsStreamSettings extends XrayCommonClass {
constructor(
serverName = '',
certificates = [new XtlsStreamSettings.Cert()],
alpn = [ALPN_OPTION.H3, ALPN_OPTION.H2, ALPN_OPTION.HTTP1],
settings = new XtlsStreamSettings.Settings()
) {
super();
this.sni = serverName;
this.certs = certificates;
this.alpn = alpn;
this.settings = settings;
}

addCert() {
this.certs.push(new XtlsStreamSettings.Cert());
}

removeCert(index) {
this.certs.splice(index, 1);
}

static fromJson(json = {}) {
let certs;
let settings;
if (!ObjectUtil.isEmpty(json.certificates)) {
certs = json.certificates.map(cert => XtlsStreamSettings.Cert.fromJson(cert));
}

if (!ObjectUtil.isEmpty(json.settings)) {
settings = new XtlsStreamSettings.Settings(json.settings.allowInsecure, json.settings.serverName);
}
return new XtlsStreamSettings(
json.serverName,
certs,
json.alpn,
settings,
);
}

toJson() {
return {
serverName: this.sni,
certificates: XtlsStreamSettings.toJsonArray(this.certs),
alpn: this.alpn,
settings: this.settings,
};
}
}

XtlsStreamSettings.Cert = class extends XrayCommonClass {
constructor(
useFile = true,
certificateFile = '',
keyFile = '',
certificate = '',
key = '',
ocspStapling = 3600,
oneTimeLoading = false,
usage = USAGE_OPTION.ENCIPHERMENT
) {
super();
this.useFile = useFile;
this.certFile = certificateFile;
this.keyFile = keyFile;
this.cert = Array.isArray(certificate) ? certificate.join('\n') : certificate;
this.key = Array.isArray(key) ? key.join('\n') : key;
this.ocspStapling = ocspStapling;
this.oneTimeLoading = oneTimeLoading;
this.usage = usage;
}

static fromJson(json = {}) {
if ('certificateFile' in json && 'keyFile' in json) {
return new XtlsStreamSettings.Cert(
true,
json.certificateFile,
json.keyFile, '', '',
json.ocspStapling,
json.oneTimeLoading,
json.usage,
);
} else {
return new XtlsStreamSettings.Cert(
false, '', '',
json.certificate.join('\n'),
json.key.join('\n'),
json.ocspStapling,
json.oneTimeLoading,
json.usage,
);
}
}

toJson() {
if (this.useFile) {
return {
certificateFile: this.certFile,
keyFile: this.keyFile,
ocspStapling: this.ocspStapling,
oneTimeLoading: this.oneTimeLoading,
usage: this.usage,
};
} else {
return {
certificate: this.cert.split('\n'),
key: this.key.split('\n'),
ocspStapling: this.ocspStapling,
oneTimeLoading: this.oneTimeLoading,
usage: this.usage,
};
}
}
};

XtlsStreamSettings.Settings = class extends XrayCommonClass {
constructor(allowInsecure = false) {
super();
this.allowInsecure = allowInsecure;
}
static fromJson(json = {}) {
return new XtlsStreamSettings.Settings(
json.allowInsecure,
);
}
toJson() {
return {
allowInsecure: this.allowInsecure,
};
}
};

class RealityStreamSettings extends XrayCommonClass {
constructor(
Expand Down Expand Up @@ -1071,7 +934,6 @@ class StreamSettings extends XrayCommonClass {
security = 'none',
externalProxy = [],
tlsSettings = new TlsStreamSettings(),
xtlsSettings = new XtlsStreamSettings(),
realitySettings = new RealityStreamSettings(),
tcpSettings = new TcpStreamSettings(),
kcpSettings = new KcpStreamSettings(),
Expand All @@ -1087,7 +949,6 @@ class StreamSettings extends XrayCommonClass {
this.security = security;
this.externalProxy = externalProxy;
this.tls = tlsSettings;
this.xtls = xtlsSettings;
this.reality = realitySettings;
this.tcp = tcpSettings;
this.kcp = kcpSettings;
Expand All @@ -1111,18 +972,6 @@ class StreamSettings extends XrayCommonClass {
}
}

get isXtls() {
return this.security === "xtls";
}

set isXtls(isXtls) {
if (isXtls) {
this.security = 'xtls';
} else {
this.security = 'none';
}
}

//for Reality
get isReality() {
return this.security === "reality";
Expand Down Expand Up @@ -1150,7 +999,6 @@ class StreamSettings extends XrayCommonClass {
json.security,
json.externalProxy,
TlsStreamSettings.fromJson(json.tlsSettings),
XtlsStreamSettings.fromJson(json.xtlsSettings),
RealityStreamSettings.fromJson(json.realitySettings),
TcpStreamSettings.fromJson(json.tcpSettings),
KcpStreamSettings.fromJson(json.kcpSettings),
Expand All @@ -1170,7 +1018,6 @@ class StreamSettings extends XrayCommonClass {
security: this.security,
externalProxy: this.externalProxy,
tlsSettings: this.isTls ? this.tls.toJson() : undefined,
xtlsSettings: this.isXtls ? this.xtls.toJson() : undefined,
realitySettings: this.isReality ? this.reality.toJson() : undefined,
tcpSettings: network === 'tcp' ? this.tcp.toJson() : undefined,
kcpSettings: network === 'kcp' ? this.kcp.toJson() : undefined,
Expand Down Expand Up @@ -1283,18 +1130,6 @@ class Inbound extends XrayCommonClass {
}
}

get xtls() {
return this.stream.security === 'xtls';
}

set xtls(isXtls) {
if (isXtls) {
this.stream.security = 'xtls';
} else {
this.stream.security = 'none';
}
}

get network() {
return this.stream.network;
}
Expand Down Expand Up @@ -1349,7 +1184,6 @@ class Inbound extends XrayCommonClass {

get serverName() {
if (this.stream.isTls) return this.stream.tls.sni;
if (this.stream.isXtls) return this.stream.xtls.sni;
if (this.stream.isReality) return this.stream.reality.serverNames;
return "";
}
Expand Down Expand Up @@ -1428,11 +1262,6 @@ class Inbound extends XrayCommonClass {
return ["tcp", "http", "grpc"].includes(this.network);
}

canEnableXtls() {
if (![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false;
return this.network === "tcp";
}

canEnableStream() {
return [Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol);
}
Expand Down Expand Up @@ -1592,18 +1421,6 @@ class Inbound extends XrayCommonClass {
}
}

else if (security === 'xtls') {
params.set("security", "xtls");
params.set("alpn", this.stream.xtls.alpn);
if (this.stream.xtls.settings.allowInsecure) {
params.set("allowInsecure", "1");
}
if (!ObjectUtil.isEmpty(this.stream.xtls.sni)) {
params.set("sni", this.stream.xtls.sni);
}
params.set("flow", flow);
}

else if (security === 'reality') {
params.set("security", "reality");
params.set("pbk", this.stream.reality.settings.publicKey);
Expand Down Expand Up @@ -1801,18 +1618,6 @@ class Inbound extends XrayCommonClass {
}
}

else if (security === 'xtls') {
params.set("security", "xtls");
params.set("alpn", this.stream.xtls.alpn);
if (this.stream.xtls.settings.allowInsecure) {
params.set("allowInsecure", "1");
}
if (!ObjectUtil.isEmpty(this.stream.xtls.sni)) {
params.set("sni", this.stream.xtls.sni);
}
params.set("flow", flow);
}

else {
params.set("security", "none");
}
Expand Down Expand Up @@ -2273,7 +2078,6 @@ Inbound.TrojanSettings = class extends Inbound.Settings {
Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
constructor(
password = RandomUtil.randomSeq(10),
flow = '',
email = RandomUtil.randomLowerAndNum(8),
limitIp = 0,
totalGB = 0,
Expand All @@ -2285,7 +2089,6 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
) {
super();
this.password = password;
this.flow = flow;
this.email = email;
this.limitIp = limitIp;
this.totalGB = totalGB;
Expand All @@ -2299,7 +2102,6 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
toJson() {
return {
password: this.password,
flow: this.flow,
email: this.email,
limitIp: this.limitIp,
totalGB: this.totalGB,
Expand All @@ -2314,7 +2116,6 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
static fromJson(json = {}) {
return new Inbound.TrojanSettings.Trojan(
json.password,
json.flow,
json.email,
json.limitIp,
json.totalGB,
Expand Down
Loading

0 comments on commit e359b5c

Please sign in to comment.