@dotrino/terminal-agent 0.2.2 → 0.2.3
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/index.js +17 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* cacheada + el TTL del cert acota el riesgo. I/O cifrado E2E (../shared/e2e.js).
|
|
18
18
|
*/
|
|
19
19
|
import os from 'node:os'
|
|
20
|
+
import fs from 'node:fs'
|
|
21
|
+
import path from 'node:path'
|
|
20
22
|
import { createRequire } from 'node:module'
|
|
21
23
|
import { verifyChain, signWithDevice, pubkeyId } from '@dotrino/identity/capabilities'
|
|
22
24
|
import { installNodeGlobals } from './node-globals.js'
|
|
@@ -68,6 +70,13 @@ export async function startAgent (opts = {}) {
|
|
|
68
70
|
await identify()
|
|
69
71
|
client.on('token', () => { identify().catch(() => {}) })
|
|
70
72
|
|
|
73
|
+
// Bitácora persistente de sesiones (sessions.log, JSONL): qué dispositivo abrió
|
|
74
|
+
// consola y cuándo — auditoría local si un dispositivo tuyo cae en malas manos.
|
|
75
|
+
const sessionsLog = path.join(dir, 'sessions.log')
|
|
76
|
+
const audit = (op, info = {}) => {
|
|
77
|
+
try { fs.appendFileSync(sessionsLog, JSON.stringify({ ts: Date.now(), op, ...info }) + '\n') } catch (_) {}
|
|
78
|
+
}
|
|
79
|
+
|
|
71
80
|
const send = (to, obj) => { try { client.send(to, obj) } catch (e) { if (!opts.quiet) console.error('[terminal] send:', e.message) } }
|
|
72
81
|
|
|
73
82
|
// --- Revocación: refrescar la lista del vault por el proxy (best-effort) ---
|
|
@@ -96,7 +105,7 @@ export async function startAgent (opts = {}) {
|
|
|
96
105
|
const sessions = new Map()
|
|
97
106
|
const sweeper = setInterval(() => {
|
|
98
107
|
const now = Date.now()
|
|
99
|
-
for (const [sid, s] of sessions) if (now > s.exp) { try { s.term?.kill() } catch {}; sessions.delete(sid) }
|
|
108
|
+
for (const [sid, s] of sessions) if (now > s.exp) { try { s.term?.kill() } catch {}; sessions.delete(sid); audit('session-expire', { sid: sid.slice(0, 8) }) }
|
|
100
109
|
}, 60 * 1000); sweeper.unref?.()
|
|
101
110
|
|
|
102
111
|
async function pushOut (s, data) {
|
|
@@ -108,6 +117,11 @@ export async function startAgent (opts = {}) {
|
|
|
108
117
|
async function handleHandshake (from, p) {
|
|
109
118
|
const { data, signature, cert } = p
|
|
110
119
|
if (!data || !signature || !cert) return send(from, { type: T.ERROR, error: 'handshake incompleto' })
|
|
120
|
+
// FRESCURA anti-replay: el HS debe ser reciente (±5 min); sin esto un relay
|
|
121
|
+
// malicioso podía reproducir handshakes viejos (sesiones huérfanas / DoS).
|
|
122
|
+
if (typeof data.ts !== 'number' || Math.abs(Date.now() - data.ts) > 5 * 60 * 1000) {
|
|
123
|
+
return send(from, { type: T.ERROR, error: 'handshake vencido (posible replay, o el reloj del dispositivo está desfasado)' })
|
|
124
|
+
}
|
|
111
125
|
const chk = await verifyChain({ data, signature, cert, expectedScope: SIGN_SCOPE, trustedIssuer: master, revoked: revokedSet })
|
|
112
126
|
if (!chk.ok) return send(from, { type: T.ERROR, error: 'no autorizado: ' + chk.reason })
|
|
113
127
|
if (data.op !== 'terminal.hs' || typeof data.eph !== 'string') return send(from, { type: T.ERROR, error: 'handshake inválido' })
|
|
@@ -123,6 +137,7 @@ export async function startAgent (opts = {}) {
|
|
|
123
137
|
const { signature: ackSig } = await signWithDevice({ privateJwk: link.device.privateJwk, data: ack })
|
|
124
138
|
|
|
125
139
|
sessions.set(sid, { sid, key, term: null, from, exp: Date.now() + SESSION_TTL_MS })
|
|
140
|
+
audit('session-open', { sid: sid.slice(0, 8), device: (await pubkeyId(chk.device)).slice(0, 8).toUpperCase() })
|
|
126
141
|
send(from, { type: T.ACK, sid, ack, signature: ackSig, cert: link.cert })
|
|
127
142
|
if (!opts.quiet) console.log(`[terminal] sesión ${sid.slice(0, 8)} autorizada (device ${chk.device?.slice?.(0, 8) || '?'})`)
|
|
128
143
|
}
|
|
@@ -148,7 +163,7 @@ export async function startAgent (opts = {}) {
|
|
|
148
163
|
}
|
|
149
164
|
if (msg.type === 'input') return void s.term?.write(msg.data)
|
|
150
165
|
if (msg.type === 'resize') { try { s.term?.resize(msg.cols, msg.rows) } catch {}; return }
|
|
151
|
-
if (msg.type === 'close') { try { s.term?.kill() } catch {}; sessions.delete(p.sid); return }
|
|
166
|
+
if (msg.type === 'close') { try { s.term?.kill() } catch {}; sessions.delete(p.sid); audit('session-close', { sid: String(p.sid).slice(0, 8) }); return }
|
|
152
167
|
}
|
|
153
168
|
|
|
154
169
|
client.on('message', (from, payload) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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": {
|