@dotrino/terminal-agent 0.2.5 → 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.
- package/bin/cli.js +2 -1
- package/index.js +32 -7
- 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'
|
|
@@ -28,9 +28,10 @@ import { loadLink, dataDir } from './link.js'
|
|
|
28
28
|
const require = createRequire(import.meta.url)
|
|
29
29
|
|
|
30
30
|
const T = {
|
|
31
|
-
HS: 'terminal.hs', ACK: 'terminal.hs.ack', CMD: 'terminal.cmd', OUT: 'terminal.out', ERROR: 'terminal.error'
|
|
31
|
+
HS: 'terminal.hs', ACK: 'terminal.hs.ack', CMD: 'terminal.cmd', OUT: 'terminal.out', ERROR: 'terminal.error',
|
|
32
|
+
PING: 'terminal.ping', PONG: 'terminal.pong'
|
|
32
33
|
}
|
|
33
|
-
const VMSG = { DEVICES: 'vault.devices', DEVICES_RESULT: 'vault.devices.result' }
|
|
34
|
+
const VMSG = { DEVICES: 'vault.devices', DEVICES_RESULT: 'vault.devices.result', REVOKED: 'vault.revoked' }
|
|
34
35
|
const SIGN_SCOPE = 'vault:sign'
|
|
35
36
|
const SESSION_TTL_MS = 30 * 60 * 1000
|
|
36
37
|
const REVOKE_REFRESH_MS = 5 * 60 * 1000
|
|
@@ -166,20 +167,44 @@ export async function startAgent (opts = {}) {
|
|
|
166
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 }
|
|
167
168
|
}
|
|
168
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
|
+
|
|
169
193
|
client.on('message', (from, payload) => {
|
|
170
194
|
if (!payload || typeof payload !== 'object') return
|
|
171
195
|
if (payload.type === T.HS) handleHandshake(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
|
|
172
196
|
else if (payload.type === T.CMD) handleCmd(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
|
|
197
|
+
// Sonda de presencia (liveness): el cliente hace ping y respondemos pong con el
|
|
198
|
+
// mismo nonce → así la app sabe que esta máquina está online (sin abrir sesión).
|
|
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(() => {})
|
|
173
201
|
})
|
|
174
202
|
|
|
175
203
|
if (!opts.quiet) {
|
|
176
204
|
console.log(`[terminal] agente activo · máquina ${myId} · vault ${(await pubkeyId(master)).slice(0, 16)} · proxy ${proxyUrl}`)
|
|
177
205
|
}
|
|
178
206
|
|
|
179
|
-
return {
|
|
180
|
-
machine: myPub, machineId: myId, master,
|
|
181
|
-
close () { clearInterval(revTimer); clearInterval(sweeper); for (const s of sessions.values()) { try { s.term?.kill() } catch {} } try { client.close() } catch {} }
|
|
182
|
-
}
|
|
207
|
+
return { machine: myPub, machineId: myId, master, close: stop }
|
|
183
208
|
}
|
|
184
209
|
|
|
185
210
|
export default { startAgent }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.2.
|
|
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": {
|