@dotrino/vaultd 0.22.0 → 0.23.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/admin.js +8 -0
- package/lib/src/enroll.js +24 -1
- package/lib/src/index.js +4 -2
- package/package.json +2 -2
- package/src/daemon.js +7 -3
- package/src/tui/app.js +27 -4
- package/src/vault.js +14 -3
- package/src/vaultControl.js +8 -3
package/lib/src/admin.js
CHANGED
|
@@ -127,7 +127,15 @@ export function createAdminDesk ({
|
|
|
127
127
|
return { ok: true, result: { ok: true } }
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
// Quitar un dispositivo: por `sub` se le retiran TODOS sus certificados. Con
|
|
131
|
+
// `certNonce` a secas solo cae ese papel, y el aparato puede tener otro vigente.
|
|
130
132
|
if (data.op === 'revoke') {
|
|
133
|
+
if (data.sub) {
|
|
134
|
+
const r = await desk.revokeDevice(String(data.sub))
|
|
135
|
+
audit('admin.revoke-device', { by, certs: r?.nonces?.length ?? null })
|
|
136
|
+
await notify('revoked', { by })
|
|
137
|
+
return { ok: true, result: r || { ok: true } }
|
|
138
|
+
}
|
|
131
139
|
const r = await desk.revoke(String(data.certNonce || ''))
|
|
132
140
|
audit('admin.revoke', { by, certNonce: data.certNonce })
|
|
133
141
|
await notify('revoked', { certNonce: data.certNonce, by })
|
package/lib/src/enroll.js
CHANGED
|
@@ -441,9 +441,32 @@ export function createEnrollDesk ({
|
|
|
441
441
|
return res
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
+
/**
|
|
445
|
+
* QUITA EL DISPOSITIVO entero: retira TODOS sus certificados vigentes y le manda una
|
|
446
|
+
* sola orden de autoborrado. `revoke(nonce)` retira un papel, y un aparato puede tener
|
|
447
|
+
* varios (una renovación dejaba vivo el anterior): quitarle uno no lo echaba, y podía
|
|
448
|
+
* quedarse dentro justo con el que llevaba `vault:admin`.
|
|
449
|
+
*/
|
|
450
|
+
async function revokeDevice (sub) {
|
|
451
|
+
if (!sub) throw new Error('sub (device pubkey) required')
|
|
452
|
+
const { issued } = await identity.listDelegations()
|
|
453
|
+
const mine = (issued || []).filter((d) => d.sub === sub)
|
|
454
|
+
audit('revoke-device', { certs: mine.length })
|
|
455
|
+
// Si el núcleo no trae `revokeDevice` (bóveda vieja), se cae a retirarlos uno a uno.
|
|
456
|
+
const res = identity.revokeDevice
|
|
457
|
+
? await identity.revokeDevice(sub)
|
|
458
|
+
: { ok: true, nonces: await (async () => {
|
|
459
|
+
const done = []
|
|
460
|
+
for (const d of mine) { await identity.revokeDelegation(d.nonce); done.push(d.nonce) }
|
|
461
|
+
return done
|
|
462
|
+
})() }
|
|
463
|
+
await emitRevoke(sub, mine[0]?.nonce || null)
|
|
464
|
+
return res
|
|
465
|
+
}
|
|
466
|
+
|
|
444
467
|
return {
|
|
445
468
|
startPairing, stopPairing, handleEnroll, handleActaSealed, handleHello, approve, reject,
|
|
446
|
-
listPending, findPending, emitRevoke, revoke,
|
|
469
|
+
listPending, findPending, emitRevoke, revoke, revokeDevice,
|
|
447
470
|
get pendingCount () { return pending.size }
|
|
448
471
|
}
|
|
449
472
|
}
|
package/lib/src/index.js
CHANGED
|
@@ -155,14 +155,16 @@ export async function startDeviceVault (identity, { proxyUrl, client: injectedCl
|
|
|
155
155
|
if (typeof d.ts !== 'number' || Math.abs(Date.now() - d.ts) > FRESH_WINDOW_MS) return
|
|
156
156
|
const chk = await verifyChain({ data: d, signature: p.signature, cert: p.cert, trustedIssuer: iss })
|
|
157
157
|
if (!chk.ok) return send(from, { type: MSG.ERROR, error: 'no autorizado: ' + chk.reason })
|
|
158
|
-
const { issued, revoked } = await identity.listDelegations()
|
|
158
|
+
const { issued, revoked, revokedCerts } = await identity.listDelegations()
|
|
159
159
|
const devices = await Promise.all((issued || []).map(async (x) => ({
|
|
160
160
|
deviceId: x.sub ? await deviceIdOf(x.sub) : null, sub: x.sub || null,
|
|
161
161
|
label: x.label || '', scope: x.scope, exp: x.exp, nonce: x.nonce
|
|
162
162
|
})))
|
|
163
163
|
send(from, { type: MSG.DEVICES_RESULT, devices, revoked: (revoked || []).map((r) => r.nonce || r) })
|
|
164
164
|
// ¿el que consulta es una máquina revocada que reapareció? → re-emite el REVOKED firmado.
|
|
165
|
-
|
|
165
|
+
// Se busca en `revokedCerts`: desde que `issued` solo trae lo vigente, los retirados
|
|
166
|
+
// ya no están ahí y este aviso dejaba de dispararse (se caía en silencio).
|
|
167
|
+
const mine = (revokedCerts || issued || []).find((x) => x.sub === chk.device && x.revokedAt)
|
|
166
168
|
if (mine) desk.emitRevoke(chk.device, mine.nonce)
|
|
167
169
|
}
|
|
168
170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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.43.0",
|
|
23
23
|
"@dotrino/proxy-client": "^0.10.0",
|
|
24
24
|
"ws": "^8.18.0"
|
|
25
25
|
},
|
package/src/daemon.js
CHANGED
|
@@ -222,10 +222,14 @@ export async function runDaemon () {
|
|
|
222
222
|
console.log('[vault] permissions updated: %s', capsReq.caps.join(', ') || '(ninguno)')
|
|
223
223
|
} catch (e) { console.error('[vault] could not change permissions:', e.message) }
|
|
224
224
|
}
|
|
225
|
+
// Quitar un dispositivo: se pide por `sub` (la llave del aparato). `nonce` sigue
|
|
226
|
+
// aceptado para una consola vieja, pero retira UN certificado, no el aparato.
|
|
225
227
|
const req = readJsonSafe(revokeReqFile)
|
|
226
|
-
if (req?.nonce) {
|
|
227
|
-
try {
|
|
228
|
-
|
|
228
|
+
if (req?.sub || req?.nonce) {
|
|
229
|
+
try {
|
|
230
|
+
await targetOf(req)?.revokeDevice(req.sub ? { sub: req.sub } : { nonce: req.nonce })
|
|
231
|
+
console.log(req.sub ? '[vault] device removed' : '[vault] revoked nonce=%s', req.nonce || '')
|
|
232
|
+
} catch (e) { console.error('[vault] revocation failed:', e.message) }
|
|
229
233
|
rm(revokeReqFile)
|
|
230
234
|
}
|
|
231
235
|
// Secretos de servicios: `secret set/rm` del CLI. El archivo con el valor
|
package/src/tui/app.js
CHANGED
|
@@ -70,6 +70,24 @@ const shortScope = (scope) => {
|
|
|
70
70
|
return arr.map((s) => String(s).replace(/^vault:/, '')).join(',') || '—'
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Un aparato = una llave (`sub`), aunque tenga varios certificados vigentes. Se queda con
|
|
75
|
+
* el de vencimiento más lejano (el último emitido) y suma los alcances de todos, para que
|
|
76
|
+
* la fila no prometa menos de lo que el aparato puede hacer de verdad.
|
|
77
|
+
*/
|
|
78
|
+
function groupByDevice (issued) {
|
|
79
|
+
const by = new Map()
|
|
80
|
+
for (const d of issued) {
|
|
81
|
+
const key = d.sub || d.deviceId || d.nonce
|
|
82
|
+
const prev = by.get(key)
|
|
83
|
+
if (!prev) { by.set(key, { ...d, certCount: 1, scope: [...(Array.isArray(d.scope) ? d.scope : [d.scope])] }); continue }
|
|
84
|
+
prev.certCount++
|
|
85
|
+
for (const s of (Array.isArray(d.scope) ? d.scope : [d.scope])) if (!prev.scope.includes(s)) prev.scope.push(s)
|
|
86
|
+
if ((d.exp || 0) > (prev.exp || 0)) { prev.exp = d.exp; prev.nonce = d.nonce; prev.label = d.label || prev.label }
|
|
87
|
+
}
|
|
88
|
+
return [...by.values()]
|
|
89
|
+
}
|
|
90
|
+
|
|
73
91
|
function activeProfile (st) {
|
|
74
92
|
const list = st.profiles?.profiles || []
|
|
75
93
|
return list.find((p) => p.current) || list[0] || null
|
|
@@ -172,13 +190,17 @@ function deviceRows (st, t) {
|
|
|
172
190
|
rows.push({ text: t.warn(i.pendingDevice(pend.deviceId)) + t.muted(i.pendingHint), sel: false })
|
|
173
191
|
rows.push({ text: '', sel: false })
|
|
174
192
|
}
|
|
175
|
-
|
|
193
|
+
// UNA FILA POR APARATO, no por certificado. Antes se pintaba `issued` tal cual y un
|
|
194
|
+
// aparato con dos certs (el viejo + el de la renovación) salía dos veces: parecían dos
|
|
195
|
+
// máquinas. Se agrupa por llave y se muestra el cert vigente más largo.
|
|
196
|
+
const issued = groupByDevice(st.devices?.issued || [])
|
|
176
197
|
if (!issued.length) {
|
|
177
198
|
rows.push({ text: t.muted(i.noDevices), sel: false })
|
|
178
199
|
}
|
|
179
200
|
for (const d of issued) {
|
|
180
201
|
const label = d.label || t.muted(i.noLabel)
|
|
181
|
-
const
|
|
202
|
+
const extra = d.certCount > 1 ? t.muted(` certs:${d.certCount}`) : ''
|
|
203
|
+
const line = ` ${t.bold(d.deviceId)} ${label} ${t.muted('scope:' + shortScope(d.scope))} ${t.muted('exp:' + fmtExp(d.exp))}${extra}`
|
|
182
204
|
rows.push({ text: line, sel: true, meta: d })
|
|
183
205
|
}
|
|
184
206
|
const revoked = st.devices?.revoked || []
|
|
@@ -523,12 +545,13 @@ async function onKeyDevices (term, st, key) {
|
|
|
523
545
|
if (!st.pending) { flash(st, i.noPendingToReject, 'warn'); return true }
|
|
524
546
|
const r = await guard(term, st, i.rejecting, () => vc.rejectPending(st.pending.deviceId, activeId(st)))
|
|
525
547
|
if (r.ok) { flash(st, i.deviceRejected); st.pending = null }
|
|
526
|
-
} else if ((ch === 'v' || key.name === 'delete') && cur?.nonce != null) { //
|
|
548
|
+
} else if ((ch === 'v' || key.name === 'delete') && (cur?.sub || cur?.nonce != null)) { // quitar el aparato seleccionado
|
|
527
549
|
setConfirm(st, {
|
|
528
550
|
text: i.revokeConfirm(cur.deviceId),
|
|
529
551
|
onYes: async () => {
|
|
530
552
|
st.confirm = null
|
|
531
|
-
|
|
553
|
+
// Por `sub`: se le retiran TODOS los certificados, no solo el de esta fila.
|
|
554
|
+
const r = await guard(term, st, i.revoking, () => vc.revokeDevice({ sub: cur.sub, nonce: cur.nonce }, activeId(st)))
|
|
532
555
|
if (r.ok) { flash(st, i.deviceRevoked(cur.deviceId)); st.devices = r.v; st.sel.devices = 0 }
|
|
533
556
|
},
|
|
534
557
|
onNo: () => { st.confirm = null }
|
package/src/vault.js
CHANGED
|
@@ -534,9 +534,20 @@ export async function startVault ({ dir = dataDir(), proxyUrl, log = console.log
|
|
|
534
534
|
await notifyMembers('label', { deviceId: device, label: r?.label ?? label })
|
|
535
535
|
return r
|
|
536
536
|
},
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
// QUITAR EL DISPOSITIVO. Se identifica por su llave (`sub`), no por un `nonce`: un
|
|
538
|
+
// aparato puede tener varios certificados y retirar uno no lo echaba de la bóveda.
|
|
539
|
+
// Se sigue aceptando `{ nonce }` para no romper una consola vieja en vuelo.
|
|
540
|
+
revokeDevice: async (target) => {
|
|
541
|
+
const sub = typeof target === 'object' && target ? target.sub : null
|
|
542
|
+
if (!sub) {
|
|
543
|
+
const nonce = typeof target === 'string' ? target : target?.nonce
|
|
544
|
+
const r = await desk.revoke(nonce)
|
|
545
|
+
await notifyMembers('revoked', { certNonce: nonce, by: 'pc' })
|
|
546
|
+
return r
|
|
547
|
+
}
|
|
548
|
+
const r = await desk.revokeDevice(sub)
|
|
549
|
+
audit('revoke-device', { device: await deviceIdOf(sub).catch(() => null), certs: r?.nonces?.length ?? null })
|
|
550
|
+
await notifyMembers('revoked', { deviceId: await deviceIdOf(sub).catch(() => null), by: 'pc' })
|
|
540
551
|
return r
|
|
541
552
|
},
|
|
542
553
|
close () {
|
package/src/vaultControl.js
CHANGED
|
@@ -245,10 +245,15 @@ export async function setDeviceCaps (pub, caps, profile) {
|
|
|
245
245
|
return listDevices(profile)
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
/**
|
|
249
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Quita un dispositivo por su llave `sub` (le ordena autoborrarse) y revuelca.
|
|
250
|
+
* Se acepta un `nonce` suelto por compatibilidad, pero eso retira UN certificado:
|
|
251
|
+
* un aparato puede tener varios y seguiría entrando con el otro.
|
|
252
|
+
*/
|
|
253
|
+
export async function revokeDevice (target, profile) {
|
|
250
254
|
requireAlive()
|
|
251
|
-
|
|
255
|
+
const req = typeof target === 'string' ? { nonce: target } : { sub: target?.sub, nonce: target?.nonce }
|
|
256
|
+
writeReq(F.revokeReq, req, profile)
|
|
252
257
|
signalOrCleanup('SIGUSR2', [F.revokeReq])
|
|
253
258
|
await sleep(300)
|
|
254
259
|
return listDevices(profile)
|