fix TypeError: this.shortIds.split is not a function (#2507)

* fix TypeError: this.shortIds.split is not a function
This commit is contained in:
Dmitry Zhavoronkov 2024-09-02 17:02:15 +07:00 committed by GitHub
parent 2dc59a601c
commit 4494ffabb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 160 additions and 160 deletions

View file

@ -268,13 +268,13 @@ func (s *SubJsonService) realityData(rData map[string]interface{}) map[string]in
rltyData["spiderX"] = "/" + random.Seq(15) rltyData["spiderX"] = "/" + random.Seq(15)
shortIds, ok := rData["shortIds"].([]interface{}) shortIds, ok := rData["shortIds"].([]interface{})
if ok && len(shortIds) > 0 { if ok && len(shortIds) > 0 {
rltyData["shortId"] = shortIds[random.Num(len(shortIds))].(string) rltyData["shortId"] = shortIds
} else { } else {
rltyData["shortId"] = "" rltyData["shortId"] = ""
} }
serverNames, ok := rData["serverNames"].([]interface{}) serverNames, ok := rData["serverNames"].([]interface{})
if ok && len(serverNames) > 0 { if ok && len(serverNames) > 0 {
rltyData["serverName"] = serverNames[random.Num(len(serverNames))].(string) rltyData["serverName"] = serverNames
} else { } else {
rltyData["serverName"] = "" rltyData["serverName"] = ""
} }

View file

@ -914,7 +914,7 @@ class RealityStreamSettings extends XrayCommonClass {
minClient = '', minClient = '',
maxClient = '', maxClient = '',
maxTimediff = 0, maxTimediff = 0,
shortIds = RandomUtil.randomShortId(), shortIds = RandomUtil.randomShortIds(),
settings = new RealityStreamSettings.Settings() settings = new RealityStreamSettings.Settings()
) { ) {
super(); super();

View file

@ -99,7 +99,7 @@ class RandomUtil {
return str; return str;
} }
static randomShortId() { static randomShortIds() {
const lengths = [2, 4, 6, 8, 10, 12, 14, 16]; const lengths = [2, 4, 6, 8, 10, 12, 14, 16];
for (let i = lengths.length - 1; i > 0; i--) { for (let i = lengths.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); const j = Math.floor(Math.random() * (i + 1));
@ -114,7 +114,7 @@ class RandomUtil {
} }
shortIds.push(shortId); shortIds.push(shortId);
} }
return shortIds; return shortIds.join(',');
} }
static randomLowerAndNum(len) { static randomLowerAndNum(len) {
@ -294,172 +294,172 @@ class ObjectUtil {
} }
class Wireguard { class Wireguard {
static gf(init) { static gf(init) {
var r = new Float64Array(16); var r = new Float64Array(16);
if (init) { if (init) {
for (var i = 0; i < init.length; ++i) for (var i = 0; i < init.length; ++i)
r[i] = init[i]; r[i] = init[i];
} }
return r; return r;
} }
static pack(o, n) { static pack(o, n) {
var b, m = this.gf(), t = this.gf(); var b, m = this.gf(), t = this.gf();
for (var i = 0; i < 16; ++i) for (var i = 0; i < 16; ++i)
t[i] = n[i]; t[i] = n[i];
this.carry(t); this.carry(t);
this.carry(t); this.carry(t);
this.carry(t); this.carry(t);
for (var j = 0; j < 2; ++j) { for (var j = 0; j < 2; ++j) {
m[0] = t[0] - 0xffed; m[0] = t[0] - 0xffed;
for (var i = 1; i < 15; ++i) { for (var i = 1; i < 15; ++i) {
m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1); m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1);
m[i - 1] &= 0xffff; m[i - 1] &= 0xffff;
} }
m[15] = t[15] - 0x7fff - ((m[14] >> 16) & 1); m[15] = t[15] - 0x7fff - ((m[14] >> 16) & 1);
b = (m[15] >> 16) & 1; b = (m[15] >> 16) & 1;
m[14] &= 0xffff; m[14] &= 0xffff;
this.cswap(t, m, 1 - b); this.cswap(t, m, 1 - b);
} }
for (var i = 0; i < 16; ++i) { for (var i = 0; i < 16; ++i) {
o[2 * i] = t[i] & 0xff; o[2 * i] = t[i] & 0xff;
o[2 * i + 1] = t[i] >> 8; o[2 * i + 1] = t[i] >> 8;
} }
} }
static carry(o) { static carry(o) {
var c; var c;
for (var i = 0; i < 16; ++i) { for (var i = 0; i < 16; ++i) {
o[(i + 1) % 16] += (i < 15 ? 1 : 38) * Math.floor(o[i] / 65536); o[(i + 1) % 16] += (i < 15 ? 1 : 38) * Math.floor(o[i] / 65536);
o[i] &= 0xffff; o[i] &= 0xffff;
} }
} }
static cswap(p, q, b) { static cswap(p, q, b) {
var t, c = ~(b - 1); var t, c = ~(b - 1);
for (var i = 0; i < 16; ++i) { for (var i = 0; i < 16; ++i) {
t = c & (p[i] ^ q[i]); t = c & (p[i] ^ q[i]);
p[i] ^= t; p[i] ^= t;
q[i] ^= t; q[i] ^= t;
} }
} }
static add(o, a, b) { static add(o, a, b) {
for (var i = 0; i < 16; ++i) for (var i = 0; i < 16; ++i)
o[i] = (a[i] + b[i]) | 0; o[i] = (a[i] + b[i]) | 0;
} }
static subtract(o, a, b) { static subtract(o, a, b) {
for (var i = 0; i < 16; ++i) for (var i = 0; i < 16; ++i)
o[i] = (a[i] - b[i]) | 0; o[i] = (a[i] - b[i]) | 0;
} }
static multmod(o, a, b) { static multmod(o, a, b) {
var t = new Float64Array(31); var t = new Float64Array(31);
for (var i = 0; i < 16; ++i) { for (var i = 0; i < 16; ++i) {
for (var j = 0; j < 16; ++j) for (var j = 0; j < 16; ++j)
t[i + j] += a[i] * b[j]; t[i + j] += a[i] * b[j];
} }
for (var i = 0; i < 15; ++i) for (var i = 0; i < 15; ++i)
t[i] += 38 * t[i + 16]; t[i] += 38 * t[i + 16];
for (var i = 0; i < 16; ++i) for (var i = 0; i < 16; ++i)
o[i] = t[i]; o[i] = t[i];
this.carry(o); this.carry(o);
this.carry(o); this.carry(o);
} }
static invert(o, i) { static invert(o, i) {
var c = this.gf(); var c = this.gf();
for (var a = 0; a < 16; ++a) for (var a = 0; a < 16; ++a)
c[a] = i[a]; c[a] = i[a];
for (var a = 253; a >= 0; --a) { for (var a = 253; a >= 0; --a) {
this.multmod(c, c, c); this.multmod(c, c, c);
if (a !== 2 && a !== 4) if (a !== 2 && a !== 4)
this.multmod(c, c, i); this.multmod(c, c, i);
} }
for (var a = 0; a < 16; ++a) for (var a = 0; a < 16; ++a)
o[a] = c[a]; o[a] = c[a];
} }
static clamp(z) { static clamp(z) {
z[31] = (z[31] & 127) | 64; z[31] = (z[31] & 127) | 64;
z[0] &= 248; z[0] &= 248;
} }
static generatePublicKey(privateKey) { static generatePublicKey(privateKey) {
var r, z = new Uint8Array(32); var r, z = new Uint8Array(32);
var a = this.gf([1]), var a = this.gf([1]),
b = this.gf([9]), b = this.gf([9]),
c = this.gf(), c = this.gf(),
d = this.gf([1]), d = this.gf([1]),
e = this.gf(), e = this.gf(),
f = this.gf(), f = this.gf(),
_121665 = this.gf([0xdb41, 1]), _121665 = this.gf([0xdb41, 1]),
_9 = this.gf([9]); _9 = this.gf([9]);
for (var i = 0; i < 32; ++i) for (var i = 0; i < 32; ++i)
z[i] = privateKey[i]; z[i] = privateKey[i];
this.clamp(z); this.clamp(z);
for (var i = 254; i >= 0; --i) { for (var i = 254; i >= 0; --i) {
r = (z[i >>> 3] >>> (i & 7)) & 1; r = (z[i >>> 3] >>> (i & 7)) & 1;
this.cswap(a, b, r); this.cswap(a, b, r);
this.cswap(c, d, r); this.cswap(c, d, r);
this.add(e, a, c); this.add(e, a, c);
this.subtract(a, a, c); this.subtract(a, a, c);
this.add(c, b, d); this.add(c, b, d);
this.subtract(b, b, d); this.subtract(b, b, d);
this.multmod(d, e, e); this.multmod(d, e, e);
this.multmod(f, a, a); this.multmod(f, a, a);
this.multmod(a, c, a); this.multmod(a, c, a);
this.multmod(c, b, e); this.multmod(c, b, e);
this.add(e, a, c); this.add(e, a, c);
this.subtract(a, a, c); this.subtract(a, a, c);
this.multmod(b, a, a); this.multmod(b, a, a);
this.subtract(c, d, f); this.subtract(c, d, f);
this.multmod(a, c, _121665); this.multmod(a, c, _121665);
this.add(a, a, d); this.add(a, a, d);
this.multmod(c, c, a); this.multmod(c, c, a);
this.multmod(a, d, f); this.multmod(a, d, f);
this.multmod(d, b, _9); this.multmod(d, b, _9);
this.multmod(b, e, e); this.multmod(b, e, e);
this.cswap(a, b, r); this.cswap(a, b, r);
this.cswap(c, d, r); this.cswap(c, d, r);
} }
this.invert(c, c); this.invert(c, c);
this.multmod(a, a, c); this.multmod(a, a, c);
this.pack(z, a); this.pack(z, a);
return z; return z;
} }
static generatePresharedKey() { static generatePresharedKey() {
var privateKey = new Uint8Array(32); var privateKey = new Uint8Array(32);
window.crypto.getRandomValues(privateKey); window.crypto.getRandomValues(privateKey);
return privateKey; return privateKey;
} }
static generatePrivateKey() { static generatePrivateKey() {
var privateKey = this.generatePresharedKey(); var privateKey = this.generatePresharedKey();
this.clamp(privateKey); this.clamp(privateKey);
return privateKey; return privateKey;
} }
static encodeBase64(dest, src) { static encodeBase64(dest, src) {
var input = Uint8Array.from([(src[0] >> 2) & 63, ((src[0] << 4) | (src[1] >> 4)) & 63, ((src[1] << 2) | (src[2] >> 6)) & 63, src[2] & 63]); var input = Uint8Array.from([(src[0] >> 2) & 63, ((src[0] << 4) | (src[1] >> 4)) & 63, ((src[1] << 2) | (src[2] >> 6)) & 63, src[2] & 63]);
for (var i = 0; i < 4; ++i) for (var i = 0; i < 4; ++i)
dest[i] = input[i] + 65 + dest[i] = input[i] + 65 +
(((25 - input[i]) >> 8) & 6) - (((25 - input[i]) >> 8) & 6) -
(((51 - input[i]) >> 8) & 75) - (((51 - input[i]) >> 8) & 75) -
(((61 - input[i]) >> 8) & 15) + (((61 - input[i]) >> 8) & 15) +
(((62 - input[i]) >> 8) & 3); (((62 - input[i]) >> 8) & 3);
} }
static keyToBase64(key) { static keyToBase64(key) {
var i, base64 = new Uint8Array(44); var i, base64 = new Uint8Array(44);
for (i = 0; i < 32 / 3; ++i) for (i = 0; i < 32 / 3; ++i)
this.encodeBase64(base64.subarray(i * 4), key.subarray(i * 3)); this.encodeBase64(base64.subarray(i * 4), key.subarray(i * 3));
this.encodeBase64(base64.subarray(i * 4), Uint8Array.from([key[i * 3 + 0], key[i * 3 + 1], 0])); this.encodeBase64(base64.subarray(i * 4), Uint8Array.from([key[i * 3 + 0], key[i * 3 + 1], 0]));
base64[43] = 61; base64[43] = 61;
return String.fromCharCode.apply(null, base64); return String.fromCharCode.apply(null, base64);
} }
static keyFromBase64(encoded) { static keyFromBase64(encoded) {
const binaryStr = atob(encoded); const binaryStr = atob(encoded);
@ -470,12 +470,12 @@ class Wireguard {
return bytes; return bytes;
} }
static generateKeypair(secretKey='') { static generateKeypair(secretKey = '') {
var privateKey = secretKey.length>0 ? this.keyFromBase64(secretKey) : this.generatePrivateKey(); var privateKey = secretKey.length > 0 ? this.keyFromBase64(secretKey) : this.generatePrivateKey();
var publicKey = this.generatePublicKey(privateKey); var publicKey = this.generatePublicKey(privateKey);
return { return {
publicKey: this.keyToBase64(publicKey), publicKey: this.keyToBase64(publicKey),
privateKey: secretKey.length>0 ? secretKey : this.keyToBase64(privateKey) privateKey: secretKey.length > 0 ? secretKey : this.keyToBase64(privateKey)
}; };
} }
} }

View file

@ -189,7 +189,7 @@
<a-tooltip> <a-tooltip>
<template slot="title"> <template slot="title">
<span>{{ i18n "reset" }}</span> <span>{{ i18n "reset" }}</span>
</template> Short ID <a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId()" type="sync"></a-icon> </template> Short IDs <a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortIds()" type="sync"></a-icon>
</a-tooltip> </a-tooltip>
</template> </template>
<a-input v-model.trim="inbound.stream.reality.shortIds"></a-input> <a-input v-model.trim="inbound.stream.reality.shortIds"></a-input>