@dotrino/terminal-agent 0.24.1 → 0.26.0
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/README.md +5 -0
- package/access.js +27 -8
- package/consoles.js +27 -2
- package/index.js +20 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,6 +80,11 @@ dotrino-terminal lock --status [--name <perfil>] # dice si hay
|
|
|
80
80
|
En la app de escritorio: menú **Perfil → Poner o cambiar la clave… / Quitar la clave**.
|
|
81
81
|
|
|
82
82
|
- Es **del perfil**: todas sus consolas comparten la misma clave.
|
|
83
|
+
- A los **tres fallos seguidos** toca esperar, cada vez más (freno local de este agente). Y si un
|
|
84
|
+
mismo aparato falla tres veces seguidas, el agente **reporta el incidente a la bóveda**
|
|
85
|
+
(`reportIncident` de `@dotrino/remote-agent` ≥ 0.16.0): los aparatos que aprueban lo ven y
|
|
86
|
+
eligen bloquear o ignorar. Bloqueado, no entra en ningún agente ni en la bóveda hasta
|
|
87
|
+
`dotrino-vault unblock <ID>`.
|
|
83
88
|
- La piden **solo los otros aparatos** (web, teléfono). Las ventanas de esta máquina no.
|
|
84
89
|
- Vale **al momento**, sin reiniciar el agente: quien ya estaba dentro tiene que escribirla
|
|
85
90
|
en lo siguiente que haga.
|
package/access.js
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
* sesión cifrada entre el aparato y el agente, así que el proxio no la ve.
|
|
11
11
|
*
|
|
12
12
|
* Los fallos se frenan POR AGENTE y no por sesión: quien prueba claves puede abrir otra
|
|
13
|
-
* conexión, y eso no le da intentos nuevos.
|
|
13
|
+
* conexión, y eso no le da intentos nuevos. A los TRES seguidos (dueño, 2026-10-07) empieza
|
|
14
|
+
* la espera, que se dobla con cada fallo más: es un bloqueo LOCAL de este servicio, nada más.
|
|
15
|
+
*
|
|
16
|
+
* Y a los tres fallos seguidos de UN MISMO aparato se avisa (`onIncident`): la bóveda se lo
|
|
17
|
+
* pone en la mesa a quien aprueba, que bloquea o ignora desde el teléfono. Avisar no decide
|
|
18
|
+
* nada aquí; el freno de arriba sigue igual.
|
|
14
19
|
*/
|
|
15
20
|
import crypto from 'node:crypto'
|
|
16
21
|
import fs from 'node:fs'
|
|
@@ -18,8 +23,10 @@ import path from 'node:path'
|
|
|
18
23
|
|
|
19
24
|
export const ACCESS_FILE = 'access.json'
|
|
20
25
|
export const MIN_LENGTH = 4
|
|
21
|
-
/** Fallos seguidos que se dejan pasar sin esperar. */
|
|
22
|
-
export const FREE_TRIES =
|
|
26
|
+
/** Fallos seguidos que se dejan pasar sin esperar: al tercero empieza la espera. */
|
|
27
|
+
export const FREE_TRIES = 3
|
|
28
|
+
/** Fallos seguidos de un mismo aparato que disparan el aviso a la bóveda. */
|
|
29
|
+
export const INCIDENT_AFTER = 3
|
|
23
30
|
const BASE_WAIT_MS = 30_000
|
|
24
31
|
const MAX_WAIT_MS = 60 * 60_000
|
|
25
32
|
const SCRYPT = { N: 1 << 15, r: 8, p: 1, maxmem: 64 * 1024 * 1024 }
|
|
@@ -75,21 +82,33 @@ export function checkAccessCode (dir, secret) {
|
|
|
75
82
|
* La puerta de un agente: comprueba la clave y frena los fallos seguidos. Una por agente,
|
|
76
83
|
* compartida por todas sus sesiones.
|
|
77
84
|
* @param {string} dir
|
|
78
|
-
* @param {{ now?: () => number }} [opts]
|
|
85
|
+
* @param {{ now?: () => number, onIncident?: (i: { device: string, tries: number }) => void }} [opts]
|
|
86
|
+
* `onIncident`: un mismo aparato (`device`, su pubkey) falló `INCIDENT_AFTER` veces seguidas.
|
|
87
|
+
* Se llama UNA vez por racha; la racha se corta al acertar.
|
|
79
88
|
*/
|
|
80
|
-
export function makeGate (dir, { now = Date.now } = {}) {
|
|
89
|
+
export function makeGate (dir, { now = Date.now, onIncident = null } = {}) {
|
|
81
90
|
let fails = 0
|
|
82
91
|
let until = 0
|
|
92
|
+
/** Fallos seguidos por aparato: el aviso es sobre QUIÉN, y el freno sobre el agente. */
|
|
93
|
+
const byDevice = new Map()
|
|
83
94
|
return {
|
|
84
95
|
/** Si hay que escribir la clave para entrar. Lanza `access-unreadable` si no se puede saber. */
|
|
85
96
|
required: () => hasAccessCode(dir),
|
|
86
|
-
/**
|
|
87
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Lanza `wait` (con `retryMs`) o `bad-code`; si no lanza, la clave era la buena.
|
|
99
|
+
* `device` es quién la escribió (pubkey), para contar sus fallos y avisar.
|
|
100
|
+
*/
|
|
101
|
+
check (secret, device = null) {
|
|
88
102
|
const left = until - now()
|
|
89
103
|
if (left > 0) throw fail('wait', 'too many wrong codes', { retryMs: left })
|
|
90
|
-
if (checkAccessCode(dir, secret)) { fails = 0; until = 0; return }
|
|
104
|
+
if (checkAccessCode(dir, secret)) { fails = 0; until = 0; if (device) byDevice.delete(device); return }
|
|
91
105
|
fails++
|
|
92
106
|
if (fails >= FREE_TRIES) until = now() + Math.min(BASE_WAIT_MS * 2 ** (fails - FREE_TRIES), MAX_WAIT_MS)
|
|
107
|
+
if (device) {
|
|
108
|
+
const n = (byDevice.get(device) || 0) + 1
|
|
109
|
+
byDevice.set(device, n)
|
|
110
|
+
if (n === INCIDENT_AFTER && onIncident) { try { onIncident({ device, tries: n }) } catch (_) {} }
|
|
111
|
+
}
|
|
93
112
|
throw fail('bad-code', 'wrong code', until ? { retryMs: until - now() } : {})
|
|
94
113
|
}
|
|
95
114
|
}
|
package/consoles.js
CHANGED
|
@@ -310,13 +310,38 @@ export class ConsoleHub {
|
|
|
310
310
|
c.viewers.clear()
|
|
311
311
|
try { c.screen.dispose() } catch (_) {}
|
|
312
312
|
})
|
|
313
|
-
|
|
313
|
+
// DÓNDE va en el panel: mientras nadie haya movido nada (están por número), en su sitio por
|
|
314
|
+
// número; si alguien las ordenó a mano, al final, para no deshacerle el orden.
|
|
315
|
+
const all = [...this.consoles.values()]
|
|
316
|
+
const byNumber = all.every((x, i) => i === 0 || all[i - 1].n < x.n)
|
|
317
|
+
const at = byNumber ? all.findIndex((x) => x.n > n) : -1
|
|
318
|
+
if (at === -1) all.push(c); else all.splice(at, 0, c)
|
|
319
|
+
this._order(all)
|
|
314
320
|
return c
|
|
315
321
|
}
|
|
316
322
|
|
|
323
|
+
_order (all) { this.consoles = new Map(all.map((c) => [c.id, c])) }
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* El ORDEN del panel, el mismo en todas las ventanas y aparatos: la consola `id` pasa a estar
|
|
327
|
+
* justo antes de `before` (o al final, con `null` o con una que ya no existe). No cambia su
|
|
328
|
+
* número, que es fijo. `false` si esa consola ya no existe.
|
|
329
|
+
*/
|
|
330
|
+
move (id, before = null) {
|
|
331
|
+
const c = this.consoles.get(id)
|
|
332
|
+
if (!c) return false
|
|
333
|
+
if (before === id) return true
|
|
334
|
+
const all = [...this.consoles.values()].filter((x) => x !== c)
|
|
335
|
+
const at = before == null ? -1 : all.findIndex((x) => x.id === before)
|
|
336
|
+
if (at === -1) all.push(c); else all.splice(at, 0, c)
|
|
337
|
+
this._order(all)
|
|
338
|
+
return true
|
|
339
|
+
}
|
|
340
|
+
|
|
317
341
|
get (id) { return this.consoles.get(id) || null }
|
|
318
342
|
|
|
319
|
-
|
|
343
|
+
/** Las consolas, en el orden del panel (por número hasta que alguien las mueve: `move`). */
|
|
344
|
+
list () { return [...this.consoles.values()].map((c) => c.info()) }
|
|
320
345
|
|
|
321
346
|
/** Cierra una consola. `by`: la pantalla (viewer) que lo pide, para decirle a las DEMÁS que no fueron ellas. */
|
|
322
347
|
kill (id, by = null) {
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* { type:'attach', id, cols, rows } · { type:'detach' } ·
|
|
15
15
|
* { type:'input', data } · { type:'resize', cols, rows } · { type:'pin', on } ·
|
|
16
16
|
* { type:'close' } (mata la consola enganchada) · { type:'kill', id } ·
|
|
17
|
+
* { type:'move', id, before? } (el orden del panel; contesta con `consoles`) ·
|
|
17
18
|
* { type:'unlock', code } (la clave de la máquina, si tiene: access.js)
|
|
18
19
|
* agente → cliente: { type:'consoles', list } · { type:'attached', id, fresh } ·
|
|
19
20
|
* { type:'replay', id, data, last } · { type:'out', data } ·
|
|
@@ -134,7 +135,7 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
134
135
|
if (msg.type === 'unlock') {
|
|
135
136
|
if (origin !== 'remote' || !gate) { session.send({ type: 'unlocked' }); return }
|
|
136
137
|
try {
|
|
137
|
-
if (gate.required()) gate.check(msg.code)
|
|
138
|
+
if (gate.required()) gate.check(msg.code, viewer.device)
|
|
138
139
|
unlocked = true
|
|
139
140
|
session.send({ type: 'unlocked' })
|
|
140
141
|
} catch (e) { fail(e.code || 'access-unreadable', e.message, e.retryMs ? { retryMs: e.retryMs } : {}) }
|
|
@@ -174,7 +175,12 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
174
175
|
// ⤢ «Esta pantalla manda en el tamaño» (on) o soltarlo (off).
|
|
175
176
|
if (msg.type === 'pin') { current?.pin(viewer, !!msg.on); return }
|
|
176
177
|
if (msg.type === 'close') { if (current) hub.kill(current.id, viewer); return }
|
|
177
|
-
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists') }
|
|
178
|
+
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists'); return }
|
|
179
|
+
// El orden del panel: es de la máquina, así que lo ve igual cualquier pantalla.
|
|
180
|
+
if (msg.type === 'move') {
|
|
181
|
+
if (!hub.move(String(msg.id), msg.before == null ? null : String(msg.before))) return fail('no-console', 'that console no longer exists')
|
|
182
|
+
session.send({ type: 'consoles', list: hub.list() })
|
|
183
|
+
}
|
|
178
184
|
})
|
|
179
185
|
session.on('close', () => {
|
|
180
186
|
const mine = owned && owned === current ? owned : null
|
|
@@ -204,9 +210,19 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
204
210
|
export async function startAgent (opts = {}) {
|
|
205
211
|
const dir = opts.dir || dataDir()
|
|
206
212
|
const hub = makeHub(loadPty(), { ...opts, dir })
|
|
207
|
-
const gate = makeGate(dir)
|
|
208
|
-
const local = await listenLocal({ dir, serve: (session) => serveSession(session, hub, { origin: 'local' }) })
|
|
209
213
|
let remote = null
|
|
214
|
+
// TRES CLAVES MAL SEGUIDAS DE UN MISMO APARATO: se reporta a la bóveda, que se lo pone en
|
|
215
|
+
// la mesa a quien aprueba (bloquear o ignorar). El freno local ya está puesto; esto es el
|
|
216
|
+
// aviso. Si no se puede reportar se dice: un aviso que no sale es un teléfono que no suena.
|
|
217
|
+
const gate = makeGate(dir, {
|
|
218
|
+
onIncident: ({ device, tries }) => {
|
|
219
|
+
if (!remote?.reportIncident) return
|
|
220
|
+
remote.reportIncident({ kind: 'bad-code', about: device, tries })
|
|
221
|
+
.then((r) => { if (!opts.quiet) console.log(`[terminal-agent] incident reported: ${r.id ? `request ${r.id} to ${r.approvers} approver(s)` : r.blocked ? 'that device is already blocked' : 'nobody can approve, nothing asked'}`) })
|
|
222
|
+
.catch((e) => console.error(`[terminal-agent] could not report the incident: ${e.message}`))
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
const local = await listenLocal({ dir, serve: (session) => serveSession(session, hub, { origin: 'local' }) })
|
|
210
226
|
let stopped = false
|
|
211
227
|
const startRemote = () => startRemoteAgent({
|
|
212
228
|
label: LABEL,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Dotrino Terminal: las ventanas de esta máquina (dotrino-terminal) y su agente, que deja abrir esas mismas consolas desde los otros aparatos de tu cuenta, cifrado punto a punto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@dotrino/identity": "0.107.2",
|
|
30
30
|
"@dotrino/proxy-client": "0.29.0",
|
|
31
|
-
"@dotrino/remote-agent": "0.
|
|
31
|
+
"@dotrino/remote-agent": "0.16.0",
|
|
32
32
|
"@dotrino/update": "0.2.2",
|
|
33
33
|
"@dotrino/vault": "0.79.0",
|
|
34
34
|
"@xterm/addon-serialize": "0.13.0",
|