@dsh-mobile/mobile-remote 3.4.1-beta.0 → 3.4.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/relay/connector.js +19 -4
- package/lib/relay/crypto.js +24 -0
- package/lib/relay/devices.js +4 -1
- package/lib/relay/phone.js +1 -1
- package/package.json +2 -1
package/lib/relay/connector.js
CHANGED
|
@@ -422,7 +422,9 @@ class GuestSession {
|
|
|
422
422
|
}
|
|
423
423
|
this.mux.receive(plain);
|
|
424
424
|
} catch (err) {
|
|
425
|
-
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
this.kick(err instanceof MuxError ? `protocol: ${err.message}` : `bad frame: ${err?.code ?? err?.name ?? "error"}${err?.message ? ` ${err.message}` : ""}`);
|
|
426
428
|
}
|
|
427
429
|
}
|
|
428
430
|
|
|
@@ -448,6 +450,8 @@ class GuestSession {
|
|
|
448
450
|
|
|
449
451
|
const result = devices.authorize(rs, this.signal || this.standby ? { ...info, otp: undefined } : info);
|
|
450
452
|
if (!result) return this.kick("unauthorized device");
|
|
453
|
+
|
|
454
|
+
if (result.refused === "full") return this.kick("设备已满:已配对的手机到了上限,配对码未作废", "full");
|
|
451
455
|
this.device = result.device;
|
|
452
456
|
const reply = this.noise.writeMessage2(enc.encode(JSON.stringify({ v: 1, ok: true, server: serverName, device: { id: result.device.id, name: result.device.name }, newlyPaired: result.newlyPaired })));
|
|
453
457
|
this.cipherOut = reply.send;
|
|
@@ -540,10 +544,14 @@ class GuestSession {
|
|
|
540
544
|
|
|
541
545
|
|
|
542
546
|
|
|
547
|
+
|
|
543
548
|
kick(reason = "kicked", why = "") {
|
|
544
549
|
if (this.state === "closed") return;
|
|
545
550
|
this.link.o.log(`relay: 断开访客 ${this.connId.slice(0, 6)}…(${reason})`);
|
|
546
|
-
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
const detail = this.link instanceof DirectLink ? { detail: reason } : {};
|
|
554
|
+
if (this.link.control(why ? { t: "kick", c: this.connId, why, ...detail } : { t: "kick", c: this.connId, ...detail })) this.link.pendingKicks?.add(this.connId);
|
|
547
555
|
this.dispose(reason);
|
|
548
556
|
}
|
|
549
557
|
dispose(reason = "closed") {
|
|
@@ -567,6 +575,13 @@ class GuestSession {
|
|
|
567
575
|
|
|
568
576
|
|
|
569
577
|
|
|
578
|
+
|
|
579
|
+
export function closeReason(text) {
|
|
580
|
+
let s = String(text);
|
|
581
|
+
while (Buffer.byteLength(s, "utf8") > 120) s = s.slice(0, -1);
|
|
582
|
+
return s;
|
|
583
|
+
}
|
|
584
|
+
|
|
570
585
|
class DirectLink {
|
|
571
586
|
constructor(owner, ws, ip = "") {
|
|
572
587
|
this.o = owner;
|
|
@@ -619,8 +634,8 @@ class DirectLink {
|
|
|
619
634
|
control(obj) {
|
|
620
635
|
if (this.closed) return false;
|
|
621
636
|
if (obj?.t === "kick") {
|
|
622
|
-
const code = obj.why === "busy" ? 4430 : obj.why === "replaced" ? 4409 : 4401;
|
|
623
|
-
this.ws.close(code, obj.why || "kicked");
|
|
637
|
+
const code = obj.why === "busy" ? 4430 : obj.why === "replaced" ? 4409 : obj.why === "full" ? 4433 : 4401;
|
|
638
|
+
this.ws.close(code, closeReason(obj.why || obj.detail || "kicked"));
|
|
624
639
|
return true;
|
|
625
640
|
}
|
|
626
641
|
if (obj?.t === "verified") return true;
|
package/lib/relay/crypto.js
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
7
11
|
import {
|
|
8
12
|
createCipheriv, createDecipheriv, createHash, createHmac, createPrivateKey, createPublicKey,
|
|
9
13
|
diffieHellman, generateKeyPairSync, randomBytes, sign as edSign, verify as edVerify, timingSafeEqual,
|
|
10
14
|
} from "node:crypto";
|
|
15
|
+
import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
11
16
|
|
|
12
17
|
export const EMPTY = new Uint8Array(0);
|
|
13
18
|
|
|
@@ -100,7 +105,25 @@ const nonceFor = (counter) => {
|
|
|
100
105
|
n.writeBigUInt64LE(BigInt(counter), 4);
|
|
101
106
|
return n;
|
|
102
107
|
};
|
|
108
|
+
|
|
109
|
+
let nativeAead;
|
|
110
|
+
export function nativeAeadAvailable() {
|
|
111
|
+
if (nativeAead === undefined) {
|
|
112
|
+
try {
|
|
113
|
+
createCipheriv("chacha20-poly1305", Buffer.alloc(32), Buffer.alloc(12), { authTagLength: 16 });
|
|
114
|
+
nativeAead = true;
|
|
115
|
+
} catch {
|
|
116
|
+
nativeAead = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return nativeAead;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function _forceNativeAead(value) {
|
|
123
|
+
nativeAead = value;
|
|
124
|
+
}
|
|
103
125
|
export function aeadEncrypt(key, counter, ad, plaintext) {
|
|
126
|
+
if (!nativeAeadAvailable()) return u8(Buffer.from(chacha20poly1305(Uint8Array.from(key), u8(nonceFor(counter)), Uint8Array.from(ad)).encrypt(Uint8Array.from(plaintext))));
|
|
104
127
|
const c = createCipheriv("chacha20-poly1305", Buffer.from(key), nonceFor(counter), { authTagLength: 16 });
|
|
105
128
|
c.setAAD(Buffer.from(ad), { plaintextLength: plaintext.length });
|
|
106
129
|
return concat(c.update(Buffer.from(plaintext)), c.final(), c.getAuthTag());
|
|
@@ -108,6 +131,7 @@ export function aeadEncrypt(key, counter, ad, plaintext) {
|
|
|
108
131
|
|
|
109
132
|
export function aeadDecrypt(key, counter, ad, ciphertext) {
|
|
110
133
|
if (ciphertext.length < 16) throw new Error("ciphertext too short");
|
|
134
|
+
if (!nativeAeadAvailable()) return u8(Buffer.from(chacha20poly1305(Uint8Array.from(key), u8(nonceFor(counter)), Uint8Array.from(ad)).decrypt(Uint8Array.from(ciphertext))));
|
|
111
135
|
const body = ciphertext.subarray(0, ciphertext.length - 16);
|
|
112
136
|
const tag = ciphertext.subarray(ciphertext.length - 16);
|
|
113
137
|
const d = createDecipheriv("chacha20-poly1305", Buffer.from(key), nonceFor(counter), { authTagLength: 16 });
|
package/lib/relay/devices.js
CHANGED
|
@@ -144,6 +144,8 @@ export class DeviceStore {
|
|
|
144
144
|
|
|
145
145
|
|
|
146
146
|
|
|
147
|
+
|
|
148
|
+
|
|
147
149
|
authorize(pub, info = {}) {
|
|
148
150
|
const known = this.find(pub);
|
|
149
151
|
if (known) {
|
|
@@ -167,8 +169,9 @@ export class DeviceStore {
|
|
|
167
169
|
const key = hex(sha256(otp));
|
|
168
170
|
const entry = this.otps.get(key);
|
|
169
171
|
if (!entry) return null;
|
|
172
|
+
|
|
173
|
+
if (this.devices.length >= this.maxDevices) return { refused: "full" };
|
|
170
174
|
this.otps.delete(key);
|
|
171
|
-
if (this.devices.length >= this.maxDevices) return null;
|
|
172
175
|
const device = {
|
|
173
176
|
id: fingerprint(pub),
|
|
174
177
|
name: cleanName(info.name ?? entry.name),
|
package/lib/relay/phone.js
CHANGED
|
@@ -205,7 +205,7 @@ export function connectPhone({ relayUrl, room, pcPub, device, name = "Phone", ot
|
|
|
205
205
|
phone._shutdown(e.code ?? 1006, e.reason ?? "");
|
|
206
206
|
if (!opened) {
|
|
207
207
|
clearTimeout(timer);
|
|
208
|
-
reject(Object.assign(new Error(`relay closed during ${stage} (${e.code})`), { code: e.code }));
|
|
208
|
+
reject(Object.assign(new Error(`relay closed during ${stage} (${e.code})`), { code: e.code, reason: e.reason }));
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
ws.addEventListener("error", () => {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-mobile/mobile-remote",
|
|
3
|
-
"version": "3.4.1-beta.
|
|
3
|
+
"version": "3.4.1-beta.2",
|
|
4
4
|
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(Android、iPhone / iPad)",
|
|
5
5
|
"homepage": "https://dsh.claud.ing/",
|
|
6
6
|
"repository": {
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"dsh": ">=0.2.1-rc.2 <0.4.0-0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
+
"@noble/ciphers": "2.4.0",
|
|
58
59
|
"qrcode": "^1.5.4",
|
|
59
60
|
"werift": "0.27.0"
|
|
60
61
|
},
|