@dotrino/vaultd 0.189.1 → 0.190.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.
@@ -5,4 +5,4 @@
5
5
  * si no coincide con la del paquete: una versión anunciada que no es la que corre es peor
6
6
  * que no anunciar ninguna.
7
7
  */
8
- export const LIB_VERSION = '0.117.0'
8
+ export const LIB_VERSION = '0.118.0'
@@ -22,7 +22,14 @@ export const NOTICE_TTL_MS = 24 * 60 * 60 * 1000
22
22
  * (`docs/pairing-protocol.md` §1.7). No pide nada: no hay a quién bloquear, porque ninguno
23
23
  * entró. Lo cuenta, con el ID y la máquina de los dos.
24
24
  */
25
- export const NOTICE_EVS = ['updated', 'update-needs-root', 'pairing-contested', 'log-anchor']
25
+ export const NOTICE_EVS = ['updated', 'update-needs-root', 'pairing-contested', 'log-anchor', 'delivered']
26
+ /**
27
+ * `delivered`: un aparato con `unattended` se llevó claves de un cajón (`kind: 'secrets'`) o
28
+ * una contraseña (`kind: 'passwords'`) sin que nadie aprobara, porque no le hacía falta (dueño,
29
+ * 2026-11-04: «equipos unattended no deben pedir aprobación, quizás sí notificar que han
30
+ * entregado contraseñas»). No pide nada: lo cuenta. Lleva `ns`, `deviceId` y `label`.
31
+ */
32
+ const DELIVERED_KINDS = ['secrets', 'passwords']
26
33
 
27
34
  const newId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((b) => b.toString(16).padStart(2, '0')).join('')
28
35
 
@@ -58,8 +65,17 @@ export function openNotices ({ disk, now = Date.now }) {
58
65
  * administrador). `product`: qué (`@dotrino/vaultd` es la propia bóveda);
59
66
  * `deviceId`/`label`: el aparato, si fue uno.
60
67
  */
61
- add (ev, { version, from = null, product = '@dotrino/vaultd', deviceId = null, label = null, devices = null, logSeq = null, head = null, tsa = null }) {
68
+ add (ev, { version, from = null, product = '@dotrino/vaultd', deviceId = null, label = null, devices = null, logSeq = null, head = null, tsa = null, ns = null, kind = null }) {
62
69
  if (!NOTICE_EVS.includes(ev)) throw fail('bad-notice', `unknown notice: ${ev}`)
70
+ if (ev === 'delivered') {
71
+ if (!DELIVERED_KINDS.includes(kind)) throw fail('bad-notice', `${ev}: kind must be one of ${DELIVERED_KINDS.join(', ')}`)
72
+ if (typeof ns !== 'string' || !ns) throw fail('bad-notice', `${ev}: the drawer (ns) is required`)
73
+ if (typeof deviceId !== 'string' || !deviceId) throw fail('bad-notice', `${ev}: the device is required`)
74
+ const n = { id: newId(), ev, kind, ns, deviceId, label: typeof label === 'string' ? label : '', ts: now() }
75
+ items = [...items.filter(alive), n]
76
+ save()
77
+ return n
78
+ }
63
79
  // EL ANCLA DE LA BITÁCORA (`logAnchor.js`): la cabeza sellada por el signer, para que el
64
80
  // aprobador la guarde. Solo se queda la última: la anterior ya no dice nada que esta no diga.
65
81
  if (ev === 'log-anchor') {
@@ -36,6 +36,7 @@ export const PASSWORDS_CAP = 'passwords'
36
36
  * `encPubOf(pubkey)` su llave de cifrado, para sellarle la respuesta
37
37
  * `needsApproval(pubkey)` (async) si ese aparato tiene que pedir aprobación (`unattended`)
38
38
  * `approve({ pubkey, op })` pide el visto bueno (el teléfono) y espera
39
+ * `onDelivered(pubkey)` se sirvió una lectura (`pm2.get`) a ese aparato
39
40
  * `audit(op, info)` la bitácora del vault
40
41
  */
41
42
  export function createPasswordDesk (opts = {}) {
@@ -48,6 +49,7 @@ export function createPasswordDesk (opts = {}) {
48
49
  encPubOf = () => null,
49
50
  needsApproval = () => true,
50
51
  approve = async () => false,
52
+ onDelivered = () => {},
51
53
  audit = () => {},
52
54
  log = () => {},
53
55
  } = opts
@@ -73,6 +75,8 @@ export function createPasswordDesk (opts = {}) {
73
75
  // La bitácora NO lleva qué credencial se pidió: eso es contenido del usuario.
74
76
  audit('passwords', { op: r.op, outcome: r.outcome, device: (r.from || '').slice(0, 24) })
75
77
  if (r.outcome !== 'ok') log(`[vault] passwords: ${r.op} ${r.outcome}`)
78
+ // Una LECTURA servida: quien llama decide si hay que contarla (`unattended`, ver vault.js).
79
+ else if (r.op === 'pm2.get' && r.from) onDelivered(r.from)
76
80
  },
77
81
  })
78
82
 
@@ -2036,6 +2036,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2036
2036
  }
2037
2037
  audit('secrets', { device: await deviceIdOf(chk.device), ns, ...(publicOnly ? { publicOnly: true } : {}) })
2038
2038
  reply(from, { type: MSG.SECRETS_RESULT, ...res })
2039
+ if (!publicOnly) announceDelivered({ device: chk.device, ns, kind: 'secrets' })
2039
2040
  }
2040
2041
 
2041
2042
  /** El bundle de `ns` para `devicePub`, sellado a su `ek` y firmado por la llave de sellado. */
@@ -2249,6 +2250,42 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2249
2250
  * en vez de mandárselo en claro «para que al menos lo vea»: eso sería cambiar la promesa
2250
2251
  * por comodidad, y encima sin avisar a nadie.
2251
2252
  */
2253
+ /** Un objeto pequeño sellado a un `encPub` del acta: `{ wrap, envelope }`, lo abre `openSealed`. */
2254
+ async function sealTo (encPub, obj) {
2255
+ const cek = await makeContentKey()
2256
+ const envelope = await encryptWithCek({ cek, gen: 0, plaintext: JSON.stringify(obj) })
2257
+ const wrap = await wrapForMember({ cek, memberEncPub: encPub })
2258
+ return { wrap, envelope }
2259
+ }
2260
+
2261
+ /**
2262
+ * EL ASUNTO DEL TIMBRE, SELLADO AL TELÉFONO (dueño, 2026-11-04: «que las notificaciones a
2263
+ * móviles no sean del todo anónimas sino que al menos tengan asunto, para ver quién solicita
2264
+ * qué»). El timbre que sale por FCM/APNs lo leen Google y Apple, así que el proxio lo manda
2265
+ * vacío. Lo que va aquí viaja dentro del mensaje como `ring` y el proxio lo pega al timbre
2266
+ * TAL CUAL: va cifrado a la `encPub` del aprobador, y solo su teléfono lo abre, sin red.
2267
+ *
2268
+ * Es solo el asunto. Quien aprueba sigue decidiendo con la lista (`op: 'approvals'`), que
2269
+ * es la que va firmada: un asunto falso no aprueba nada.
2270
+ *
2271
+ * Sin `encPub` en el acta no hay asunto (y el teléfono enseña el genérico): mandarlo en claro
2272
+ * sería cambiar la promesa sin avisar.
2273
+ */
2274
+ const RING_CTX_KEYS = ['op', 'fields', 'product', 'version', 'from', 'reporterLabel', 'kind']
2275
+ async function ringFor (pub, record, hint) {
2276
+ const encPub = (record?.members || []).find((m) => m.pub === pub)?.encPub || null
2277
+ if (!encPub) return null
2278
+ let ctx = null
2279
+ if (hint.ctx && typeof hint.ctx === 'object') {
2280
+ ctx = {}
2281
+ for (const k of RING_CTX_KEYS) if (hint.ctx[k] != null) ctx[k] = hint.ctx[k]
2282
+ }
2283
+ try { return await sealTo(encPub, { ...hint, ctx }) } catch (e) {
2284
+ log(`[vault] could not seal the subject of the ring for ${pub.slice(0, 24)}…: ${e.message}`)
2285
+ return null
2286
+ }
2287
+ }
2288
+
2252
2289
  async function withSealedContext (items, approver, record) {
2253
2290
  const encPub = (record?.members || []).find((m) => m.pub === approver)?.encPub || null
2254
2291
  const output = []
@@ -2257,9 +2294,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2257
2294
  if (!ctx) { output.push({ ...rest, ctx: null }); continue }
2258
2295
  if (!encPub) { output.push({ ...rest, ctx: null, ctxSealed: false, ctxReason: 'no-enc-key' }); continue }
2259
2296
  try {
2260
- const cek = await makeContentKey()
2261
- const envelope = await encryptWithCek({ cek, gen: 0, plaintext: JSON.stringify(ctx) })
2262
- const wrap = await wrapForMember({ cek, memberEncPub: encPub })
2297
+ const { wrap, envelope } = await sealTo(encPub, ctx)
2263
2298
  output.push({ ...rest, ctx: null, ctxSealed: true, ctxWrap: wrap, ctxEnvelope: envelope })
2264
2299
  } catch (e) {
2265
2300
  // NO SE TRAGA: sin esto, un fallo al sellar se vería en el teléfono igual que un
@@ -2300,7 +2335,8 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2300
2335
  for (const pub of who) {
2301
2336
  // A la app que APRUEBA (`vault`): en un teléfono la llave es de todas sus apps, y sin
2302
2337
  // decirlo el pedido timbraba a messenger (websocket-proxy ≥ 1.4.0).
2303
- try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal }, { app: 'vault' }) }
2338
+ const ring = await ringFor(pub, record, { ...body, ctx: pend.ctx || null })
2339
+ try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal, ...(ring ? { ring } : {}) }, { app: 'vault' }) }
2304
2340
  catch (e) { log(`[vault] could not ring ${pub.slice(0, 24)}… about ${pend.ns}: ${e.message}`) }
2305
2341
  }
2306
2342
  log(`[vault] ${pend.ns}: rang ${who.length} approver(s) for ${pend.id}`)
@@ -2331,9 +2367,12 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2331
2367
  const { id, ev, ts, ...rest } = notice
2332
2368
  const body = { ev, id, ...rest, ts }
2333
2369
  const seal = await sealOrFail(body)
2370
+ // Lo que calla no timbra: no lleva asunto. Lo que suena, sí (ver `ringFor`).
2371
+ const record = quiet ? null : await refreshActa()
2334
2372
  let sent = 0
2335
2373
  for (const pub of who) {
2336
- try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal }, { app: 'vault', ...(quiet ? { quiet: true } : {}) }); sent++ }
2374
+ const ring = quiet ? null : await ringFor(pub, record, { ev, id, ts, kind: rest.kind || null, ns: rest.ns || null, deviceId: rest.deviceId || null, label: rest.label || null, product: rest.product || null, version: rest.version || null, from: rest.from || null })
2375
+ try { client.sendByPubkey(pub, { type: MSG.ADMIN_EVENT, body, seal, ...(ring ? { ring } : {}) }, { app: 'vault', ...(quiet ? { quiet: true } : {}) }); sent++ }
2337
2376
  catch (e) { log(`[vault] could not tell ${pub.slice(0, 24)}… about ${what}: ${e.message}`) }
2338
2377
  }
2339
2378
  return sent
@@ -2402,6 +2441,39 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2402
2441
  return { approvers: who.length, sent, notice }
2403
2442
  }
2404
2443
 
2444
+ /**
2445
+ * «SE LLEVÓ CLAVES SIN PEDIR», a quien aprueba (dueño, 2026-11-04). Un aparato con
2446
+ * `unattended` no pide aprobación —para eso se le dio—, pero que lo haga en silencio deja al
2447
+ * dueño sin saber qué máquina se llevó qué. Se cuenta como aviso (`delivered`), no como pedido.
2448
+ *
2449
+ * UNO POR APARATO, CAJÓN Y HORA: un servicio pide su cajón en cada arranque y el gestor una
2450
+ * contraseña en cada relleno; timbrar cada vez enseña a ignorar el timbre. Solo cuando de
2451
+ * verdad no se pidió por `unattended`: sin aprobadores no hay a quién contar, y lo aprobado
2452
+ * ya lo vio quien aprobó.
2453
+ */
2454
+ const DELIVERED_EVERY_MS = 60 * 60 * 1000
2455
+ const deliveredAt = new Map()
2456
+ async function announceDelivered ({ device, ns, kind }) {
2457
+ try {
2458
+ const record = await refreshActa()
2459
+ if (!record || !Acta.memberCan(record, device, 'unattended')) return
2460
+ const who = (record.members || []).filter((m) => Acta.memberCan(record, m.pub, 'approve')).map((m) => m.pub)
2461
+ if (!who.length) return
2462
+ const key = `${device}|${kind}|${ns}`
2463
+ const now = Date.now()
2464
+ if (now - (deliveredAt.get(key) || 0) < DELIVERED_EVERY_MS) return
2465
+ deliveredAt.set(key, now)
2466
+ for (const [k, t] of deliveredAt) if (now - t >= DELIVERED_EVERY_MS) deliveredAt.delete(k)
2467
+ const deviceId = await deviceIdOf(device).catch(() => null)
2468
+ if (!deviceId) return log(`[vault] delivered: could not name the device that took ${kind} of ${ns}, so nobody is told`)
2469
+ const label = (record.members || []).find((m) => m.pub === device)?.label || ''
2470
+ const notice = notices.add('delivered', { kind, ns, deviceId, label })
2471
+ const sent = await sendNotice(notice, who, `the delivery of ${kind} of ${ns} to ${deviceId}`)
2472
+ audit('delivered.announced', { device: deviceId, ns, kind, approvers: who.length, sent })
2473
+ log(`[vault] delivered: told ${sent} of ${who.length} approver(s) that ${deviceId} took ${kind} of ${ns} without approval (unattended)`)
2474
+ } catch (e) { log(`[vault] delivered: could not tell the approvers (${e.code || 'error'}: ${e.message})`) }
2475
+ }
2476
+
2405
2477
  /**
2406
2478
  * UN INCIDENTE: un agente de la cuenta dice que OTRO aparato de la cuenta se equivocó de
2407
2479
  * clave tres veces seguidas (la terminal, `dotrino-terminal lock`). No se decide aquí
@@ -2676,6 +2748,7 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
2676
2748
  // el permiso se seguía sirviendo solo.
2677
2749
  needsApproval: passwordsNeedApproval,
2678
2750
  approve: approvePasswordRequest,
2751
+ onDelivered: (pub) => announceDelivered({ device: pub, ns: 'passwords', kind: 'passwords' }),
2679
2752
  audit,
2680
2753
  log,
2681
2754
  }).start()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vaultd",
3
- "version": "0.189.1",
3
+ "version": "0.190.1",
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": {