optimize security in front codes #1300

This commit is contained in:
Alireza Ahmadi 2023-12-08 16:46:44 +01:00
parent 4ee986aa71
commit 549f230221
3 changed files with 24 additions and 103 deletions

View file

@ -8,13 +8,6 @@ const Protocols = {
HTTP: 'http', HTTP: 'http',
}; };
const VmessMethods = {
AES_128_GCM: 'aes-128-gcm',
CHACHA20_POLY1305: 'chacha20-poly1305',
AUTO: 'auto',
NONE: 'none',
};
const SSMethods = { const SSMethods = {
AES_256_GCM: 'aes-256-gcm', AES_256_GCM: 'aes-256-gcm',
AES_128_GCM: 'aes-128-gcm', AES_128_GCM: 'aes-128-gcm',
@ -91,7 +84,6 @@ const SNIFFING_OPTION = {
}; };
Object.freeze(Protocols); Object.freeze(Protocols);
Object.freeze(VmessMethods);
Object.freeze(SSMethods); Object.freeze(SSMethods);
Object.freeze(XTLS_FLOW_CONTROL); Object.freeze(XTLS_FLOW_CONTROL);
Object.freeze(TLS_FLOW_CONTROL); Object.freeze(TLS_FLOW_CONTROL);
@ -422,7 +414,7 @@ class HttpStreamSettings extends XrayCommonClass {
} }
class QuicStreamSettings extends XrayCommonClass { class QuicStreamSettings extends XrayCommonClass {
constructor(security=VmessMethods.NONE, constructor(security='none',
key=RandomUtil.randomSeq(10), type='none') { key=RandomUtil.randomSeq(10), type='none') {
super(); super();
this.security = security; this.security = security;
@ -1163,95 +1155,34 @@ class Inbound extends XrayCommonClass {
} }
canEnableTls() { canEnableTls() {
switch (this.protocol) { if(![Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false;
case Protocols.VMESS: return ["tcp", "ws", "http", "quic", "grpc"].includes(this.network);
case Protocols.VLESS:
case Protocols.TROJAN:
break;
default:
return false;
}
switch (this.network) {
case "tcp":
case "ws":
case "http":
case "quic":
case "grpc":
return true;
default:
return false;
}
} }
canEnableReality() { canEnableReality() {
switch (this.protocol) { if(![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false;
case Protocols.VLESS: return ["tcp", "http", "grpc"].includes(this.network);
case Protocols.TROJAN:
break;
default:
return false;
}
switch (this.network) {
case "tcp":
case "http":
case "grpc":
return true;
default:
return false;
}
} }
//this is used for xtls-rprx-vision //this is used for xtls-rprx-vision
canEnableTlsFlow() { canEnableTlsFlow() {
if (((this.stream.security === 'tls') || (this.stream.security === 'reality')) && (this.network === "tcp")) { if (((this.stream.security === 'tls') || (this.stream.security === 'reality')) && (this.network === "tcp")) {
switch (this.protocol) { return this.protocol === Protocols.VLESS;
case Protocols.VLESS:
return true;
default:
return false;
}
} }
return false; return false;
} }
canSetTls() {
return this.canEnableTls();
}
canEnableXtls() { canEnableXtls() {
switch (this.protocol) { if(![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false;
case Protocols.VLESS:
case Protocols.TROJAN:
break;
default:
return false;
}
return this.network === "tcp"; return this.network === "tcp";
} }
canEnableStream() { canEnableStream() {
switch (this.protocol) { return [Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol);
case Protocols.VMESS:
case Protocols.VLESS:
case Protocols.TROJAN:
case Protocols.SHADOWSOCKS:
return true;
default:
return false;
}
} }
canSniffing() { canSniffing() {
switch (this.protocol) { return [Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol);
case Protocols.VMESS:
case Protocols.VLESS:
case Protocols.TROJAN:
case Protocols.SHADOWSOCKS:
return true;
default:
return false;
}
} }
reset() { reset() {
@ -1691,7 +1622,7 @@ class Inbound extends XrayCommonClass {
toJson() { toJson() {
let streamSettings; let streamSettings;
if (this.canEnableStream() || this.protocol === Protocols.TROJAN) { if (this.canEnableStream()) {
streamSettings = this.stream.toJson(); streamSettings = this.stream.toJson();
} }
return { return {

View file

@ -1,34 +1,24 @@
{{define "form/tlsSettings"}} {{define "form/tlsSettings"}}
<!-- tls enable --> <!-- tls enable -->
<a-form layout="inline" v-if="inbound.canSetTls()"> <a-form layout="inline" v-if="inbound.canEnableTls()">
<a-divider style="margin:0;"></a-divider> <a-divider style="margin:0;"></a-divider>
<a-form-item v-if="inbound.canEnableTls()" label="TLS"> <a-form-item label='{{ i18n "security" }}'>
<a-switch v-model="inbound.tls"> <a-radio-group v-model="inbound.stream.security" button-style="solid">
</a-switch> <a-radio-button value="none">{{ i18n "none" }}</a-radio-button>
</a-form-item> <a-radio-button value="tls">TLS</a-radio-button>
<a-form-item v-if="inbound.canEnableReality()">
<span slot="label">
Reality
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.inbounds.realityDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-switch v-model="inbound.reality"></a-switch>
</a-form-item>
<a-form-item v-if="inbound.canEnableXtls()">
<span slot="label">
XTLS
<a-tooltip> <a-tooltip>
<template slot="title"> <template slot="title">
<span>{{ i18n "pages.inbounds.xtlsDesc" }}</span> <span>{{ i18n "pages.inbounds.xtlsDesc" }}</span>
</template> </template>
<a-icon type="question-circle" theme="filled"></a-icon> <a-radio-button v-if="inbound.canEnableXtls()" value="xtls">XTLS</a-radio-button>
</a-tooltip> </a-tooltip>
</span> <a-tooltip>
<a-switch v-model="inbound.xtls"></a-switch> <template slot="title">
<span>{{ i18n "pages.inbounds.realityDesc" }}</span>
</template>
<a-radio-button v-if="inbound.canEnableReality()" value="reality">Reality</a-radio-button>
</a-tooltip>
</a-radio-group>
</a-form-item> </a-form-item>
</a-form> </a-form>

View file

@ -93,7 +93,7 @@
}, },
methods: { methods: {
streamNetworkChange() { streamNetworkChange() {
if (!inModal.inbound.canSetTls()) { if (!inModal.inbound.canEnableTls()) {
this.inModal.inbound.stream.security = 'none'; this.inModal.inbound.stream.security = 'none';
} }
if (!inModal.inbound.canEnableReality()) { if (!inModal.inbound.canEnableReality()) {