@dotrino/terminal-agent 0.2.6 → 0.2.7

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 (3) hide show
  1. package/bin/cli.js +2 -1
  2. package/index.js +27 -6
  3. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -65,7 +65,8 @@ try {
65
65
  process.exit(1)
66
66
  }
67
67
  const agent = await startAgent({
68
- dir: opt('--dir'), proxyUrl: opt('--proxy'), shell: opt('--shell')
68
+ dir: opt('--dir'), proxyUrl: opt('--proxy'), shell: opt('--shell'),
69
+ onRevoked: () => { console.log(' Esta máquina fue revocada desde tu bóveda. Para reconectarla, enrólala de nuevo.\n'); process.exit(0) }
69
70
  })
70
71
  console.log('\n Dotrino Terminal — agente activo')
71
72
  console.log(' máquina:', agent.machineId)
package/index.js CHANGED
@@ -20,7 +20,7 @@ import os from 'node:os'
20
20
  import fs from 'node:fs'
21
21
  import path from 'node:path'
22
22
  import { createRequire } from 'node:module'
23
- import { verifyChain, signWithDevice, pubkeyId } from '@dotrino/identity/capabilities'
23
+ import { verifyChain, signWithDevice, verifyDeviceSig, pubkeyId } from '@dotrino/identity/capabilities'
24
24
  import { installNodeGlobals } from './node-globals.js'
25
25
  import { makeEphemeral, deriveKey, seal, open } from './e2e.js'
26
26
  import { loadLink, dataDir } from './link.js'
@@ -31,7 +31,7 @@ const T = {
31
31
  HS: 'terminal.hs', ACK: 'terminal.hs.ack', CMD: 'terminal.cmd', OUT: 'terminal.out', ERROR: 'terminal.error',
32
32
  PING: 'terminal.ping', PONG: 'terminal.pong'
33
33
  }
34
- const VMSG = { DEVICES: 'vault.devices', DEVICES_RESULT: 'vault.devices.result' }
34
+ const VMSG = { DEVICES: 'vault.devices', DEVICES_RESULT: 'vault.devices.result', REVOKED: 'vault.revoked' }
35
35
  const SIGN_SCOPE = 'vault:sign'
36
36
  const SESSION_TTL_MS = 30 * 60 * 1000
37
37
  const REVOKE_REFRESH_MS = 5 * 60 * 1000
@@ -167,6 +167,29 @@ export async function startAgent (opts = {}) {
167
167
  if (msg.type === 'close') { try { s.term?.kill() } catch {}; sessions.delete(p.sid); audit('session-close', { sid: String(p.sid).slice(0, 8) }); return }
168
168
  }
169
169
 
170
+ const stop = () => {
171
+ clearInterval(revTimer); clearInterval(sweeper)
172
+ for (const s of sessions.values()) { try { s.term?.kill() } catch {} }
173
+ try { client.close() } catch {}
174
+ }
175
+
176
+ // AUTO-BORRADO al ser REVOCADA: la bóveda envía un REVOKED FIRMADO por la maestra
177
+ // dirigido a ESTA máquina (al revocar, o cuando reaparece: ver @dotrino/vault). Solo
178
+ // nos borramos si la firma valida y el body es para nuestra pubkey → un proxy/peer
179
+ // malicioso NO puede borrarnos con un mensaje falso (cierra el wipe-DoS). Borra el
180
+ // enlace (link.json) y detiene el agente.
181
+ async function handleRevoked (p) {
182
+ const b = p?.body
183
+ if (!b || b.op !== 'revoke' || b.sub !== myPub) return
184
+ if (typeof b.exp === 'number' && Date.now() > b.exp) return
185
+ if (!await verifyDeviceSig({ publickey: master, data: b, signature: p.signature })) return
186
+ audit('revoked', { nonce: b.nonce })
187
+ if (!opts.quiet) console.log('\n[terminal] tu bóveda REVOCÓ esta máquina → borro el enlace y salgo.')
188
+ try { fs.rmSync(path.join(dir, 'link.json'), { force: true }) } catch (_) {}
189
+ stop()
190
+ if (opts.onRevoked) { try { opts.onRevoked() } catch (_) {} }
191
+ }
192
+
170
193
  client.on('message', (from, payload) => {
171
194
  if (!payload || typeof payload !== 'object') return
172
195
  if (payload.type === T.HS) handleHandshake(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
@@ -174,16 +197,14 @@ export async function startAgent (opts = {}) {
174
197
  // Sonda de presencia (liveness): el cliente hace ping y respondemos pong con el
175
198
  // mismo nonce → así la app sabe que esta máquina está online (sin abrir sesión).
176
199
  else if (payload.type === T.PING) send(from, { type: T.PONG, n: payload.n })
200
+ else if (payload.type === VMSG.REVOKED) handleRevoked(payload).catch(() => {})
177
201
  })
178
202
 
179
203
  if (!opts.quiet) {
180
204
  console.log(`[terminal] agente activo · máquina ${myId} · vault ${(await pubkeyId(master)).slice(0, 16)} · proxy ${proxyUrl}`)
181
205
  }
182
206
 
183
- return {
184
- machine: myPub, machineId: myId, master,
185
- close () { clearInterval(revTimer); clearInterval(sweeper); for (const s of sessions.values()) { try { s.term?.kill() } catch {} } try { client.close() } catch {} }
186
- }
207
+ return { machine: myPub, machineId: myId, master, close: stop }
187
208
  }
188
209
 
189
210
  export default { startAgent }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Agente de Dotrino Terminal: abre una shell (PTY) en la máquina del vault solo para el dispositivo enlazado, vía @dotrino/tunnel y cifrado E2E.",
5
5
  "type": "module",
6
6
  "bin": {