@dotrino/vault 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +25 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vault",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Usa ESTE dispositivo (navegador) como bóveda/CA del ecosistema Dotrino: atiende enrolamientos por el proxy y firma certificados de delegación a tus máquinas. Contraparte browser del daemon dotrino-vault, reutilizable por cualquier app.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -35,6 +35,7 @@ const MSG = {
35
35
  ENROLLED: 'vault.enrolled',
36
36
  DEVICES: 'vault.devices',
37
37
  DEVICES_RESULT: 'vault.devices.result',
38
+ REVOKED: 'vault.revoked',
38
39
  ERROR: 'vault.error'
39
40
  }
40
41
 
@@ -127,8 +128,19 @@ export async function startDeviceVault (identity, { proxyUrl } = {}) {
127
128
  send(from, { type: MSG.ENROLL_CHALLENGE, deviceId })
128
129
  }
129
130
 
131
+ // Emite un REVOKED FIRMADO por la maestra a la máquina revocada para que se
132
+ // auto-borre. Va por `sendByPubkey` → si está offline, el proxy lo encola 24 h; y
133
+ // si reaparece más tarde, `handleDevices` lo re-emite en su siguiente consulta.
134
+ // El auto-borrado remoto SOLO se dispara con esta firma (no con un error cualquiera).
135
+ async function emitRevoke (dpub, nonce) {
136
+ const body = { op: 'revoke', sub: dpub, nonce, iat: Date.now(), exp: Date.now() + DEVICE_TTL_MS }
137
+ const { signature } = await identity.signData(body)
138
+ try { client.sendByPubkey(dpub, { type: MSG.REVOKED, body, signature }) } catch (_) {}
139
+ }
140
+
130
141
  // Consulta de revocaciones (igual que `vault.devices` del daemon): responde la lista
131
- // de dispositivos enrolados + revocados para que el dispositivo refresque su set.
142
+ // de dispositivos enrolados + revocados para que el dispositivo refresque su set. Y si
143
+ // QUIEN consulta es una máquina ya revocada (reapareció), le re-emite el REVOKED firmado.
132
144
  async function handleDevices (from, p) {
133
145
  const d = p?.data
134
146
  if (!d || !p.signature || !p.cert) return send(from, { type: MSG.ERROR, error: 'petición inválida' })
@@ -141,6 +153,9 @@ export async function startDeviceVault (identity, { proxyUrl } = {}) {
141
153
  label: x.label || '', scope: x.scope, exp: x.exp, nonce: x.nonce
142
154
  })))
143
155
  send(from, { type: MSG.DEVICES_RESULT, devices, revoked: (revoked || []).map((r) => r.nonce || r) })
156
+ // ¿el que consulta es una máquina revocada que reapareció? → re-emite el REVOKED firmado.
157
+ const mine = (issued || []).find((x) => x.sub === chk.device && x.revokedAt)
158
+ if (mine) emitRevoke(chk.device, mine.nonce)
144
159
  }
145
160
 
146
161
  client.on('message', (_from, p) => {
@@ -205,7 +220,7 @@ export async function startDeviceVault (identity, { proxyUrl } = {}) {
205
220
  const now = Date.now()
206
221
  const bySub = new Map()
207
222
  for (const x of (issued || [])) {
208
- if (!x.sub || (x.exp && x.exp <= now)) continue
223
+ if (!x.sub || x.revokedAt || (x.exp && x.exp <= now)) continue // revocada = fuera de la lista
209
224
  if (!Array.isArray(x.scope) || !x.scope.includes(SIGN_SCOPE)) continue
210
225
  if (!x.label || x.label === 'cli') continue
211
226
  if (!bySub.has(x.sub) || (x.exp || 0) > (bySub.get(x.sub).exp || 0)) bySub.set(x.sub, x)
@@ -214,7 +229,14 @@ export async function startDeviceVault (identity, { proxyUrl } = {}) {
214
229
  }
215
230
 
216
231
  async function revoke (nonce) {
217
- return identity.revokeDelegation(nonce)
232
+ // Deja el registro persistente (revokedAt en la delegación) y AVISA a la máquina
233
+ // con un REVOKED firmado para que se auto-borre (ahora si está online, o al
234
+ // reaparecer vía handleDevices). Ver emitRevoke.
235
+ const { issued } = await identity.listDelegations()
236
+ const dele = (issued || []).find((d) => d.nonce === nonce)
237
+ const res = await identity.revokeDelegation(nonce)
238
+ if (dele?.sub) await emitRevoke(dele.sub, nonce)
239
+ return res
218
240
  }
219
241
 
220
242
  return {