@bom-pi/core 0.1.0 → 0.1.1
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/package.json +19 -19
- package/src/connector-store.ts +18 -3
- package/src/device-ceremony.ts +2 -1
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
"name": "@bom-pi/core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Core pairing machinery for Bom Pi: ceremonies, transports, durable stores",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@bom-pi/protocol": "0.1.0"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
"./cloud-connector.ts": "./src/cloud-connector.ts",
|
|
12
|
+
"./cloud-wss-transport.ts": "./src/cloud-wss-transport.ts",
|
|
13
|
+
"./connector-store.ts": "./src/connector-store.ts",
|
|
14
|
+
"./device-ceremony.ts": "./src/device-ceremony.ts",
|
|
15
|
+
"./ingress-receiver.ts": "./src/ingress-receiver.ts",
|
|
16
|
+
"./lan-pairing.ts": "./src/lan-pairing.ts",
|
|
17
|
+
"./pairing-storage.ts": "./src/pairing-storage.ts",
|
|
18
|
+
"./secure-transport.ts": "./src/secure-transport.ts",
|
|
19
|
+
"./session-gateway.ts": "./src/session-gateway.ts"
|
|
20
|
+
}
|
|
21
21
|
}
|
package/src/connector-store.ts
CHANGED
|
@@ -92,6 +92,15 @@ function ownerMismatch(stat: Stats): boolean {
|
|
|
92
92
|
return process.getuid !== undefined && stat.uid !== process.getuid();
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** POSIX mode bits are this store's privacy boundary on POSIX hosts. Windows stat carries no
|
|
96
|
+
* such bits (a writable file reads 0o666); there the boundary is the user profile's ACL, and
|
|
97
|
+
* the uid/ownership checks above still apply wherever uid exists. */
|
|
98
|
+
const POSIX_MODES = process.platform !== "win32";
|
|
99
|
+
|
|
100
|
+
function privateMode(stat: Stats, mode: number): boolean {
|
|
101
|
+
return !POSIX_MODES || (stat.mode & 0o777) === mode;
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
/** Slot names are derived only from the validated fingerprint: exact, collision-free and free of
|
|
96
105
|
* path metacharacters. A store instance is bound to exactly one pinned cloud forever. */
|
|
97
106
|
function slotPaths(
|
|
@@ -282,7 +291,7 @@ function parseRecord(text: string, pinned: PinnedIdentity): ConnectorSnapshot {
|
|
|
282
291
|
function assertRecordFile(stat: Stats): void {
|
|
283
292
|
if (
|
|
284
293
|
!stat.isFile() ||
|
|
285
|
-
(stat
|
|
294
|
+
!privateMode(stat, 0o600) ||
|
|
286
295
|
ownerMismatch(stat) ||
|
|
287
296
|
stat.size > MAX_RECORD_BYTES
|
|
288
297
|
) {
|
|
@@ -293,7 +302,7 @@ function assertRecordFile(stat: Stats): void {
|
|
|
293
302
|
async function checkDirectory(directory: string): Promise<void> {
|
|
294
303
|
const stat = await lstat(directory).catch(() => fail("missing store directory"));
|
|
295
304
|
|
|
296
|
-
if (!stat.isDirectory() || (stat
|
|
305
|
+
if (!stat.isDirectory() || !privateMode(stat, 0o700)) {
|
|
297
306
|
fail("store directory must be private (0700) and not a symlink");
|
|
298
307
|
}
|
|
299
308
|
|
|
@@ -303,6 +312,12 @@ async function checkDirectory(directory: string): Promise<void> {
|
|
|
303
312
|
}
|
|
304
313
|
|
|
305
314
|
async function syncDirectory(directory: string): Promise<void> {
|
|
315
|
+
// Windows cannot open a directory for fsync (EPERM); there the atomic rename itself is the
|
|
316
|
+
// durability step, as in every other Windows-native atomic writer. POSIX keeps the fsync.
|
|
317
|
+
if (process.platform === "win32") {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
306
321
|
const handle = await open(directory, "r");
|
|
307
322
|
|
|
308
323
|
try {
|
|
@@ -385,7 +400,7 @@ async function assertLock(directory: string, lockPath: string, lock: LockLease):
|
|
|
385
400
|
if (
|
|
386
401
|
!owned.isFile() ||
|
|
387
402
|
!present.isFile() ||
|
|
388
|
-
(present
|
|
403
|
+
!privateMode(present, 0o600) ||
|
|
389
404
|
owned.dev !== present.dev ||
|
|
390
405
|
owned.ino !== present.ino ||
|
|
391
406
|
owned.nlink !== 1 ||
|
package/src/device-ceremony.ts
CHANGED
|
@@ -1893,7 +1893,8 @@ export class DevicePairBroker {
|
|
|
1893
1893
|
|
|
1894
1894
|
record.state = decision === "approve" ? "approved" : "denied";
|
|
1895
1895
|
record.decision = decision;
|
|
1896
|
-
record.approvedExpiry =
|
|
1896
|
+
record.approvedExpiry =
|
|
1897
|
+
decision === "approve" ? approvedExpiryOf(input.decision) : null;
|
|
1897
1898
|
record.decisionReceipt = receipt;
|
|
1898
1899
|
record.decisionBytes = Buffer.from(
|
|
1899
1900
|
canonicalJson(input.decision as unknown as CanonicalValue),
|