@dotrino/vaultd 0.176.1 → 0.177.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/lib/src/core/libVersion.js +1 -1
- package/lib/src/core/vault.js +41 -15
- package/lib/src/service.js +68 -30
- package/package.json +2 -2
- package/src/replica.js +5 -2
package/lib/src/core/vault.js
CHANGED
|
@@ -464,20 +464,29 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
464
464
|
* Solo lo intenta el master —es el único que sella actas— y no bloquea el arranque: sin
|
|
465
465
|
* llave los sobres salen sin firma, que es lo que ya pasaba antes de §8.8.
|
|
466
466
|
*/
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
467
|
+
// CADA BÓVEDA, SU LLAVE (`docs/replicas.md` §11.5). Lo que se mira es la llave que el acta
|
|
468
|
+
// nombra para ESTA bóveda (su miembro), no la del acta: con dos bóvedas en la cuenta, la del
|
|
469
|
+
// acta la estrenó la última que selló, y mirar esa hacía que cada una se la quitara a la otra
|
|
470
|
+
// al abrirse. Se llama al arrancar y al abrir (`takeMasterKey`): un perfil con contraseña
|
|
471
|
+
// arranca cerrado siempre, y sin lo segundo no estrenaría la suya nunca.
|
|
472
|
+
async function ensureOwnSealKey () {
|
|
473
|
+
try {
|
|
474
|
+
const info = await identity.profileActa?.()
|
|
475
|
+
const acta = info?.acta
|
|
476
|
+
// CON EL PERFIL ABIERTO. Estrenar la llave de sellado SELLA EL ACTA, y una bóveda
|
|
477
|
+
// cerrada no sella nada. Cerrada se queda sin llave propia y lo que sirve lo firma con
|
|
478
|
+
// la del acta si es suya; si no, no sirve firmado hasta que se abra o una hermana se la
|
|
479
|
+
// nombre («presellar», op `sealkey`).
|
|
480
|
+
if (!info?.isMaster || !acta || isLocked()) return false
|
|
481
|
+
const mine = (acta.members || []).find((m) => m.pub === master)
|
|
482
|
+
if (mine?.sealPub && sealKeys.has(mine.sealPub)) return false
|
|
475
483
|
const r = await identity.rotateSealKey()
|
|
476
484
|
// Sin `%s`: este `log` va con un prefijo por delante, así que el formato no es lo
|
|
477
485
|
// primero y `console.log` no lo sustituye (salía «record #%s 2»).
|
|
478
|
-
log(`[vault] new sealing key in record #${r.seq}`)
|
|
479
|
-
|
|
480
|
-
|
|
486
|
+
log(`[vault] new sealing key for this vault in record #${r.seq}`)
|
|
487
|
+
return true
|
|
488
|
+
} catch (e) { log('[vault] could not set up the sealing key:', e.message); return false }
|
|
489
|
+
}
|
|
481
490
|
|
|
482
491
|
/**
|
|
483
492
|
* LA LLAVE DE COMUNICACIÓN, dentro del acta.
|
|
@@ -549,6 +558,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
549
558
|
}
|
|
550
559
|
// Lo que se selló aquí se anuncia cuando ya hay transporte (más abajo): sin el aviso, la otra
|
|
551
560
|
// bóveda de la cuenta no se entera y las dos acaban con actas distintas del mismo número.
|
|
561
|
+
await ensureOwnSealKey()
|
|
552
562
|
const commSealedAtStart = await ensureCommKeyInActa()
|
|
553
563
|
|
|
554
564
|
// `announce`: el canal de ESTA cuenta, para que una máquina prestada —que no tiene
|
|
@@ -2381,8 +2391,12 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
2381
2391
|
// El socket se nombra por la LLAVE de esta bóveda: una máquina puede tener varias, y un
|
|
2382
2392
|
// servicio solo conoce la maestra que lleva pineada. Así los dos lados calculan la misma
|
|
2383
2393
|
// ruta sin mirar ningún índice.
|
|
2394
|
+
// Se guarda para CERRARLO con la bóveda: abierto tras `close()`, un servicio de esta máquina
|
|
2395
|
+
// seguía entrando por aquí (es el camino más directo) y le contestaba una identidad ya
|
|
2396
|
+
// destruida («Identity not ready»), en vez de salir por el proxio a otra bóveda de la cuenta.
|
|
2397
|
+
let localDesk = null
|
|
2384
2398
|
if (identity.me?.publickey && typeof platform.openLocalDesk === 'function') {
|
|
2385
|
-
platform.openLocalDesk({
|
|
2399
|
+
localDesk = platform.openLocalDesk({
|
|
2386
2400
|
name: (await pubkeyId(identity.me.publickey)).slice(0, 16),
|
|
2387
2401
|
onMessage, channels: channels, maxBytes: MAX_REPLY_BYTES, log
|
|
2388
2402
|
})
|
|
@@ -3419,9 +3433,19 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
3419
3433
|
async function signSeal (body) {
|
|
3420
3434
|
try {
|
|
3421
3435
|
const acta = (await identity.profileActa?.().catch(() => null))?.acta
|
|
3422
|
-
if (!acta
|
|
3423
|
-
|
|
3424
|
-
|
|
3436
|
+
if (!acta) return null
|
|
3437
|
+
// LA DEL ACTA, SI ES NUESTRA: es la que sabe verificar un agente de antes de §11.5.
|
|
3438
|
+
if (acta.sealPub && sealKeys.has(acta.sealPub)) {
|
|
3439
|
+
const sig = await sealKeys.sign(acta.sealPub, body)
|
|
3440
|
+
if (sig) return { seq: acta.seq, sig }
|
|
3441
|
+
}
|
|
3442
|
+
// LA DE ESTA BÓVEDA (`docs/replicas.md` §11.5): la firma dice de cuál es (`vault`), y quien
|
|
3443
|
+
// verifica busca la llave de esa bóveda en el acta. Así sirve también la bóveda que no
|
|
3444
|
+
// selló la última acta.
|
|
3445
|
+
const mine = (acta.members || []).find((m) => m.pub === master)
|
|
3446
|
+
if (!mine?.sealPub || !sealKeys.has(mine.sealPub)) return null
|
|
3447
|
+
const sig = await sealKeys.sign(mine.sealPub, body)
|
|
3448
|
+
return sig ? { seq: acta.seq, sig, vault: master } : null
|
|
3425
3449
|
} catch (_) { return null }
|
|
3426
3450
|
}
|
|
3427
3451
|
|
|
@@ -4480,6 +4504,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
4480
4504
|
try {
|
|
4481
4505
|
if (await ensureCommKeyInActa()) { await reidentify?.(); await notifyMembers('commkey') }
|
|
4482
4506
|
} catch (_) {}
|
|
4507
|
+
await ensureOwnSealKey()
|
|
4483
4508
|
await syncExNotices()
|
|
4484
4509
|
}
|
|
4485
4510
|
// Y ABSORBER LO PENDIENTE. La subacta ya lo estaba honrando con el perfil cerrado —de
|
|
@@ -4808,6 +4833,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
4808
4833
|
for (const t of pendingNotices.values()) clearTimeout(t)
|
|
4809
4834
|
pendingNotices.clear()
|
|
4810
4835
|
closeTransport()
|
|
4836
|
+
try { localDesk?.close?.() } catch (_) {}
|
|
4811
4837
|
try { client.close() } catch (_) {} identity.destroy()
|
|
4812
4838
|
}
|
|
4813
4839
|
}
|
package/lib/src/service.js
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
makeDeviceKey, makeDeviceEncKey, importDeviceEncKey, signWithDevice,
|
|
26
26
|
verifyDeviceSig, makePairingCode, commitCode, pubkeyId, keyLabel } from '@dotrino/identity/capabilities'
|
|
27
27
|
import { openWrap, wrapForMember, decryptWithCek } from '@dotrino/identity/content'
|
|
28
|
-
import { verifyActa, sealKeyAt, memberCan, checkVaultReply, accountMismatch } from '@dotrino/identity/acta'
|
|
28
|
+
import { verifyActa, sealKeyAt, sealersOf, memberCan, checkVaultReply, accountMismatch } from '@dotrino/identity/acta'
|
|
29
29
|
import { MSG, secretsScope, isValidSecretsNs, VAULT_PROTOCOL, VAULT_SPEAKS } from './protocol.js'
|
|
30
30
|
import { PKG_VERSION } from './version.js'
|
|
31
31
|
import { makeEphemeralKey, openSealed } from './sealed.js'
|
|
@@ -236,9 +236,9 @@ function waitForMsg (client, predicate, timeoutMs = 30000, guard = null) {
|
|
|
236
236
|
export const requestRef = (signature) => createHash('sha256').update(String(signature || '')).digest('hex')
|
|
237
237
|
|
|
238
238
|
/** ¿Este error lo firmó una llave de sellado del acta, y es para esta petición? */
|
|
239
|
-
export async function isMyVaultError (p, { re, masterPubkey, knownSeq = null }) {
|
|
239
|
+
export async function isMyVaultError (p, { re, masterPubkey, knownSeq = null, knownSealers = null }) {
|
|
240
240
|
if (!p?.signed || p.signed.re !== re || p.signed.op !== 'secrets.error' || p.signed.error !== p.error) return false
|
|
241
|
-
try { await verifyResponder({ body: p.signed, seal: p.seal, acta: p.acta, masterPubkey, knownSeq }); return true } catch (_) { return false }
|
|
241
|
+
try { await verifyResponder({ body: p.signed, seal: p.seal, acta: p.acta, masterPubkey, knownSeq, knownSealers }); return true } catch (_) { return false }
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
const identityFileOf = (dir) => path.join(dir, IDENTITY_FILE)
|
|
@@ -555,7 +555,7 @@ export async function registerEncKey ({ dir, ns, proxyUrl, masterPubkey, device,
|
|
|
555
555
|
await identifyAsService(client, device)
|
|
556
556
|
const data = { op: 'enckey', ns, encPub, publickey: device.publickey, ts: Date.now() }
|
|
557
557
|
const { signature } = await signWithDevice({ privateJwk: device.privateJwk, data })
|
|
558
|
-
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
558
|
+
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
559
559
|
client.sendByPubkey(masterPubkey, { type: MSG.SECRETS, data, signature, cert })
|
|
560
560
|
const res = await pending
|
|
561
561
|
if (res.type === MSG.ERROR) throw vaultError(res)
|
|
@@ -607,11 +607,11 @@ export async function storeVars ({ dir, ns, proxyUrl, masterPubkey, device, cert
|
|
|
607
607
|
const ask = async (data) => {
|
|
608
608
|
const signed = { ...data, ns, publickey: device.publickey, ts: Date.now() }
|
|
609
609
|
const { signature } = await signWithDevice({ privateJwk: device.privateJwk, data: signed })
|
|
610
|
-
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
610
|
+
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
611
611
|
client.sendByPubkey(masterPubkey, { type: MSG.SECRETS, data: signed, signature, cert })
|
|
612
612
|
const res = await pending
|
|
613
613
|
if (res.type === MSG.ERROR) throw vaultError(res)
|
|
614
|
-
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
614
|
+
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
615
615
|
if (res.body?.op !== data.op.replace(/^store$/, 'store.result') || res.body?.ns !== ns) throw new Error('the vault answered something else')
|
|
616
616
|
return res.body
|
|
617
617
|
}
|
|
@@ -661,11 +661,11 @@ export async function fetchDigest ({ dir, ns, proxyUrl, masterPubkey, device, ce
|
|
|
661
661
|
await identifyAsService(client, device)
|
|
662
662
|
const data = { op: 'digest', ns, publickey: device.publickey, ts: Date.now() }
|
|
663
663
|
const { signature } = await signWithDevice({ privateJwk: device.privateJwk, data })
|
|
664
|
-
const pending = waitForMsg(client, (p) => p.type === MSG.ERROR || (p.type === MSG.SECRETS_RESULT && p.body?.op === 'secrets.digest'), timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
664
|
+
const pending = waitForMsg(client, (p) => p.type === MSG.ERROR || (p.type === MSG.SECRETS_RESULT && p.body?.op === 'secrets.digest'), timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
665
665
|
client.sendByPubkey(masterPubkey, { type: MSG.SECRETS, data, signature, cert })
|
|
666
666
|
const res = await pending
|
|
667
667
|
if (res.type === MSG.ERROR) throw vaultError(res)
|
|
668
|
-
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
668
|
+
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
669
669
|
if (res.body.ns !== ns || typeof res.body.digest !== 'string') throw new Error('malformed digest reply')
|
|
670
670
|
if (typeof res.body.ts !== 'number' || Math.abs(Date.now() - res.body.ts) > FRESH_WINDOW_MS) throw new Error('stale digest reply')
|
|
671
671
|
return res.body.digest
|
|
@@ -716,7 +716,7 @@ export async function askUpdateApproval ({ product, version, from = null, dir, p
|
|
|
716
716
|
const mine = (p) => p.type === MSG.ERROR || (p.type === MSG.SECRETS_RESULT && p.body?.op === 'update-ask' && p.body.product === product && p.body.version === version)
|
|
717
717
|
const check = async (res) => {
|
|
718
718
|
if (res.type === MSG.ERROR) throw vaultError(res)
|
|
719
|
-
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
719
|
+
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
720
720
|
if (typeof res.body.ts !== 'number' || Math.abs(Date.now() - res.body.ts) > FRESH_WINDOW_MS) throw new Error('stale update-ask reply')
|
|
721
721
|
return res.body
|
|
722
722
|
}
|
|
@@ -826,14 +826,14 @@ async function reportToVault (op, { product, version, from = null, dir, proxyUrl
|
|
|
826
826
|
await identifyAsService(client, device)
|
|
827
827
|
const data = { op, product, version, ...(typeof from === 'string' && from ? { from } : {}), publickey: device.publickey, ts: Date.now() }
|
|
828
828
|
const { signature } = await signWithDevice({ privateJwk: device.privateJwk, data })
|
|
829
|
-
const pending = waitForMsg(client, (p) => p.type === MSG.ERROR || (p.type === MSG.SECRETS_RESULT && p.body?.op === op && p.body.product === product && p.body.version === version), timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
829
|
+
const pending = waitForMsg(client, (p) => p.type === MSG.ERROR || (p.type === MSG.SECRETS_RESULT && p.body?.op === op && p.body.product === product && p.body.version === version), timeoutMs, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
830
830
|
client.sendByPubkey(masterPubkey, { type: MSG.SECRETS, data, signature, cert })
|
|
831
831
|
const res = await pending.catch((e) => {
|
|
832
832
|
if (/timeout/.test(e.message)) throw Object.assign(new Error(`${op}: the vault did not answer`), { code: 'vault-no-reply' })
|
|
833
833
|
throw e
|
|
834
834
|
})
|
|
835
835
|
if (res.type === MSG.ERROR) throw vaultError(res)
|
|
836
|
-
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
836
|
+
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
837
837
|
if (res.body.ok !== true) throw new Error(`malformed ${op} reply`)
|
|
838
838
|
return { ok: true }
|
|
839
839
|
} finally { client.close() }
|
|
@@ -894,12 +894,16 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
|
|
|
894
894
|
*/
|
|
895
895
|
const recordActa = (acta) => {
|
|
896
896
|
if (typeof acta?.seq !== 'number') return
|
|
897
|
+
// Quién puede sellar según esta acta, que ya se aceptó: con eso se acepta la siguiente
|
|
898
|
+
// aunque la selle otra bóveda de la cuenta (`verifyResponder`). La primera vez se guarda
|
|
899
|
+
// también con el mismo `seq`, porque un agente de antes no lo tenía.
|
|
900
|
+
if (typeof saved?.actaSeq === 'number' && acta.seq === saved.actaSeq && !Array.isArray(saved.sealers)) remember({ sealers: sealersOf(acta) })
|
|
897
901
|
if (typeof saved?.actaSeq === 'number' && acta.seq <= saved.actaSeq) return
|
|
898
902
|
// Y QUIÉNES REPARTEN. Sale del acta, que llega firmada en cada respuesta, así que no
|
|
899
903
|
// hay una lista que mantener a mano ni un `.env` que se olvide: darle `replica` a un
|
|
900
904
|
// aparato basta para que sus servicios sepan preguntarle cuando la bóveda no esté.
|
|
901
905
|
const replicas = (acta.members || []).filter((m) => memberCan(acta, m.pub, 'replica')).map((m) => m.pub)
|
|
902
|
-
remember({ actaSeq: acta.seq, replicas })
|
|
906
|
+
remember({ actaSeq: acta.seq, replicas, sealers: sealersOf(acta) })
|
|
903
907
|
}
|
|
904
908
|
|
|
905
909
|
// DOS MOTIVOS PARA PEDIR PAPEL NUEVO:
|
|
@@ -978,7 +982,7 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
|
|
|
978
982
|
let res = null
|
|
979
983
|
let last = null
|
|
980
984
|
for (const target of targets) {
|
|
981
|
-
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, byTarget, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
985
|
+
const pending = waitForMsg(client, (p) => p.type === MSG.SECRETS_RESULT || p.type === MSG.ERROR, byTarget, { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
982
986
|
client.sendByPubkey(target, { type: MSG.SECRETS, data, signature, cert })
|
|
983
987
|
try { res = await pending; break } catch (e) { last = e }
|
|
984
988
|
}
|
|
@@ -989,11 +993,11 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
|
|
|
989
993
|
// verdad llega cuando el aparato que aprueba firme — por esta misma conexión, que
|
|
990
994
|
// sigue identificada. Se espera lo que dura el pedido; denegado o vencido es error.
|
|
991
995
|
if (res.body?.op === 'secrets.pending' && res.body.ns === ns) {
|
|
992
|
-
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
996
|
+
await verifyResponder({ body: res.body, seal: res.seal, acta: res.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
993
997
|
recordActa(res.acta)
|
|
994
998
|
try { onPending?.({ id: res.body.id, ns, exp: res.body.exp }) } catch (_) {}
|
|
995
999
|
const until = typeof res.body.exp === 'number' ? Math.max(5000, res.body.exp - Date.now() + 5000) : approvalTimeoutMs
|
|
996
|
-
res = await waitForMsg(client, (p) => (p.type === MSG.SECRETS_RESULT && p.body?.op === 'secrets.result') || p.type === MSG.ERROR, Math.min(until, approvalTimeoutMs), { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
1000
|
+
res = await waitForMsg(client, (p) => (p.type === MSG.SECRETS_RESULT && p.body?.op === 'secrets.result') || p.type === MSG.ERROR, Math.min(until, approvalTimeoutMs), { re: requestRef(signature), masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
997
1001
|
.catch((e) => {
|
|
998
1002
|
if (/timeout/.test(e.message)) throw Object.assign(new Error('approval: nobody approved the request in time'), { code: 'unanswered' })
|
|
999
1003
|
throw e
|
|
@@ -1014,7 +1018,7 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
|
|
|
1014
1018
|
// confía en nadie — solo saca el acta con la que SÍ se comprueba. Nada de lo que hay
|
|
1015
1019
|
// dentro se usa hasta después de verificar.
|
|
1016
1020
|
const payload = await openSealed({ privateKey: eph.privateKey, enc: body.enc })
|
|
1017
|
-
await verifyResponder({ body, seal: res.seal, acta: payload?.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null })
|
|
1021
|
+
await verifyResponder({ body, seal: res.seal, acta: payload?.acta, masterPubkey, knownSeq: saved?.actaSeq ?? null, knownSealers: saved?.sealers ?? null })
|
|
1018
1022
|
recordActa(payload?.acta)
|
|
1019
1023
|
// La huella de lo que se acaba de recibir: con ella se compara después (`fetchDigest`)
|
|
1020
1024
|
// sin volver a pedir claves. Ya comprobada: va dentro del cuerpo firmado.
|
|
@@ -1085,13 +1089,40 @@ export async function fetchSecrets ({ dir, ns, proxyUrl, masterPubkey, device, c
|
|
|
1085
1089
|
* @param {number|null} [knownSeq] El `seq` más alto que este agente ya vio de esta cuenta.
|
|
1086
1090
|
* `null`/ausente = no conoce la cuenta, y entonces un replicador no vale.
|
|
1087
1091
|
*/
|
|
1088
|
-
|
|
1092
|
+
/**
|
|
1093
|
+
* A QUIÉN LE PUEDE ENVOLVER UN SERVICIO LA LLAVE DE SU CAJÓN, cuando la bóveda se lo pide
|
|
1094
|
+
* (`rewrap`). Solo de SU cajón —eso lo mira quien llama—, y solo a dos tipos de miembro:
|
|
1095
|
+
*
|
|
1096
|
+
* · los de ese cajón (`cn === ns`): un hermano del servicio;
|
|
1097
|
+
* · las BÓVEDAS de la cuenta (las que el acta deja sellar). Son clones y tienen que tener
|
|
1098
|
+
* todos los cajones (dueño, 2026-10-26: «el sellado delegado verificarás que un
|
|
1099
|
+
* dispositivo sella para las bóvedas existentes» y «si sella de su propio cajón pero para
|
|
1100
|
+
* todas las bóvedas, entendería»). Sin esto, una bóveda nueva se quedaba para siempre sin
|
|
1101
|
+
* el cajón cuya llave solo tiene el servicio.
|
|
1102
|
+
*
|
|
1103
|
+
* Cualquier otro aparato, no: un servicio no amplía el acceso a lo suyo. Y la llave pública
|
|
1104
|
+
* sale del ACTA, nunca del mensaje.
|
|
1105
|
+
*
|
|
1106
|
+
* @returns {{ ok: true, member: object } | { ok: false, why: string }}
|
|
1107
|
+
*/
|
|
1108
|
+
export function rewrapTarget (acta, targetPub, ns) {
|
|
1109
|
+
const member = (acta?.members || []).find((m) => m.pub === targetPub)
|
|
1110
|
+
if (!member?.encPub) return { ok: false, why: 'is not in the record (or has no encryption key)' }
|
|
1111
|
+
if (member.cn === ns || memberCan(acta, member.pub, 'sealer')) return { ok: true, member }
|
|
1112
|
+
return { ok: false, why: `is neither part of «${ns}» nor a vault of the account` }
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
export async function verifyResponder ({ body, seal, acta, masterPubkey, knownSeq = null, knownSealers = null }) {
|
|
1089
1116
|
if (!seal?.sig) {
|
|
1090
1117
|
throw new Error('the reply carries no sealing signature: this vault is too old to serve (update it)')
|
|
1091
1118
|
}
|
|
1092
1119
|
if (!acta) throw new Error('the reply carries no record: cannot tell which key was allowed to sign it')
|
|
1093
|
-
|
|
1094
|
-
|
|
1120
|
+
// LAS DOS SON MAESTRA (`docs/replicas.md` §11.5): el acta la puede haber sellado cualquier
|
|
1121
|
+
// bóveda de la cuenta. Vale la maestra que este agente conoce, o una a la que el acta que YA
|
|
1122
|
+
// aceptó le dejaba sellar (`knownSealers`, ver `recordActa`): es la cadena de selladoras,
|
|
1123
|
+
// comprobada paso a paso. Una que nunca vio no vale, aunque el acta diga que sella.
|
|
1124
|
+
if (acta.sealedBy !== masterPubkey && !(Array.isArray(knownSealers) && knownSealers.includes(acta.sealedBy))) {
|
|
1125
|
+
throw new Error('the record was not sealed by a vault this agent knows: refusing the reply')
|
|
1095
1126
|
}
|
|
1096
1127
|
if (!(await verifyActa({ acta })).ok) throw new Error('the record does not verify')
|
|
1097
1128
|
|
|
@@ -1121,7 +1152,8 @@ export async function verifyResponder ({ body, seal, acta, masterPubkey, knownSe
|
|
|
1121
1152
|
if (typeof seal.seq !== 'number') {
|
|
1122
1153
|
throw new Error('the reply carries no sealing signature: this vault is too old to serve (update it)')
|
|
1123
1154
|
}
|
|
1124
|
-
|
|
1155
|
+
// `seal.vault`: la firmó la llave de sellado de UNA bóveda, la que el acta nombra para ella.
|
|
1156
|
+
const pub = sealKeyAt(acta, seal.seq, seal.vault ?? null)
|
|
1125
1157
|
if (!pub) throw new Error(`the record names no sealing key for #${seal.seq}`)
|
|
1126
1158
|
if (!(await verifyDeviceSig({ publickey: pub, data: body, signature: seal.sig }))) {
|
|
1127
1159
|
throw new Error('the reply signature does not check out against the key the record names')
|
|
@@ -1141,12 +1173,14 @@ export async function verifyResponder ({ body, seal, acta, masterPubkey, knownSe
|
|
|
1141
1173
|
* cazar. Un sobre SIN firma se acepta y se avisa: los hay de antes de que esto existiera
|
|
1142
1174
|
* y negarse a arrancar por eso apagaría servicios que llevan meses bien.
|
|
1143
1175
|
*/
|
|
1144
|
-
export async function makeSealCheck (acta, masterPubkey, log = console.log) {
|
|
1176
|
+
export async function makeSealCheck (acta, masterPubkey, log = console.log, knownSealers = null) {
|
|
1145
1177
|
if (!acta) return () => {}
|
|
1146
1178
|
// El acta tiene que venir firmada por la maestra que este agente ya conoce. Si la
|
|
1147
1179
|
// selló otro (un traspaso que este agente no ha visto), no se puede establecer
|
|
1148
1180
|
// procedencia: se dice y se sigue, en vez de fingir que se comprobó.
|
|
1149
|
-
|
|
1181
|
+
// O una bóveda que el acta ya aceptada dejaba sellar (`docs/replicas.md` §11.5).
|
|
1182
|
+
const known = acta.sealedBy === masterPubkey || (Array.isArray(knownSealers) && knownSealers.includes(acta.sealedBy))
|
|
1183
|
+
const ok = known && (await verifyActa({ acta })).ok
|
|
1150
1184
|
if (!ok) {
|
|
1151
1185
|
log('[vault] ⚠ the record does not come from the master this agent knows: envelope provenance NOT checked')
|
|
1152
1186
|
return () => {}
|
|
@@ -1157,7 +1191,7 @@ export async function makeSealCheck (acta, masterPubkey, log = console.log) {
|
|
|
1157
1191
|
if (!warned) { warned = true; log('[vault] ⚠ some envelopes carry no signature (sealed before this vault could sign)') }
|
|
1158
1192
|
return
|
|
1159
1193
|
}
|
|
1160
|
-
const pub = sealKeyAt(acta, seal.seq)
|
|
1194
|
+
const pub = sealKeyAt(acta, seal.seq, seal.vault ?? null)
|
|
1161
1195
|
if (!pub) throw new Error(`${key}: the record has no sealing key for #${seal.seq} (the envelope claims a record that does not exist)`)
|
|
1162
1196
|
const good = await verifyDeviceSig({ publickey: pub, data: { owner, key, gen, iv: e.iv, ct: e.ct }, signature: seal.sig })
|
|
1163
1197
|
if (!good) throw new Error(`${key}: the envelope signature does not check out — it did not come from this vault`)
|
|
@@ -1192,7 +1226,7 @@ async function openSealedBundle (sealed, ident, acta = null, masterPubkey = null
|
|
|
1192
1226
|
return cek
|
|
1193
1227
|
}
|
|
1194
1228
|
|
|
1195
|
-
const checkSignature = await makeSealCheck(acta, masterPubkey)
|
|
1229
|
+
const checkSignature = await makeSealCheck(acta, masterPubkey, undefined, ident?.sealers ?? null)
|
|
1196
1230
|
|
|
1197
1231
|
const out = {}
|
|
1198
1232
|
for (const [key, e] of Object.entries(sealed.entries || {})) {
|
|
@@ -1371,15 +1405,19 @@ export async function watchSecretsChanges ({
|
|
|
1371
1405
|
const mineOwners = [`ns:${ns}`, `dev:${saved.device.publickey}`]
|
|
1372
1406
|
if (!mineOwners.includes(body.owner)) return log('[vault] rewrap for a drawer that is not mine: ignored')
|
|
1373
1407
|
try {
|
|
1374
|
-
await verifyResponder({ body, seal: payload.seal, acta: body.acta, masterPubkey: master, knownSeq: readServiceIdentity(dir)?.actaSeq ?? null })
|
|
1408
|
+
await verifyResponder({ body, seal: payload.seal, acta: body.acta, masterPubkey: master, knownSeq: readServiceIdentity(dir)?.actaSeq ?? null, knownSealers: readServiceIdentity(dir)?.sealers ?? null })
|
|
1375
1409
|
} catch (e) { return log(`[vault] rewrap request BADLY SIGNED: ignored (${e.message})`) }
|
|
1376
1410
|
const acta = body.acta
|
|
1377
|
-
|
|
1411
|
+
// La puede haber sellado cualquier bóveda de la cuenta que este agente ya conoce
|
|
1412
|
+
// (`docs/replicas.md` §11.5), igual que en `verifyResponder`.
|
|
1413
|
+
const sealers = readServiceIdentity(dir)?.sealers
|
|
1414
|
+
const knownSealer = acta && (acta.sealedBy === master || (Array.isArray(sealers) && sealers.includes(acta.sealedBy)))
|
|
1415
|
+
if (!acta || !knownSealer || !(await verifyActa({ acta })).ok) {
|
|
1378
1416
|
return log('[vault] rewrap request without a valid record: ignored')
|
|
1379
1417
|
}
|
|
1380
|
-
const
|
|
1381
|
-
if (!
|
|
1382
|
-
|
|
1418
|
+
const allowed = rewrapTarget(acta, body.target, ns)
|
|
1419
|
+
if (!allowed.ok) return log(`[vault] rewrap: ${String(body.target).slice(0, 12)}… ${allowed.why}: refused`)
|
|
1420
|
+
const target = allowed.member
|
|
1383
1421
|
|
|
1384
1422
|
try {
|
|
1385
1423
|
const ident = readServiceIdentity(dir)
|
|
@@ -1418,7 +1456,7 @@ export async function watchSecretsChanges ({
|
|
|
1418
1456
|
// (la maestra solo firma el acta y reenvuelve sobres, CLAUDE.md).
|
|
1419
1457
|
let bad = null
|
|
1420
1458
|
try {
|
|
1421
|
-
await verifyResponder({ body, seal: payload.seal, acta: payload.acta, masterPubkey: master, knownSeq: readServiceIdentity(dir)?.actaSeq ?? null })
|
|
1459
|
+
await verifyResponder({ body, seal: payload.seal, acta: payload.acta, masterPubkey: master, knownSeq: readServiceIdentity(dir)?.actaSeq ?? null, knownSealers: readServiceIdentity(dir)?.sealers ?? null })
|
|
1422
1460
|
} catch (e) { bad = e } finally { inFlight.delete(body.ts) }
|
|
1423
1461
|
if (bad) return log(`[vault] change notice BADLY SIGNED: ignored (${bad.message})`)
|
|
1424
1462
|
if (body.ts <= lastTs) return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.177.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Certificador personal de Dotrino: daemon headless que custodia la clave maestra y delega capacidades a tus dispositivos por el proxy. Tu CA propia.",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@dotrino/compat": "0.4.0",
|
|
25
|
-
"@dotrino/identity": "0.
|
|
25
|
+
"@dotrino/identity": "0.128.0",
|
|
26
26
|
"@dotrino/opaque": "0.1.0",
|
|
27
27
|
"@dotrino/passmanager": "0.18.6",
|
|
28
28
|
"@dotrino/proxy-client": "^0.45.0",
|
package/src/replica.js
CHANGED
|
@@ -198,9 +198,12 @@ export async function runReplica ({ dir = replicaDir(), proxyUrl, wakeUrl = null
|
|
|
198
198
|
if (!body || body.op !== 'replica.push') return
|
|
199
199
|
const acta = body.acta || store.acta
|
|
200
200
|
if (!acta) return log('[replica] a push arrived with no record and none is stored: ignored')
|
|
201
|
-
|
|
201
|
+
// LAS DOS SON MAESTRA (`docs/replicas.md` §11.5): vale la que enroló a este replicador o una
|
|
202
|
+
// bóveda a la que el acta que ya guarda le dejaba sellar.
|
|
203
|
+
const known = acta.sealedBy === link.iss || (store.acta && sealersOf(store.acta).includes(acta.sealedBy))
|
|
204
|
+
if (!known) return log('[replica] the pushed record was sealed by a vault this replica does not know: ignored')
|
|
202
205
|
if (!(await verifyActa({ acta })).ok) return log('[replica] the pushed record does not verify: ignored')
|
|
203
|
-
const pub = sealKeyAt(acta, p.seal?.seq)
|
|
206
|
+
const pub = sealKeyAt(acta, p.seal?.seq, p.seal?.vault ?? null)
|
|
204
207
|
if (!pub || !(await verifyDeviceSig({ publickey: pub, data: body, signature: p.seal?.sig }))) {
|
|
205
208
|
return log('[replica] the push is not signed by the key the record names: ignored')
|
|
206
209
|
}
|