@dotrino/terminal-agent 0.2.6 → 0.2.8
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 +34 -8
- package/package.json +2 -2
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
|
|
@@ -48,9 +48,14 @@ export async function startAgent (opts = {}) {
|
|
|
48
48
|
|
|
49
49
|
installNodeGlobals(dir)
|
|
50
50
|
|
|
51
|
+
// PTY nativo con binarios PREBUILT (Linux/macOS/Windows, sin toolchain): el fork
|
|
52
|
+
// `@homebridge/node-pty-prebuilt-multiarch` es API-idéntico a node-pty. Fallback a
|
|
53
|
+
// `node-pty` por si una instalación vieja lo trae.
|
|
51
54
|
let pty
|
|
52
|
-
try { pty = require('node-pty') } catch {
|
|
53
|
-
|
|
55
|
+
try { pty = require('@homebridge/node-pty-prebuilt-multiarch') } catch {
|
|
56
|
+
try { pty = require('node-pty') } catch {
|
|
57
|
+
throw new Error('falta el módulo PTY. Reinstala el agente: `npx @dotrino/terminal-agent` (baja el binario prebuilt).')
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
const { getWebSocketProxyClient } = await import('@dotrino/proxy-client')
|
|
@@ -167,6 +172,29 @@ export async function startAgent (opts = {}) {
|
|
|
167
172
|
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
173
|
}
|
|
169
174
|
|
|
175
|
+
const stop = () => {
|
|
176
|
+
clearInterval(revTimer); clearInterval(sweeper)
|
|
177
|
+
for (const s of sessions.values()) { try { s.term?.kill() } catch {} }
|
|
178
|
+
try { client.close() } catch {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// AUTO-BORRADO al ser REVOCADA: la bóveda envía un REVOKED FIRMADO por la maestra
|
|
182
|
+
// dirigido a ESTA máquina (al revocar, o cuando reaparece: ver @dotrino/vault). Solo
|
|
183
|
+
// nos borramos si la firma valida y el body es para nuestra pubkey → un proxy/peer
|
|
184
|
+
// malicioso NO puede borrarnos con un mensaje falso (cierra el wipe-DoS). Borra el
|
|
185
|
+
// enlace (link.json) y detiene el agente.
|
|
186
|
+
async function handleRevoked (p) {
|
|
187
|
+
const b = p?.body
|
|
188
|
+
if (!b || b.op !== 'revoke' || b.sub !== myPub) return
|
|
189
|
+
if (typeof b.exp === 'number' && Date.now() > b.exp) return
|
|
190
|
+
if (!await verifyDeviceSig({ publickey: master, data: b, signature: p.signature })) return
|
|
191
|
+
audit('revoked', { nonce: b.nonce })
|
|
192
|
+
if (!opts.quiet) console.log('\n[terminal] tu bóveda REVOCÓ esta máquina → borro el enlace y salgo.')
|
|
193
|
+
try { fs.rmSync(path.join(dir, 'link.json'), { force: true }) } catch (_) {}
|
|
194
|
+
stop()
|
|
195
|
+
if (opts.onRevoked) { try { opts.onRevoked() } catch (_) {} }
|
|
196
|
+
}
|
|
197
|
+
|
|
170
198
|
client.on('message', (from, payload) => {
|
|
171
199
|
if (!payload || typeof payload !== 'object') return
|
|
172
200
|
if (payload.type === T.HS) handleHandshake(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
|
|
@@ -174,16 +202,14 @@ export async function startAgent (opts = {}) {
|
|
|
174
202
|
// Sonda de presencia (liveness): el cliente hace ping y respondemos pong con el
|
|
175
203
|
// mismo nonce → así la app sabe que esta máquina está online (sin abrir sesión).
|
|
176
204
|
else if (payload.type === T.PING) send(from, { type: T.PONG, n: payload.n })
|
|
205
|
+
else if (payload.type === VMSG.REVOKED) handleRevoked(payload).catch(() => {})
|
|
177
206
|
})
|
|
178
207
|
|
|
179
208
|
if (!opts.quiet) {
|
|
180
209
|
console.log(`[terminal] agente activo · máquina ${myId} · vault ${(await pubkeyId(master)).slice(0, 16)} · proxy ${proxyUrl}`)
|
|
181
210
|
}
|
|
182
211
|
|
|
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
|
-
}
|
|
212
|
+
return { machine: myPub, machineId: myId, master, close: stop }
|
|
187
213
|
}
|
|
188
214
|
|
|
189
215
|
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.8",
|
|
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": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@dotrino/identity": "0.17.0",
|
|
17
17
|
"@dotrino/proxy-client": "0.6.4",
|
|
18
|
-
"node-pty": "
|
|
18
|
+
"@homebridge/node-pty-prebuilt-multiarch": "0.13.1",
|
|
19
19
|
"ws": "8.21.0"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT"
|