@dotrino/vaultd 0.23.0 → 0.24.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/package.json +2 -2
- package/src/ctl.js +39 -8
- package/src/vault.js +31 -1
- package/src/vaultControl.js +27 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dotrino/identity": "^0.
|
|
22
|
+
"@dotrino/identity": "^0.44.0",
|
|
23
23
|
"@dotrino/proxy-client": "^0.10.0",
|
|
24
24
|
"ws": "^8.18.0"
|
|
25
25
|
},
|
package/src/ctl.js
CHANGED
|
@@ -410,13 +410,27 @@ async function cmdDevices () {
|
|
|
410
410
|
let snap = null
|
|
411
411
|
for (let i = 0; i < 50; i++) { await sleep(100); const d = readJson(devFile, null); if (d?.at) { snap = d; break } }
|
|
412
412
|
if (!snap) { console.error('El daemon no respondió.'); process.exit(1) }
|
|
413
|
-
const active = snap.issued || snap.active || snap.delegations || []
|
|
414
413
|
const revoked = snap.revoked || []
|
|
414
|
+
const fuera = new Set(revoked.map((r) => r?.nonce || r))
|
|
415
|
+
// UN APARATO, UNA LÍNEA. El daemon lleva la cuenta por CERTIFICADO —correcto para él,
|
|
416
|
+
// porque revocar es revocar un papel—, pero renovar emite uno nuevo cada 30 días: un
|
|
417
|
+
// aparato de un año salía doce veces, y los ya retirados seguían contando como
|
|
418
|
+
// enrolados. Se agrupa por llave y se dice cuántos certificados tiene.
|
|
419
|
+
const porLlave = new Map()
|
|
420
|
+
for (const d of (snap.issued || snap.active || snap.delegations || [])) {
|
|
421
|
+
if (d.revokedAt || fuera.has(d.nonce)) continue
|
|
422
|
+
const clave = d.sub || d.nonce
|
|
423
|
+
const y = porLlave.get(clave)
|
|
424
|
+
if (!y) porLlave.set(clave, { ...d, certs: 1 })
|
|
425
|
+
else { y.certs++; if ((d.exp || 0) > (y.exp || 0)) Object.assign(y, { ...d, certs: y.certs }) }
|
|
426
|
+
}
|
|
427
|
+
const active = [...porLlave.values()]
|
|
415
428
|
console.log('Dispositivos enrolados: %d', active.length)
|
|
416
429
|
for (const d of active) {
|
|
417
430
|
const did = d.sub ? await deviceIdOf(d.sub) : '????-????'
|
|
418
|
-
console.log(' · %s %s%s%s', did, d.label || '(sin etiqueta)',
|
|
419
|
-
d.exp ? '
|
|
431
|
+
console.log(' · %s %s%s%s%s', did, d.label || '(sin etiqueta)',
|
|
432
|
+
d.exp ? ' vence=' + new Date(d.exp).toISOString().slice(0, 10) : '',
|
|
433
|
+
d.certs > 1 ? ' (' + d.certs + ' certificados)' : '',
|
|
420
434
|
d.nonce ? ' nonce=' + d.nonce : '')
|
|
421
435
|
}
|
|
422
436
|
if (revoked.length) {
|
|
@@ -426,12 +440,29 @@ async function cmdDevices () {
|
|
|
426
440
|
console.log('\nPara revocar uno (y ordenarle autoborrarse): dotrino-vault revoke <nonce>')
|
|
427
441
|
}
|
|
428
442
|
|
|
429
|
-
|
|
430
|
-
|
|
443
|
+
/**
|
|
444
|
+
* `dotrino-vault revoke <ID|nonce>` — quita un dispositivo.
|
|
445
|
+
*
|
|
446
|
+
* Con el IDENTIFICADOR del aparato (`AB12-CD34`) se le retiran TODOS sus certificados,
|
|
447
|
+
* que es lo que la gente quiere decir con «quitar este dispositivo»: renovar emite uno
|
|
448
|
+
* nuevo cada 30 días, así que quitar solo el último dejaba vivos los anteriores hasta que
|
|
449
|
+
* caducaran — quitarlo sin quitarlo. Con un `nonce` suelto se retira ese y solo ese, que
|
|
450
|
+
* sigue siendo útil para casos finos.
|
|
451
|
+
*/
|
|
452
|
+
async function cmdRevoke (arg) {
|
|
453
|
+
if (!arg) { console.error('uso: dotrino-vault revoke <ID|nonce> (el ID quita el aparato entero)'); process.exit(2) }
|
|
454
|
+
const esId = /^[0-9a-f]{4}-?[0-9a-f]{4}$/i.test(arg)
|
|
431
455
|
const s = requireDaemon()
|
|
432
|
-
|
|
456
|
+
if (esId) {
|
|
457
|
+
const m = await buscarMiembro(arg.toUpperCase().includes('-') ? arg.toUpperCase() : arg.toUpperCase().replace(/(.{4})(.{4})/, '$1-$2'))
|
|
458
|
+
writeReq('revoke-request.json', { sub: m.pub })
|
|
459
|
+
avisar(s.pid, 'SIGUSR2')
|
|
460
|
+
console.log('Quitado %s (todos sus certificados). Se autoborrará al reconectar. Verifica: dotrino-vault devices', m.id)
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
writeReq('revoke-request.json', { nonce: arg })
|
|
433
464
|
avisar(s.pid, 'SIGUSR2')
|
|
434
|
-
console.log('Revocación enviada para nonce=%s. El dispositivo se autoborrará al reconectar. Verifica: dotrino-vault devices',
|
|
465
|
+
console.log('Revocación enviada para nonce=%s. El dispositivo se autoborrará al reconectar. Verifica: dotrino-vault devices', arg)
|
|
435
466
|
}
|
|
436
467
|
|
|
437
468
|
/**
|
|
@@ -671,7 +702,7 @@ function help () {
|
|
|
671
702
|
members el acta del perfil: quién es tuyo y qué puede hacer
|
|
672
703
|
label <ID> <nombre> renombra un dispositivo (el nombre con el que lo reconoces)
|
|
673
704
|
caps <ID> ±permiso cambia permisos (+firma -guarda +administra …)
|
|
674
|
-
revoke <nonce>
|
|
705
|
+
revoke <ID|nonce> quita un dispositivo (con el ID, todos sus certificados)
|
|
675
706
|
activity [n] bitácora de seguridad: firmas, renovaciones, enrolados, rechazos
|
|
676
707
|
logs últimos logs del servicio
|
|
677
708
|
version muestra la versión instalada
|
package/src/vault.js
CHANGED
|
@@ -217,10 +217,40 @@ export async function startVault ({ dir = dataDir(), proxyUrl, log = console.log
|
|
|
217
217
|
|
|
218
218
|
// Lista (solo lectura) de dispositivos enrolados, para un panel en el navegador.
|
|
219
219
|
// Cualquier cert válido tuyo puede verla; REVOCAR sigue siendo solo desde el PC.
|
|
220
|
+
/**
|
|
221
|
+
* Un aparato REVOCADO que vuelve a aparecer: se le reemite el `vault.revoked` FIRMADO
|
|
222
|
+
* para que se entere y se auto-borre.
|
|
223
|
+
*
|
|
224
|
+
* Un «unauthorized: revoked» suelto no basta y no debe bastar: no va firmado, así que
|
|
225
|
+
* el dispositivo tiene prohibido borrar nada con él (si no, cualquiera destruiría datos
|
|
226
|
+
* ajenos con un mensaje). Lo único que puede borrar es un aviso firmado por la maestra
|
|
227
|
+
* — y hasta ahora el daemon no lo reemitía nunca. Si el aparato estaba apagado cuando lo
|
|
228
|
+
* quitaste, no se enteraba jamás: seguía enseñando el perfil como si nada.
|
|
229
|
+
*/
|
|
230
|
+
async function avisarSiRevocado (pubkey) {
|
|
231
|
+
if (typeof pubkey !== 'string') return
|
|
232
|
+
try {
|
|
233
|
+
// OJO con dónde se buscan: desde identity 0.42 `issued` es «lo que HOY sirve para
|
|
234
|
+
// entrar», así que los retirados NO están ahí — viven en `revokedCerts`. Buscarlos
|
|
235
|
+
// en `issued` no daba error, daba una lista vacía y ningún aviso.
|
|
236
|
+
const dele = await identity.listDelegations()
|
|
237
|
+
const revocados = await revocationSet()
|
|
238
|
+
const candidatos = [...(dele.revokedCerts || []), ...(dele.issued || [])]
|
|
239
|
+
const suyas = candidatos.filter((x) => x.sub === pubkey && (x.revokedAt || revocados.has(x.nonce)))
|
|
240
|
+
if (suyas.length) {
|
|
241
|
+
await desk.emitRevoke(pubkey, suyas[0].nonce)
|
|
242
|
+
audit('revoke.notified', { device: await deviceIdOf(pubkey).catch(() => null) })
|
|
243
|
+
}
|
|
244
|
+
} catch (e) { log('[vault] could not re-emit the revocation:', e.message) }
|
|
245
|
+
}
|
|
246
|
+
|
|
220
247
|
async function handleDevices (from, p) {
|
|
221
248
|
if (!isFresh(p.data)) return staleReply(from)
|
|
222
249
|
const chk = await verifyChain({ data: p.data, signature: p.signature, cert: p.cert, trustedIssuer: master, revoked: await revocationSet() })
|
|
223
|
-
if (!chk.ok)
|
|
250
|
+
if (!chk.ok) {
|
|
251
|
+
if (chk.reason === 'revoked') await avisarSiRevocado(p.data?.publickey)
|
|
252
|
+
return reply(from, { type: MSG.ERROR, error: 'unauthorized: ' + chk.reason })
|
|
253
|
+
}
|
|
224
254
|
const { issued, revoked } = await identity.listDelegations()
|
|
225
255
|
// El acta viaja con la lista: así cada dispositivo se entera de los cambios de
|
|
226
256
|
// política (quién manda, quién puede qué) sin un canal aparte.
|
package/src/vaultControl.js
CHANGED
|
@@ -196,10 +196,36 @@ export async function listDevices (profile) {
|
|
|
196
196
|
const { devices } = await snapshot(profile)
|
|
197
197
|
if (!devices) throw coded('the daemon did not reply', 'NO_REPLY')
|
|
198
198
|
const issued = devices.issued || devices.active || devices.delegations || []
|
|
199
|
+
const revoked = devices.revoked || []
|
|
199
200
|
const withIds = await Promise.all(issued.map(async (d) => ({
|
|
200
201
|
...d, deviceId: d.sub ? await deviceIdOf(d.sub) : '????-????'
|
|
201
202
|
})))
|
|
202
|
-
return { issued: withIds, revoked
|
|
203
|
+
return { issued: agruparPorAparato(withIds, revoked), revoked, profile: devices.profile || null }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* UN APARATO, UNA FILA — y sin los certificados retirados.
|
|
208
|
+
*
|
|
209
|
+
* El daemon lleva la cuenta por CERTIFICADO, que es lo correcto para él: revocar es
|
|
210
|
+
* revocar un papel. Pero al dueño le sobra ese detalle — renovar emite uno nuevo cada 30
|
|
211
|
+
* días, así que un aparato de un año saldría doce veces, y los revocados seguían contando
|
|
212
|
+
* como «enrolados». Se agrupa por llave, se queda el más nuevo y se guardan TODOS sus
|
|
213
|
+
* nonces, que es lo que hace falta para retirarlo entero.
|
|
214
|
+
*/
|
|
215
|
+
export function agruparPorAparato (lista, revoked = []) {
|
|
216
|
+
const fuera = new Set(revoked.map((r) => r?.nonce || r))
|
|
217
|
+
const porLlave = new Map()
|
|
218
|
+
for (const d of lista) {
|
|
219
|
+
if (d.revokedAt || fuera.has(d.nonce)) continue
|
|
220
|
+
const clave = d.sub || d.nonce
|
|
221
|
+
const y = porLlave.get(clave)
|
|
222
|
+
if (!y) porLlave.set(clave, { ...d, nonces: [d.nonce] })
|
|
223
|
+
else {
|
|
224
|
+
y.nonces.push(d.nonce)
|
|
225
|
+
if ((d.exp || 0) > (y.exp || 0)) Object.assign(y, { ...d, nonces: y.nonces })
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return [...porLlave.values()]
|
|
203
229
|
}
|
|
204
230
|
|
|
205
231
|
/**
|