iosignal 9.6.0 → 9.12.0
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/dist/node/iosignal.cjs
CHANGED
|
@@ -18,7 +18,7 @@ var fs = require('fs');
|
|
|
18
18
|
var process$1 = require('process');
|
|
19
19
|
var path = require('path');
|
|
20
20
|
|
|
21
|
-
var version$1 = "9.
|
|
21
|
+
var version$1 = "9.12.0";
|
|
22
22
|
var pkg = {
|
|
23
23
|
version: version$1};
|
|
24
24
|
|
|
@@ -7527,6 +7527,7 @@ class RemoteCore {
|
|
|
7527
7527
|
this.did = ''; // Device Id
|
|
7528
7528
|
this.uid = ''; // User Id
|
|
7529
7529
|
this.nick = '';
|
|
7530
|
+
this.site = ''; // the Origin host of a browser connection, set by Remote
|
|
7530
7531
|
|
|
7531
7532
|
this.privateNode = false;
|
|
7532
7533
|
this.HOME_CHANNEL = '';
|
|
@@ -8181,6 +8182,19 @@ function getClientAddress(req, trust = serverOption.trustProxy) {
|
|
|
8181
8182
|
}
|
|
8182
8183
|
}
|
|
8183
8184
|
|
|
8185
|
+
// The site a browser connection came from: the host name of its Origin header ('bayo.tv'),
|
|
8186
|
+
// without scheme or port. '' when there is none (Node.js, apps, TCP) or it is 'null' (a file
|
|
8187
|
+
// page). A non-browser client can send any Origin, so this is for display only.
|
|
8188
|
+
function originHost(req) {
|
|
8189
|
+
const origin = req?.headers?.origin;
|
|
8190
|
+
if (typeof origin !== 'string' || !origin || origin === 'null' || origin.length > 512) return ''
|
|
8191
|
+
try {
|
|
8192
|
+
return new URL(origin).hostname.toLowerCase().replace(/^\[|\]$/g, '').slice(0, 253)
|
|
8193
|
+
} catch {
|
|
8194
|
+
return ''
|
|
8195
|
+
}
|
|
8196
|
+
}
|
|
8197
|
+
|
|
8184
8198
|
class Remote extends RemoteCore {
|
|
8185
8199
|
constructor(socket, req, manager) {
|
|
8186
8200
|
super(socket, manager);
|
|
@@ -8194,6 +8208,7 @@ class Remote extends RemoteCore {
|
|
|
8194
8208
|
const { ip, TLS } = getClientAddress(req, this.manager.server?.trustProxy);
|
|
8195
8209
|
this.ip = ip;
|
|
8196
8210
|
this.TLS = TLS;
|
|
8211
|
+
this.site = originHost(req);
|
|
8197
8212
|
} else {
|
|
8198
8213
|
this.TLS = false;
|
|
8199
8214
|
this.ip = normalizeIP(socket.remoteAddress) ?? '0.0.0.0';
|
|
@@ -8730,6 +8745,9 @@ function deliveryAllowed(target, sender) {
|
|
|
8730
8745
|
return policy.defaultAllow
|
|
8731
8746
|
}
|
|
8732
8747
|
|
|
8748
|
+
// Characters of an anonymous CID after its '?': lowercase Crockford base32, easy to read aloud and type.
|
|
8749
|
+
const ANONYMOUS_CID_ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';
|
|
8750
|
+
|
|
8733
8751
|
const encoder = new TextEncoder();
|
|
8734
8752
|
const decoder$1 = new TextDecoder();
|
|
8735
8753
|
|
|
@@ -9352,17 +9370,20 @@ class Manager {
|
|
|
9352
9370
|
}
|
|
9353
9371
|
|
|
9354
9372
|
|
|
9373
|
+
// One random byte per CID character.
|
|
9355
9374
|
anonymousCidRandom(size) {
|
|
9356
9375
|
return globalThis.crypto.getRandomValues(Buffer.alloc(size))
|
|
9357
9376
|
}
|
|
9358
9377
|
|
|
9359
|
-
// '?' +
|
|
9360
|
-
// synchronous turn (CID_REQ handler), so concurrent
|
|
9361
|
-
//
|
|
9378
|
+
// '?' + lowercase Crockford base32 (ANONYMOUS_CID_ALPHABET: no i, l, o, u), never one that is
|
|
9379
|
+
// online. Check and set run in the same synchronous turn (CID_REQ handler), so concurrent
|
|
9380
|
+
// requests cannot take the same CID. 4 characters normally; 8 if the short space keeps colliding.
|
|
9362
9381
|
issueAnonymousCid() {
|
|
9363
|
-
for (const [size, tries] of [[
|
|
9382
|
+
for (const [size, tries] of [[4, 8], [8, 8]]) {
|
|
9364
9383
|
for (let i = 0; i < tries; i++) {
|
|
9365
|
-
|
|
9384
|
+
let cid = '?';
|
|
9385
|
+
// 32 divides 256, so the low 5 bits of a random byte are uniform.
|
|
9386
|
+
for (const byte of this.anonymousCidRandom(size)) cid += ANONYMOUS_CID_ALPHABET[byte & 31];
|
|
9366
9387
|
if (!this.cid2remote.has(cid)) return cid
|
|
9367
9388
|
}
|
|
9368
9389
|
}
|
|
@@ -9655,7 +9676,6 @@ class BohoAuth {
|
|
|
9655
9676
|
//7. setting info.
|
|
9656
9677
|
peer.did = id;
|
|
9657
9678
|
peer.cid = authInfo.cid;
|
|
9658
|
-
peer.nick = authInfo.cid; // temporary: nick as cid
|
|
9659
9679
|
if (authInfo.uid) peer.uid = authInfo.uid;
|
|
9660
9680
|
// Delivery policy of an owned device, in place before the CID is reachable (step 9).
|
|
9661
9681
|
peer.ownerUid = uid;
|
|
@@ -10211,6 +10231,9 @@ class FileKeyProvider {
|
|
|
10211
10231
|
}
|
|
10212
10232
|
|
|
10213
10233
|
const DEVICE_PREFIX = "device:";
|
|
10234
|
+
// Every device CID in use. The account service picks new CIDs outside it, so a device added here
|
|
10235
|
+
// is listed too and no member can be given its CID.
|
|
10236
|
+
const CID_SET = "sets_cid";
|
|
10214
10237
|
|
|
10215
10238
|
class RedisKeyProvider {
|
|
10216
10239
|
constructor(redisClient) {
|
|
@@ -10247,11 +10270,17 @@ class RedisKeyProvider {
|
|
|
10247
10270
|
const fields = { 'key': Base64hashKey, 'cid': cid };
|
|
10248
10271
|
if (role) fields.role = role;
|
|
10249
10272
|
if (quota) fields.quota = quota;
|
|
10250
|
-
|
|
10273
|
+
const old = await this.redis.hGet(DEVICE_PREFIX + id, 'cid');
|
|
10274
|
+
const result = await this.redis.hSet(DEVICE_PREFIX + id, fields);
|
|
10275
|
+
if (old && old !== cid) await this.redis.sRem(CID_SET, old);
|
|
10276
|
+
if (cid) await this.redis.sAdd(CID_SET, cid);
|
|
10277
|
+
return result
|
|
10251
10278
|
}
|
|
10252
10279
|
|
|
10253
10280
|
//sudoService call
|
|
10254
10281
|
async delAuth(id) {
|
|
10282
|
+
const cid = await this.redis.hGet(DEVICE_PREFIX + id, 'cid');
|
|
10283
|
+
if (cid) await this.redis.sRem(CID_SET, cid);
|
|
10255
10284
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
10256
10285
|
}
|
|
10257
10286
|
|
package/dist/node/iosignal.js
CHANGED
|
@@ -16,7 +16,7 @@ import fs, { readFileSync } from 'fs';
|
|
|
16
16
|
import { memoryUsage } from 'process';
|
|
17
17
|
import path from 'path';
|
|
18
18
|
|
|
19
|
-
var version$1 = "9.
|
|
19
|
+
var version$1 = "9.12.0";
|
|
20
20
|
var pkg = {
|
|
21
21
|
version: version$1};
|
|
22
22
|
|
|
@@ -7525,6 +7525,7 @@ class RemoteCore {
|
|
|
7525
7525
|
this.did = ''; // Device Id
|
|
7526
7526
|
this.uid = ''; // User Id
|
|
7527
7527
|
this.nick = '';
|
|
7528
|
+
this.site = ''; // the Origin host of a browser connection, set by Remote
|
|
7528
7529
|
|
|
7529
7530
|
this.privateNode = false;
|
|
7530
7531
|
this.HOME_CHANNEL = '';
|
|
@@ -8179,6 +8180,19 @@ function getClientAddress(req, trust = serverOption.trustProxy) {
|
|
|
8179
8180
|
}
|
|
8180
8181
|
}
|
|
8181
8182
|
|
|
8183
|
+
// The site a browser connection came from: the host name of its Origin header ('bayo.tv'),
|
|
8184
|
+
// without scheme or port. '' when there is none (Node.js, apps, TCP) or it is 'null' (a file
|
|
8185
|
+
// page). A non-browser client can send any Origin, so this is for display only.
|
|
8186
|
+
function originHost(req) {
|
|
8187
|
+
const origin = req?.headers?.origin;
|
|
8188
|
+
if (typeof origin !== 'string' || !origin || origin === 'null' || origin.length > 512) return ''
|
|
8189
|
+
try {
|
|
8190
|
+
return new URL(origin).hostname.toLowerCase().replace(/^\[|\]$/g, '').slice(0, 253)
|
|
8191
|
+
} catch {
|
|
8192
|
+
return ''
|
|
8193
|
+
}
|
|
8194
|
+
}
|
|
8195
|
+
|
|
8182
8196
|
class Remote extends RemoteCore {
|
|
8183
8197
|
constructor(socket, req, manager) {
|
|
8184
8198
|
super(socket, manager);
|
|
@@ -8192,6 +8206,7 @@ class Remote extends RemoteCore {
|
|
|
8192
8206
|
const { ip, TLS } = getClientAddress(req, this.manager.server?.trustProxy);
|
|
8193
8207
|
this.ip = ip;
|
|
8194
8208
|
this.TLS = TLS;
|
|
8209
|
+
this.site = originHost(req);
|
|
8195
8210
|
} else {
|
|
8196
8211
|
this.TLS = false;
|
|
8197
8212
|
this.ip = normalizeIP(socket.remoteAddress) ?? '0.0.0.0';
|
|
@@ -8728,6 +8743,9 @@ function deliveryAllowed(target, sender) {
|
|
|
8728
8743
|
return policy.defaultAllow
|
|
8729
8744
|
}
|
|
8730
8745
|
|
|
8746
|
+
// Characters of an anonymous CID after its '?': lowercase Crockford base32, easy to read aloud and type.
|
|
8747
|
+
const ANONYMOUS_CID_ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';
|
|
8748
|
+
|
|
8731
8749
|
const encoder = new TextEncoder();
|
|
8732
8750
|
const decoder$1 = new TextDecoder();
|
|
8733
8751
|
|
|
@@ -9350,17 +9368,20 @@ class Manager {
|
|
|
9350
9368
|
}
|
|
9351
9369
|
|
|
9352
9370
|
|
|
9371
|
+
// One random byte per CID character.
|
|
9353
9372
|
anonymousCidRandom(size) {
|
|
9354
9373
|
return globalThis.crypto.getRandomValues(Buffer.alloc(size))
|
|
9355
9374
|
}
|
|
9356
9375
|
|
|
9357
|
-
// '?' +
|
|
9358
|
-
// synchronous turn (CID_REQ handler), so concurrent
|
|
9359
|
-
//
|
|
9376
|
+
// '?' + lowercase Crockford base32 (ANONYMOUS_CID_ALPHABET: no i, l, o, u), never one that is
|
|
9377
|
+
// online. Check and set run in the same synchronous turn (CID_REQ handler), so concurrent
|
|
9378
|
+
// requests cannot take the same CID. 4 characters normally; 8 if the short space keeps colliding.
|
|
9360
9379
|
issueAnonymousCid() {
|
|
9361
|
-
for (const [size, tries] of [[
|
|
9380
|
+
for (const [size, tries] of [[4, 8], [8, 8]]) {
|
|
9362
9381
|
for (let i = 0; i < tries; i++) {
|
|
9363
|
-
|
|
9382
|
+
let cid = '?';
|
|
9383
|
+
// 32 divides 256, so the low 5 bits of a random byte are uniform.
|
|
9384
|
+
for (const byte of this.anonymousCidRandom(size)) cid += ANONYMOUS_CID_ALPHABET[byte & 31];
|
|
9364
9385
|
if (!this.cid2remote.has(cid)) return cid
|
|
9365
9386
|
}
|
|
9366
9387
|
}
|
|
@@ -9653,7 +9674,6 @@ class BohoAuth {
|
|
|
9653
9674
|
//7. setting info.
|
|
9654
9675
|
peer.did = id;
|
|
9655
9676
|
peer.cid = authInfo.cid;
|
|
9656
|
-
peer.nick = authInfo.cid; // temporary: nick as cid
|
|
9657
9677
|
if (authInfo.uid) peer.uid = authInfo.uid;
|
|
9658
9678
|
// Delivery policy of an owned device, in place before the CID is reachable (step 9).
|
|
9659
9679
|
peer.ownerUid = uid;
|
|
@@ -10209,6 +10229,9 @@ class FileKeyProvider {
|
|
|
10209
10229
|
}
|
|
10210
10230
|
|
|
10211
10231
|
const DEVICE_PREFIX = "device:";
|
|
10232
|
+
// Every device CID in use. The account service picks new CIDs outside it, so a device added here
|
|
10233
|
+
// is listed too and no member can be given its CID.
|
|
10234
|
+
const CID_SET = "sets_cid";
|
|
10212
10235
|
|
|
10213
10236
|
class RedisKeyProvider {
|
|
10214
10237
|
constructor(redisClient) {
|
|
@@ -10245,11 +10268,17 @@ class RedisKeyProvider {
|
|
|
10245
10268
|
const fields = { 'key': Base64hashKey, 'cid': cid };
|
|
10246
10269
|
if (role) fields.role = role;
|
|
10247
10270
|
if (quota) fields.quota = quota;
|
|
10248
|
-
|
|
10271
|
+
const old = await this.redis.hGet(DEVICE_PREFIX + id, 'cid');
|
|
10272
|
+
const result = await this.redis.hSet(DEVICE_PREFIX + id, fields);
|
|
10273
|
+
if (old && old !== cid) await this.redis.sRem(CID_SET, old);
|
|
10274
|
+
if (cid) await this.redis.sAdd(CID_SET, cid);
|
|
10275
|
+
return result
|
|
10249
10276
|
}
|
|
10250
10277
|
|
|
10251
10278
|
//sudoService call
|
|
10252
10279
|
async delAuth(id) {
|
|
10280
|
+
const cid = await this.redis.hGet(DEVICE_PREFIX + id, 'cid');
|
|
10281
|
+
if (cid) await this.redis.sRem(CID_SET, cid);
|
|
10253
10282
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
10254
10283
|
}
|
|
10255
10284
|
|