@dotrino/vault 0.1.1 → 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.
- package/package.json +1 -1
- package/src/index.js +24 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vault",
|
|
3
|
-
"version": "0.1.
|
|
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) => {
|
|
@@ -214,7 +229,14 @@ export async function startDeviceVault (identity, { proxyUrl } = {}) {
|
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
async function revoke (nonce) {
|
|
217
|
-
|
|
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 {
|