@makerbi/remodex 1.5.0 → 1.5.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 +1 -1
- package/src/secure-device-state.js +34 -6
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ const DEFAULT_STORE_DIR = path.join(os.homedir(), ".remodex");
|
|
|
14
14
|
const DEFAULT_STORE_FILE = path.join(DEFAULT_STORE_DIR, "device-state.json");
|
|
15
15
|
const KEYCHAIN_SERVICE = "com.remodex.bridge.device-state";
|
|
16
16
|
const KEYCHAIN_ACCOUNT = "default";
|
|
17
|
+
const UUID_V4_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
17
18
|
let hasLoggedKeychainMismatch = false;
|
|
18
19
|
|
|
19
20
|
// Loads the canonical bridge state or bootstraps a fresh one when no trusted state exists yet.
|
|
@@ -22,8 +23,11 @@ function loadOrCreateBridgeDeviceState() {
|
|
|
22
23
|
const keychainRecord = readKeychainStateRecord();
|
|
23
24
|
|
|
24
25
|
if (fileRecord.state) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const canonicalState = recoverBridgeDeviceIdentity(fileRecord.state, {
|
|
27
|
+
fallbackState: keychainRecord.state,
|
|
28
|
+
});
|
|
29
|
+
reconcileLegacyKeychainMirror(canonicalState, keychainRecord);
|
|
30
|
+
return canonicalState;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
if (fileRecord.error) {
|
|
@@ -31,8 +35,9 @@ function loadOrCreateBridgeDeviceState() {
|
|
|
31
35
|
warnOnce(
|
|
32
36
|
"[remodex] Recovering the canonical device-state.json from the legacy Keychain pairing mirror."
|
|
33
37
|
);
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
const recoveredState = recoverBridgeDeviceIdentity(keychainRecord.state);
|
|
39
|
+
writeBridgeDeviceState(recoveredState);
|
|
40
|
+
return recoveredState;
|
|
36
41
|
}
|
|
37
42
|
throw corruptedStateError("device-state.json", fileRecord.error);
|
|
38
43
|
}
|
|
@@ -47,8 +52,9 @@ function loadOrCreateBridgeDeviceState() {
|
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
if (keychainRecord.state) {
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const recoveredState = recoverBridgeDeviceIdentity(keychainRecord.state);
|
|
56
|
+
writeBridgeDeviceState(recoveredState);
|
|
57
|
+
return recoveredState;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
const nextState = createBridgeDeviceState();
|
|
@@ -382,10 +388,32 @@ function normalizeBridgeDeviceState(rawState) {
|
|
|
382
388
|
};
|
|
383
389
|
}
|
|
384
390
|
|
|
391
|
+
function recoverBridgeDeviceIdentity(state, { fallbackState = null } = {}) {
|
|
392
|
+
if (isValidBridgeDeviceId(state?.macDeviceId)) {
|
|
393
|
+
return state;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (fallbackState && isValidBridgeDeviceId(fallbackState.macDeviceId)) {
|
|
397
|
+
warnOnce("[remodex] Recovering an invalid saved bridge device identity from the legacy Keychain mirror.");
|
|
398
|
+
writeBridgeDeviceState(fallbackState);
|
|
399
|
+
return fallbackState;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
warnOnce("[remodex] Rotating an invalid saved bridge device identity; scan the fresh QR to pair again.");
|
|
403
|
+
const nextState = createBridgeDeviceState();
|
|
404
|
+
nextState.lastSeenPhoneAppVersion = state?.lastSeenPhoneAppVersion || null;
|
|
405
|
+
writeBridgeDeviceState(nextState);
|
|
406
|
+
return nextState;
|
|
407
|
+
}
|
|
408
|
+
|
|
385
409
|
function bridgeStatesEqual(left, right) {
|
|
386
410
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
387
411
|
}
|
|
388
412
|
|
|
413
|
+
function isValidBridgeDeviceId(value) {
|
|
414
|
+
return UUID_V4_PATTERN.test(normalizeNonEmptyString(value));
|
|
415
|
+
}
|
|
416
|
+
|
|
389
417
|
function normalizeNonEmptyString(value) {
|
|
390
418
|
if (typeof value !== "string") {
|
|
391
419
|
return "";
|