@dotrino/vaultd 0.164.1 → 0.165.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/README.md +1 -1
- package/lib/src/admin.js +2 -2
- package/lib/src/atrest.js +4 -4
- package/lib/src/browser.js +10 -10
- package/lib/src/core/approvals.js +3 -2
- package/lib/src/core/libVersion.js +2 -2
- package/lib/src/core/sealer.js +2 -2
- package/lib/src/core/sealers.js +15 -15
- package/lib/src/core/secretsStore.js +66 -66
- package/lib/src/core/subacta.js +8 -8
- package/lib/src/core/threadStore.js +2 -2
- package/lib/src/core/transport.js +31 -31
- package/lib/src/core/vault.js +247 -214
- package/lib/src/enroll.js +1 -1
- package/lib/src/env.js +10 -10
- package/lib/src/index.js +7 -7
- package/lib/src/kek.js +6 -6
- package/lib/src/localdesk.js +10 -10
- package/lib/src/lock.js +18 -18
- package/lib/src/loginClient.js +23 -23
- package/lib/src/passwordLogins.js +8 -8
- package/lib/src/proc.js +5 -5
- package/lib/src/procContext.js +2 -2
- package/lib/src/service.js +67 -43
- package/lib/src/sshKeys.js +3 -3
- package/lib/src/version.js +4 -4
- package/package.json +3 -3
- package/src/ctl.js +72 -72
- package/src/daemon.js +105 -105
- package/src/keyowner.js +3 -3
- package/src/manager.js +5 -5
- package/src/platform.js +17 -17
- package/src/profiles.js +47 -47
- package/src/replica.js +25 -25
- package/src/selfupdate.js +6 -6
- package/src/tui/app.js +81 -81
- package/src/tui/i18n.js +1 -1
- package/src/update.js +12 -12
- package/src/updateApproval.js +1 -1
- package/src/vaultControl.js +4 -4
package/src/profiles.js
CHANGED
|
@@ -283,18 +283,18 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
283
283
|
* daemon. Ese es el precio, y es el mismo que ya se paga por poder sellar actas
|
|
284
284
|
* estando abierta: lo que acota la exposición es el auto-candado, no el olvido.
|
|
285
285
|
*/
|
|
286
|
-
const
|
|
286
|
+
const keys = new Map() // id -> Uint8Array (la llave derivada, solo si está abierto)
|
|
287
287
|
// La `K` de los perfiles SIN candado que la guardan bajo la llave de la máquina (`openKey`).
|
|
288
|
-
const
|
|
288
|
+
const byMachine = new Map()
|
|
289
289
|
|
|
290
290
|
/** Borra el material de verdad antes de soltar la referencia. */
|
|
291
|
-
const
|
|
292
|
-
const k =
|
|
291
|
+
const forget = (id) => {
|
|
292
|
+
const k = keys.get(id)
|
|
293
293
|
if (k) { try { k.fill(0) } catch (_) {} }
|
|
294
|
-
|
|
295
|
-
const m =
|
|
294
|
+
keys.delete(id)
|
|
295
|
+
const m = byMachine.get(id)
|
|
296
296
|
if (m) { try { m.fill(0) } catch (_) {} }
|
|
297
|
-
|
|
297
|
+
byMachine.delete(id)
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
/** ¿Sigue abierto? Vence al MIRARLO, así que no hace falta ningún temporizador. */
|
|
@@ -303,7 +303,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
303
303
|
if (until == null) return false
|
|
304
304
|
if (autoLockMs > 0 && Date.now() >= until) {
|
|
305
305
|
unlocked.delete(id)
|
|
306
|
-
|
|
306
|
+
forget(id)
|
|
307
307
|
// El aviso va después de borrarlo: quien lo escuche verá el perfil ya cerrado.
|
|
308
308
|
try { onAutoLock?.(id) } catch (_) {}
|
|
309
309
|
return false
|
|
@@ -352,7 +352,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
352
352
|
* Sin código, el rechazo llegaba como un texto suelto del daemon, indistinguible de
|
|
353
353
|
* «se volvió a pedir la contraseña porque sí».
|
|
354
354
|
*/
|
|
355
|
-
function
|
|
355
|
+
function throttle (p) {
|
|
356
356
|
let tries = p.tries || { n: 0, at: 0 }
|
|
357
357
|
if (tries.at && Date.now() - tries.at > TRIES_FORGET_MS) {
|
|
358
358
|
tries = { n: 0, at: 0 }
|
|
@@ -391,7 +391,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
391
391
|
} else {
|
|
392
392
|
throw Object.assign(new Error('nothing to open the profile with'), { code: 'NO_CREDENTIALS' })
|
|
393
393
|
}
|
|
394
|
-
const tries =
|
|
394
|
+
const tries = throttle(p)
|
|
395
395
|
let K = null
|
|
396
396
|
for (const d of cands) {
|
|
397
397
|
const k = doorKey(d, { password, secret })
|
|
@@ -450,11 +450,11 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
450
450
|
// misma que sale en `members`. Ambiguo se rechaza, no se adivina.
|
|
451
451
|
// El id que tenía antes de que la carpeta se llamara como su llave (ver
|
|
452
452
|
// `ensureNamedByKey`): un cliente abierto durante la actualización sigue usándolo.
|
|
453
|
-
const
|
|
454
|
-
if (
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
if (
|
|
453
|
+
const old = data.profiles.find((p) => p.wasId && p.wasId.toLowerCase() === needle)
|
|
454
|
+
if (old) return old.id
|
|
455
|
+
const byPrefix = data.profiles.filter((p) => p.id.toLowerCase().startsWith(needle))
|
|
456
|
+
if (byPrefix.length === 1) return byPrefix[0].id
|
|
457
|
+
if (byPrefix.length > 1) throw new Error(`"${ref}" matches ${byPrefix.length} profiles; give more of the id (dotrino-vault profile ls)`)
|
|
458
458
|
throw new Error('profile does not exist: ' + ref)
|
|
459
459
|
},
|
|
460
460
|
|
|
@@ -603,15 +603,15 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
603
603
|
try { pub = await mintKey(dir) } catch (_) { return id }
|
|
604
604
|
}
|
|
605
605
|
if (!pub) return id
|
|
606
|
-
const
|
|
607
|
-
if (
|
|
608
|
-
if (fs.existsSync(dirOf(
|
|
609
|
-
throw Object.assign(new Error(`cannot rename ${id}: ${
|
|
606
|
+
const wants = await keyDirName(pub)
|
|
607
|
+
if (wants === id) return id
|
|
608
|
+
if (fs.existsSync(dirOf(wants))) {
|
|
609
|
+
throw Object.assign(new Error(`cannot rename ${id}: ${wants} already exists`), { code: 'key-exists' })
|
|
610
610
|
}
|
|
611
|
-
fs.renameSync(dir, dirOf(
|
|
611
|
+
fs.renameSync(dir, dirOf(wants))
|
|
612
612
|
const p = find(id)
|
|
613
613
|
if (p) {
|
|
614
|
-
p.id =
|
|
614
|
+
p.id = wants
|
|
615
615
|
// EL NOMBRE VIEJO SE RECUERDA. Quien tenía una consola o una TUI abierta durante
|
|
616
616
|
// la actualización sigue pidiendo por el id de antes, y sin esto cada petición
|
|
617
617
|
// suya contestaba «ese perfil no existe» —que es verdad y no ayuda nada—. Se
|
|
@@ -619,11 +619,11 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
619
619
|
// reinicie, que es cuando dejará de preguntarlo.
|
|
620
620
|
p.wasId = id
|
|
621
621
|
}
|
|
622
|
-
if (data.current === id) data.current =
|
|
623
|
-
if (unlocked.has(id)) { unlocked.set(
|
|
624
|
-
if (
|
|
622
|
+
if (data.current === id) data.current = wants
|
|
623
|
+
if (unlocked.has(id)) { unlocked.set(wants, unlocked.get(id)); unlocked.delete(id) }
|
|
624
|
+
if (keys.has(id)) { keys.set(wants, keys.get(id)); keys.delete(id) }
|
|
625
625
|
save()
|
|
626
|
-
return
|
|
626
|
+
return wants
|
|
627
627
|
},
|
|
628
628
|
|
|
629
629
|
/** Quita la marca de «nació para adoptar» (ya adoptó, o se canceló). */
|
|
@@ -652,7 +652,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
652
652
|
if (data.current === id) data.current = data.profiles[0].id
|
|
653
653
|
save()
|
|
654
654
|
unlocked.delete(id)
|
|
655
|
-
|
|
655
|
+
forget(id)
|
|
656
656
|
try { fs.rmSync(dirOf(id), { recursive: true, force: true }) } catch (_) {}
|
|
657
657
|
return { id, name: p.name || '' }
|
|
658
658
|
},
|
|
@@ -698,7 +698,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
698
698
|
*/
|
|
699
699
|
async keyWith (id, creds = {}) {
|
|
700
700
|
const p = assertExists(id)
|
|
701
|
-
if (isOpen(id) &&
|
|
701
|
+
if (isOpen(id) && keys.get(id)) return new Uint8Array(keys.get(id))
|
|
702
702
|
return new Uint8Array(await resolveK(p, normCreds(creds)))
|
|
703
703
|
},
|
|
704
704
|
|
|
@@ -716,7 +716,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
716
716
|
open(id)
|
|
717
717
|
// La llave se queda mientras el candado esté abierto: es lo que permite envolverle
|
|
718
718
|
// su cajón a un servicio que se enrola AHORA, sin volver a pedir la frase.
|
|
719
|
-
|
|
719
|
+
keys.set(id, new Uint8Array(K))
|
|
720
720
|
K.fill(0)
|
|
721
721
|
return { ok: true, locked: false }
|
|
722
722
|
},
|
|
@@ -741,7 +741,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
741
741
|
const K = p.kdf?.salt && password
|
|
742
742
|
? new Uint8Array(scryptKey(password, p.kdf.salt))
|
|
743
743
|
: new Uint8Array(crypto2.randomBytes(32))
|
|
744
|
-
|
|
744
|
+
keys.set(id, K)
|
|
745
745
|
open(id)
|
|
746
746
|
return { K, fresh: true }
|
|
747
747
|
},
|
|
@@ -749,7 +749,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
749
749
|
/** Deshace un `ensureKey` fresco que no llegó a tener puerta. */
|
|
750
750
|
dropFreshKey (id) {
|
|
751
751
|
const p = find(id)
|
|
752
|
-
if (p && !hasKey(p)) { unlocked.delete(id);
|
|
752
|
+
if (p && !hasKey(p)) { unlocked.delete(id); forget(id) }
|
|
753
753
|
},
|
|
754
754
|
|
|
755
755
|
/**
|
|
@@ -786,7 +786,7 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
786
786
|
save()
|
|
787
787
|
// Si la llave venía de la de la máquina (perfil sin candado), ahora es la del perfil
|
|
788
788
|
// ABIERTO: tiene que estar donde la busca `openKey` con el candado puesto.
|
|
789
|
-
if (!
|
|
789
|
+
if (!keys.get(id)) keys.set(id, new Uint8Array(K))
|
|
790
790
|
open(id)
|
|
791
791
|
return publicDoor(door)
|
|
792
792
|
},
|
|
@@ -867,14 +867,14 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
867
867
|
* Es lo correcto además de lo posible: ponerla es una decisión del dueño, y el dueño
|
|
868
868
|
* acaba de teclear la principal.
|
|
869
869
|
*/
|
|
870
|
-
setSecondary (id,
|
|
870
|
+
setSecondary (id, derived) {
|
|
871
871
|
const p = assertExists(id)
|
|
872
872
|
if (!isProtected(p)) throw Object.assign(new Error('this profile has no lock: there is nothing to open remotely'), { code: 'NO_PASSWORD' })
|
|
873
|
-
const
|
|
874
|
-
if (!
|
|
875
|
-
if (!(
|
|
873
|
+
const key = api.openKey(id)
|
|
874
|
+
if (!key) throw Object.assign(new Error('open the profile first (dotrino-vault unlock)'), { code: 'PROFILE_LOCKED' })
|
|
875
|
+
if (!(derived instanceof Uint8Array) || derived.length !== 32) throw new Error('the admin key must be 32 bytes')
|
|
876
876
|
const salt = p.kdf2?.salt || b64(crypto.getRandomValues(new Uint8Array(32)))
|
|
877
|
-
p.kdf2 = { v: 1, salt, wrapped: encryptText(b64(
|
|
877
|
+
p.kdf2 = { v: 1, salt, wrapped: encryptText(b64(key), Buffer.from(derived)) }
|
|
878
878
|
save()
|
|
879
879
|
return { ok: true }
|
|
880
880
|
},
|
|
@@ -897,13 +897,13 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
897
897
|
*
|
|
898
898
|
* Comparte el contador de `unlock` (`frenar`): probar por aquí frena allá y al revés.
|
|
899
899
|
*/
|
|
900
|
-
async openWithSecondary (id,
|
|
900
|
+
async openWithSecondary (id, derived) {
|
|
901
901
|
const p = assertExists(id)
|
|
902
902
|
if (!p.kdf2?.wrapped) throw Object.assign(new Error('this profile has no admin password'), { code: 'NO_SECONDARY' })
|
|
903
|
-
const tries =
|
|
904
|
-
let
|
|
905
|
-
try {
|
|
906
|
-
if (!
|
|
903
|
+
const tries = throttle(p)
|
|
904
|
+
let key = null
|
|
905
|
+
try { key = Buffer.from(decryptText(p.kdf2.wrapped, Buffer.from(derived)), 'base64') } catch (_) { key = null }
|
|
906
|
+
if (!key || key.length !== 32) {
|
|
907
907
|
p.tries = { n: tries.n + 1, at: Date.now() }
|
|
908
908
|
save()
|
|
909
909
|
throw Object.assign(new Error('wrong admin password'), { code: 'WRONG_PASSWORD', tries: p.tries.n })
|
|
@@ -911,11 +911,11 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
911
911
|
delete p.tries
|
|
912
912
|
save()
|
|
913
913
|
open(id)
|
|
914
|
-
|
|
914
|
+
keys.set(id, new Uint8Array(key))
|
|
915
915
|
return { ok: true, locked: false }
|
|
916
916
|
},
|
|
917
917
|
|
|
918
|
-
lock (id) { assertExists(id); unlocked.delete(id);
|
|
918
|
+
lock (id) { assertExists(id); unlocked.delete(id); forget(id); return { ok: true, locked: api.isLocked(id) } },
|
|
919
919
|
|
|
920
920
|
/**
|
|
921
921
|
* La llave del perfil ABIERTO, o `null`. Es lo que hace que «la bóveda está abierta»
|
|
@@ -924,18 +924,18 @@ export function openProfiles (root = dataDir(), { autoLockMs = AUTO_LOCK_MS, onA
|
|
|
924
924
|
* tendrá que pedirla, que es exactamente el comportamiento de antes.
|
|
925
925
|
*/
|
|
926
926
|
openKey (id) {
|
|
927
|
-
if (isOpen(id)) return
|
|
927
|
+
if (isOpen(id)) return keys.get(id) || null
|
|
928
928
|
// SIN CANDADO PERO CON LLAVE: un perfil al que se le quitó la última puerta. Su `K` vive
|
|
929
929
|
// bajo la llave de la máquina y se abre sola, como el resto del disco.
|
|
930
930
|
const p = find(id)
|
|
931
931
|
const m = p && !isProtected(p) ? (p.doors || []).find((d) => d.kind === 'machine') : null
|
|
932
932
|
if (!m) return null
|
|
933
|
-
if (!
|
|
933
|
+
if (!byMachine.has(id)) {
|
|
934
934
|
const K = Buffer.from(decryptText(m.wrapped, Buffer.from(kekFor(dirOf(id)))), 'base64')
|
|
935
935
|
if (K.length !== 32) throw Object.assign(new Error('the profile key under this machine key is malformed'), { code: 'BAD_PROFILE_KEY' })
|
|
936
|
-
|
|
936
|
+
byMachine.set(id, new Uint8Array(K))
|
|
937
937
|
}
|
|
938
|
-
return
|
|
938
|
+
return byMachine.get(id)
|
|
939
939
|
},
|
|
940
940
|
|
|
941
941
|
/**
|
package/src/replica.js
CHANGED
|
@@ -54,11 +54,11 @@ const STATE = 'state.json'
|
|
|
54
54
|
*
|
|
55
55
|
* Las envolturas se SUMAN: son de aparatos distintos y ninguna estorba a otra.
|
|
56
56
|
*/
|
|
57
|
-
export function mergeBundle (
|
|
58
|
-
if (!
|
|
59
|
-
if (!
|
|
60
|
-
const entries = { ...(
|
|
61
|
-
for (const [k, e] of Object.entries(
|
|
57
|
+
export function mergeBundle (old, newer) {
|
|
58
|
+
if (!old) return newer
|
|
59
|
+
if (!newer) return old
|
|
60
|
+
const entries = { ...(old.entries || {}) }
|
|
61
|
+
for (const [k, e] of Object.entries(newer.entries || {})) {
|
|
62
62
|
const a = entries[k]
|
|
63
63
|
if (!a) { entries[k] = e; continue }
|
|
64
64
|
const ga = a.gen || 0
|
|
@@ -66,13 +66,13 @@ export function mergeBundle (viejo, nuevo) {
|
|
|
66
66
|
if (gb > ga) entries[k] = e
|
|
67
67
|
else if (gb === ga && String(e.e?.ct ?? e.pubv ?? '') < String(a.e?.ct ?? a.pubv ?? '')) entries[k] = e
|
|
68
68
|
}
|
|
69
|
-
const wraps = mergeWraps(
|
|
69
|
+
const wraps = mergeWraps(old.wraps, newer.wraps)
|
|
70
70
|
// `ns`/`dev` son la envoltura VIGENTE de cada lado, y salen de la lista ya mezclada: con
|
|
71
71
|
// `{...viejo, ...nuevo}` se quedaba la del empujón aunque su generación fuera menor, o
|
|
72
72
|
// sea justo lo contrario de lo que decide la lista.
|
|
73
73
|
return {
|
|
74
|
-
...
|
|
75
|
-
...
|
|
74
|
+
...old,
|
|
75
|
+
...newer,
|
|
76
76
|
entries,
|
|
77
77
|
wraps,
|
|
78
78
|
ns: wraps.ns[wraps.ns.length - 1] || null,
|
|
@@ -113,17 +113,17 @@ export const bundleKey = (ns, devicePub) => `${ns} ${devicePub}`
|
|
|
113
113
|
export function openReplicaStore (dir) {
|
|
114
114
|
fs.mkdirSync(dir, { recursive: true })
|
|
115
115
|
const atRest = atRestFor(dir)
|
|
116
|
-
const
|
|
117
|
-
const
|
|
116
|
+
const read = (f, d) => readJson(path.join(dir, f), d, atRest)
|
|
117
|
+
const write = (f, v) => writeJson(path.join(dir, f), v, atRest)
|
|
118
118
|
|
|
119
|
-
let link =
|
|
120
|
-
let state =
|
|
119
|
+
let link = read(LINK, null)
|
|
120
|
+
let state = read(STATE, null) || { seq: 0, acta: null, bundles: {} }
|
|
121
121
|
|
|
122
122
|
return {
|
|
123
123
|
get link () { return link },
|
|
124
124
|
get acta () { return state.acta },
|
|
125
125
|
get seq () { return state.seq },
|
|
126
|
-
setLink (v) { link = v;
|
|
126
|
+
setLink (v) { link = v; write(LINK, v) },
|
|
127
127
|
bundleFor (ns, devicePub) { return state.bundles[bundleKey(ns, devicePub)] || null },
|
|
128
128
|
get bundles () { return Object.keys(state.bundles).length },
|
|
129
129
|
/**
|
|
@@ -134,10 +134,10 @@ export function openReplicaStore (dir) {
|
|
|
134
134
|
*/
|
|
135
135
|
apply ({ seq, acta, bundles }) {
|
|
136
136
|
if (typeof seq !== 'number' || seq < state.seq) return false
|
|
137
|
-
const
|
|
138
|
-
for (const [k,
|
|
139
|
-
state = { seq, acta: acta || state.acta, bundles:
|
|
140
|
-
|
|
137
|
+
const mixed = { ...state.bundles }
|
|
138
|
+
for (const [k, newer] of Object.entries(bundles || {})) mixed[k] = mergeBundle(mixed[k], newer)
|
|
139
|
+
state = { seq, acta: acta || state.acta, bundles: mixed }
|
|
140
|
+
write(STATE, state)
|
|
141
141
|
return true
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -158,7 +158,7 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
158
158
|
const url = proxyUrl || link.proxy || process.env.PROXY_URL || 'wss://proxy.dotrino.com'
|
|
159
159
|
const id = await keyLabel(link.device.publickey)
|
|
160
160
|
|
|
161
|
-
const
|
|
161
|
+
const sign = (data) => signWithDevice({ privateJwk: link.device.privateJwk, data })
|
|
162
162
|
// CONTESTAR es por la CONEXIÓN (`send`) y no por la llave (`sendByPubkey`): `from` es el
|
|
163
163
|
// identificador de quien escribe en el proxio, no su pubkey. Mandar por llave a un `from`
|
|
164
164
|
// no falla — se va a la nada, y quien preguntó se queda esperando el plazo entero.
|
|
@@ -168,7 +168,7 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
168
168
|
const client = new WebSocketProxyClient({ url })
|
|
169
169
|
await client.connect()
|
|
170
170
|
// El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
|
|
171
|
-
await client.identifyAs({ publickey: link.device.publickey, sign: (d) =>
|
|
171
|
+
await client.identifyAs({ publickey: link.device.publickey, sign: (d) => sign(d) })
|
|
172
172
|
log(`[replica] ${id} · connected to ${url}`)
|
|
173
173
|
log(`[replica] record #${store.seq}${store.acta ? '' : ' · no record yet: waiting for the vault'}`)
|
|
174
174
|
|
|
@@ -197,7 +197,7 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
197
197
|
}
|
|
198
198
|
log(`[replica] record #${store.seq} · ${Object.keys(body.bundles || {}).length} bundle(s) stored`)
|
|
199
199
|
const ack = { op: 'replica.ack', publickey: link.device.publickey, seq: store.seq, ts: Date.now() }
|
|
200
|
-
client.send(from, { type: MSG.REPLICA_ACK, body: ack, signature: (await
|
|
200
|
+
client.send(from, { type: MSG.REPLICA_ACK, body: ack, signature: (await sign(ack)).signature })
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
/**
|
|
@@ -257,8 +257,8 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
257
257
|
log(`[replica] the record does not let ${(await pubkeyId(chk.device)).slice(0, 8)} read "${ns}": refused`)
|
|
258
258
|
return no(`unauthorized: cn — the record does not recognise this member as the "${ns}" service`)
|
|
259
259
|
}
|
|
260
|
-
const
|
|
261
|
-
const b = store.bundleFor(ns,
|
|
260
|
+
const who = chk.device
|
|
261
|
+
const b = store.bundleFor(ns, who)
|
|
262
262
|
if (!b) {
|
|
263
263
|
log(`[replica] asked for "${ns}" and has nothing stored for that device`)
|
|
264
264
|
return client.send(from, {
|
|
@@ -270,7 +270,7 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
270
270
|
const body = { op: 'secrets.result', ns, enc, ts: Date.now() }
|
|
271
271
|
// `by` y no `seq`: no tenemos la llave de sellado y no debemos tenerla. Quien recibe
|
|
272
272
|
// mira el acta, ve que a esta llave le reconoce `replica`, y acepta.
|
|
273
|
-
const { signature } = await
|
|
273
|
+
const { signature } = await sign(body)
|
|
274
274
|
client.send(from, { type: MSG.SECRETS_RESULT, body, seal: { by: link.device.publickey, sig: signature } })
|
|
275
275
|
log(`[replica] served "${ns}" from record #${store.seq}`)
|
|
276
276
|
}
|
|
@@ -295,9 +295,9 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, log = console.
|
|
|
295
295
|
// conexión: si la bóveda va por delante, contesta con un empujón. Sin esto, un
|
|
296
296
|
// replicador recién encendido se queda vacío hasta que alguien cambie algo — y el
|
|
297
297
|
// empujón del propio enrolamiento se manda cuando este proceso todavía no existe.
|
|
298
|
-
const
|
|
298
|
+
const greeting = { op: 'replica.ack', publickey: link.device.publickey, seq: store.seq, ts: Date.now() }
|
|
299
299
|
try {
|
|
300
|
-
client.sendByPubkey(link.iss, { type: MSG.REPLICA_ACK, body:
|
|
300
|
+
client.sendByPubkey(link.iss, { type: MSG.REPLICA_ACK, body: greeting, signature: (await sign(greeting)).signature })
|
|
301
301
|
} catch (e) { log('[replica] could not say hello to the vault: ' + e.message) }
|
|
302
302
|
|
|
303
303
|
log('[replica] ready · it hands out what the vault already signed, and nothing else')
|
package/src/selfupdate.js
CHANGED
|
@@ -62,15 +62,15 @@ export function shouldWatch (env = process.env, execPath = process.execPath) {
|
|
|
62
62
|
*/
|
|
63
63
|
export function watchBinary ({ log = console.log, exit = (c) => process.exit(c), env = process.env, execPath = process.execPath, checkMs = CHECK_MS } = {}) {
|
|
64
64
|
if (!shouldWatch(env, execPath)) return null
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const initial = fingerprint(execPath)
|
|
66
|
+
if (!initial) return null
|
|
67
67
|
|
|
68
|
-
let
|
|
68
|
+
let still = null // huella del candidato, para exigir que se repita
|
|
69
69
|
|
|
70
70
|
const t = setInterval(() => {
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
73
|
-
if (
|
|
71
|
+
const now = fingerprint(execPath)
|
|
72
|
+
if (!now || now === initial) { still = null; return }
|
|
73
|
+
if (still !== now) { still = now; return } // primera vez que se ve: esperar
|
|
74
74
|
clearInterval(t)
|
|
75
75
|
log('[vault] the binary changed on disk: restarting to run the new version')
|
|
76
76
|
// Se sale con 0 y limpiamente: systemd lo trata como una parada normal y vuelve a
|