@dotrino/terminal-agent 0.24.0 → 0.25.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/bin/terminal.js +15 -5
- package/index.js +13 -3
- 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/bin/terminal.js
CHANGED
|
@@ -435,13 +435,23 @@ function interactive (conn, first, dir) {
|
|
|
435
435
|
if (m.type === 'meta') { onInfo(m.console); return }
|
|
436
436
|
if (m.type === 'exit') {
|
|
437
437
|
// LA CERRÓ OTRA PANTALLA (el teléfono, la web, el panel de otra ventana): esta ventana no
|
|
438
|
-
// se va — nadie aquí pidió cerrarla, y cerrarla dejaba al usuario sin ventana
|
|
439
|
-
//
|
|
440
|
-
//
|
|
438
|
+
// se va — nadie aquí pidió cerrarla, y cerrarla dejaba al usuario sin ventana. Pasa a una
|
|
439
|
+
// consola que YA existe: primero una que no mire nadie; si todas se miran, la primera igual.
|
|
440
|
+
// Una NUEVA solo si la máquina se quedó sin ninguna (dueño, 2026-10-07: la misma regla que
|
|
441
|
+
// el panel de la web y de los teléfonos), y entonces se dice. Si la shell terminó sola
|
|
442
|
+
// (`exit`) o la cerró esta misma ventana, la ventana se cierra, como cualquier terminal.
|
|
441
443
|
if (m.closedBy === 'other') {
|
|
444
|
+
const closed = consoleId
|
|
442
445
|
consoleId = null
|
|
443
|
-
|
|
444
|
-
|
|
446
|
+
ready = false // lo que se teclee mientras tanto espera a la consola que venga
|
|
447
|
+
request(conn, { type: 'list' }, 'consoles').then((r) => {
|
|
448
|
+
if (r.type !== 'consoles') return // un `fail`: ya lo atendió el manejador de abajo
|
|
449
|
+
const rest = r.list.filter((c) => c.id !== closed)
|
|
450
|
+
const other = rest.find((c) => !c.watchers.length) || rest[0]
|
|
451
|
+
if (other) return switchTo({ type: 'attach', id: other.id })
|
|
452
|
+
switchTo({ type: 'open', cwd: first.cwd || path.resolve(process.cwd()) })
|
|
453
|
+
out.write(`\x1b[2m${t('Otra pantalla cerró esta consola. Esta es una nueva.', 'Another screen closed this console. This is a new one.')}\x1b[0m\r\n`)
|
|
454
|
+
})
|
|
445
455
|
return
|
|
446
456
|
}
|
|
447
457
|
finish(m.code || 0)
|
package/index.js
CHANGED
|
@@ -134,7 +134,7 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
134
134
|
if (msg.type === 'unlock') {
|
|
135
135
|
if (origin !== 'remote' || !gate) { session.send({ type: 'unlocked' }); return }
|
|
136
136
|
try {
|
|
137
|
-
if (gate.required()) gate.check(msg.code)
|
|
137
|
+
if (gate.required()) gate.check(msg.code, viewer.device)
|
|
138
138
|
unlocked = true
|
|
139
139
|
session.send({ type: 'unlocked' })
|
|
140
140
|
} catch (e) { fail(e.code || 'access-unreadable', e.message, e.retryMs ? { retryMs: e.retryMs } : {}) }
|
|
@@ -204,9 +204,19 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
204
204
|
export async function startAgent (opts = {}) {
|
|
205
205
|
const dir = opts.dir || dataDir()
|
|
206
206
|
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
207
|
let remote = null
|
|
208
|
+
// TRES CLAVES MAL SEGUIDAS DE UN MISMO APARATO: se reporta a la bóveda, que se lo pone en
|
|
209
|
+
// la mesa a quien aprueba (bloquear o ignorar). El freno local ya está puesto; esto es el
|
|
210
|
+
// aviso. Si no se puede reportar se dice: un aviso que no sale es un teléfono que no suena.
|
|
211
|
+
const gate = makeGate(dir, {
|
|
212
|
+
onIncident: ({ device, tries }) => {
|
|
213
|
+
if (!remote?.reportIncident) return
|
|
214
|
+
remote.reportIncident({ kind: 'bad-code', about: device, tries })
|
|
215
|
+
.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'}`) })
|
|
216
|
+
.catch((e) => console.error(`[terminal-agent] could not report the incident: ${e.message}`))
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
const local = await listenLocal({ dir, serve: (session) => serveSession(session, hub, { origin: 'local' }) })
|
|
210
220
|
let stopped = false
|
|
211
221
|
const startRemote = () => startRemoteAgent({
|
|
212
222
|
label: LABEL,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.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",
|