@dotrino/remote-agent 0.29.0 → 0.31.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 +8 -0
- package/package.json +5 -5
- package/src/client.js +22 -3
- package/src/link.js +44 -5
package/README.md
CHANGED
|
@@ -107,6 +107,14 @@ parámetros (`{ ns, proxyUrl: link.proxy, masterPubkey: link.iss, device, cert,
|
|
|
107
107
|
Un agente que corre UNA vez (un bot por cron) no tiene el tic de renovación de
|
|
108
108
|
`startRemoteAgent`: que llame a `renewLink(link)` en cada corrida, o su cert muere a los 30 días.
|
|
109
109
|
|
|
110
|
+
### El enlace va cifrado en reposo
|
|
111
|
+
|
|
112
|
+
`saveLink` escribe `link.json` cifrado con `@dotrino/vault/atrest` (≥ 0.115.0), el mismo
|
|
113
|
+
cifrado de la bóveda: una clave sacada de esta máquina, así que el archivo copiado a otro
|
|
114
|
+
equipo no sirve. `loadLink` reescribe cifrado un enlace en claro de una versión anterior.
|
|
115
|
+
Si el enlace existe y no se puede abrir, **lanza** `link-unreadable`: `null` es solo «no
|
|
116
|
+
hay enlace». No protege contra quien ya entra a esta máquina como tu usuario.
|
|
117
|
+
|
|
110
118
|
### Sin bóveda: identidad propia (`selfLink`)
|
|
111
119
|
|
|
112
120
|
Un agente no tiene por qué exigir una bóveda. `selfLink({ label, dir })` crea las llaves
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/remote-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Middleware compartido del ecosistema Dotrino para apps de agente remoto cifrado punto a punto (handshake E2E, emparejamiento SAS con vault, revocación, descubrimiento). Lo consumen dotrino-terminal (PTY) y dotrino-ia (chat con IA).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@dotrino/identity": ">=0.121.7",
|
|
52
52
|
"@dotrino/proxy-client": ">=0.36.1",
|
|
53
|
-
"@dotrino/vault": ">=0.
|
|
53
|
+
"@dotrino/vault": ">=0.115.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@dotrino/identity": "0.
|
|
57
|
-
"@dotrino/proxy-client": "0.
|
|
58
|
-
"@dotrino/vault": "0.
|
|
56
|
+
"@dotrino/identity": "0.135.0",
|
|
57
|
+
"@dotrino/proxy-client": "0.45.3",
|
|
58
|
+
"@dotrino/vault": "0.115.0"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/src/client.js
CHANGED
|
@@ -34,9 +34,14 @@ export class RemoteAgentClient {
|
|
|
34
34
|
* @param {object} opts
|
|
35
35
|
* @param {string} opts.agentPubkey dirección (pubkey) del agente destino.
|
|
36
36
|
* @param {string} [opts.proxyUrl] override del proxy del enlace.
|
|
37
|
+
* @param {() => object|null} [opts.trustedActa] un acta ya COMPROBADA y que alguien mantiene
|
|
38
|
+
* al día (un agente de Node: la de su enlace, que refresca cada 5 min y con los avisos de la
|
|
39
|
+
* bóveda). Con ella el saludo no espera a la bóveda; si no pasa, se le pregunta y se juzga
|
|
40
|
+
* otra vez. Sin ella, la bóveda en cada saludo, como siempre.
|
|
37
41
|
*/
|
|
38
|
-
constructor (link, { agentPubkey, proxyUrl } = {}) {
|
|
42
|
+
constructor (link, { agentPubkey, proxyUrl, trustedActa = null } = {}) {
|
|
39
43
|
this.link = link // { id, cert, iss, proxy, mode? }
|
|
44
|
+
this.trustedActa = trustedActa
|
|
40
45
|
this.agentPubkey = agentPubkey // pubkey del agente destino
|
|
41
46
|
this.proxyUrl = proxyUrl || link.proxy || DEFAULT_PROXY
|
|
42
47
|
this.client = null
|
|
@@ -193,6 +198,21 @@ export class RemoteAgentClient {
|
|
|
193
198
|
|
|
194
199
|
/** Comprueba el ack y deja `sid` y `key`. */
|
|
195
200
|
async _checkAck (res, eph) {
|
|
201
|
+
// PRIMERO EL ACTA QUE YA SE TIENE (`trustedActa`), y la bóveda solo si con esa no pasa.
|
|
202
|
+
// Preguntarle en cada saludo hacía esperar a la ventana 4-17 s antes de pedir la clave de
|
|
203
|
+
// otra máquina (2026-11-04): el ack llega en medio segundo, el acta tardaba el resto. Si
|
|
204
|
+
// no pasa puede ser que el acta guardada vaya atrás (una máquina recién emparejada): se
|
|
205
|
+
// pregunta a la bóveda y se juzga otra vez, una sola, como hace el agente con un saludo.
|
|
206
|
+
let local = null
|
|
207
|
+
try { local = this.trustedActa?.() || null } catch (_) {}
|
|
208
|
+
if (local) {
|
|
209
|
+
try { return await this._judgeAck(res, eph, local) } catch (e) { if (e.code !== 'unauthorized') throw e }
|
|
210
|
+
}
|
|
211
|
+
return this._judgeAck(res, eph, await this._acta())
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Juzga el ack con `acta` y, si pasa, deja `sid` y `key`. */
|
|
215
|
+
async _judgeAck (res, eph, acta) {
|
|
196
216
|
|
|
197
217
|
// El ack debe: (1) encadenar a NUESTRA maestra, (2) estar firmado por el agente
|
|
198
218
|
// que apuntamos, (3) atar nuestra pub efímera y el sid.
|
|
@@ -203,8 +223,7 @@ export class RemoteAgentClient {
|
|
|
203
223
|
// decir «vale» sin haber comprobado nada es como entraba un papel viejo. Aquí no se le
|
|
204
224
|
// pasaba: el lado del agente sí lo hacía (`contextoActa`) y este lado se quedó atrás,
|
|
205
225
|
// así que TODA sesión moría con «el agente no está certificado por tu vault: no-record».
|
|
206
|
-
// `clientLink` no trae el acta, así que se le pide a la bóveda
|
|
207
|
-
const acta = await this._acta()
|
|
226
|
+
// `clientLink` no trae el acta, así que se le pide a la bóveda (`_acta`) o llega hecha.
|
|
208
227
|
const chk = await verifyChain({
|
|
209
228
|
data: res.ack, signature: res.signature, cert: res.cert,
|
|
210
229
|
actaSeq: acta?.seq ?? null, sealers: acta ? sealersOf(acta) : null
|
package/src/link.js
CHANGED
|
@@ -22,6 +22,9 @@ import { installNodeGlobals } from '../node-globals.js'
|
|
|
22
22
|
import { adoptRecord } from './record.js'
|
|
23
23
|
import { verifySealerChain, genesisActa, sealActa } from '@dotrino/identity/acta'
|
|
24
24
|
import { DEFAULT_PROXY, RENEW_BEFORE_MS } from '../protocol.js'
|
|
25
|
+
// Estático y no perezoso: `loadLink`/`saveLink` son síncronos y así siguen. Necesita
|
|
26
|
+
// @dotrino/vault >= 0.115.0 (la primera que exporta `atrest`).
|
|
27
|
+
import { atRestFor, isEncrypted } from '@dotrino/vault/atrest'
|
|
25
28
|
|
|
26
29
|
export function dataDir (name = 'dotrino-remote-agent') {
|
|
27
30
|
if (process.env.DOTRINO_REMOTE_AGENT_DIR) return process.env.DOTRINO_REMOTE_AGENT_DIR
|
|
@@ -31,15 +34,51 @@ export function dataDir (name = 'dotrino-remote-agent') {
|
|
|
31
34
|
|
|
32
35
|
const linkPath = (dir) => path.join(dir, 'link.json')
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
/*
|
|
38
|
+
* EL ENLACE VA CIFRADO EN REPOSO (0.30.0). Lleva la llave privada del aparato, y hasta aquí
|
|
39
|
+
* estaba en claro (0600): copiar el archivo bastaba para hacerse pasar por el aparato. Se cifra
|
|
40
|
+
* con `@dotrino/vault/atrest`, el mismo cifrado de la bóveda y de la identidad de un servicio:
|
|
41
|
+
* una clave sacada de esta máquina (`/etc/machine-id` + un salt de la carpeta), así que el
|
|
42
|
+
* archivo copiado a otro equipo no sirve. No protege contra quien ya entra a esta máquina
|
|
43
|
+
* como tu usuario; eso pediría un TPM o el llavero del sistema.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Lee el enlace persistido, o `null` si NO EXISTE. Un enlace en claro (anterior a 0.30.0) se
|
|
48
|
+
* lee y se reescribe cifrado en el acto, comprobando antes que se vuelve a leer igual.
|
|
49
|
+
*
|
|
50
|
+
* Si existe y no se puede leer —otro equipo, la máquina cambió, el archivo está roto— LANZA
|
|
51
|
+
* (`link-unreadable`). Devolver `null` diría «no hay enlace», y quien lo llama crearía otro
|
|
52
|
+
* encima del que ya era el aparato: la identidad se perdería en silencio.
|
|
53
|
+
*/
|
|
35
54
|
export function loadLink (dir = dataDir()) {
|
|
36
|
-
|
|
55
|
+
let text
|
|
56
|
+
try { text = fs.readFileSync(linkPath(dir), 'utf8') } catch (e) {
|
|
57
|
+
if (e?.code === 'ENOENT') return null
|
|
58
|
+
throw Object.assign(new Error(`cannot read the link (${linkPath(dir)}): ${e.message}`), { code: 'link-unreadable' })
|
|
59
|
+
}
|
|
60
|
+
const box = atRestFor(dir)
|
|
61
|
+
let link
|
|
62
|
+
try { link = JSON.parse(box.decrypt(text)) } catch (e) {
|
|
63
|
+
throw Object.assign(new Error(`cannot open the link (${linkPath(dir)}): it was encrypted on another machine, or the file is damaged. Enroll this device again.`), { code: 'link-unreadable', cause: e })
|
|
64
|
+
}
|
|
65
|
+
if (!isEncrypted(text)) writeEncrypted(dir, box, link)
|
|
66
|
+
return link
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function writeEncrypted (dir, box, link) {
|
|
70
|
+
const json = JSON.stringify(link, null, 2)
|
|
71
|
+
const blob = box.encrypt(json)
|
|
72
|
+
if (box.decrypt(blob) !== json) throw Object.assign(new Error('link: at-rest verification failed, nothing was written'), { code: 'link-unwritable' })
|
|
73
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
74
|
+
const tmp = linkPath(dir) + '.tmp'
|
|
75
|
+
fs.writeFileSync(tmp, blob, { mode: 0o600 })
|
|
76
|
+
fs.renameSync(tmp, linkPath(dir))
|
|
37
77
|
}
|
|
38
78
|
|
|
39
|
-
/** Persiste el enlace (0600). Exportada porque la RENOVACIÓN del cert lo reescribe. */
|
|
79
|
+
/** Persiste el enlace, cifrado (0600). Exportada porque la RENOVACIÓN del cert lo reescribe. */
|
|
40
80
|
export function saveLink (dir, link) {
|
|
41
|
-
|
|
42
|
-
fs.writeFileSync(linkPath(dir), JSON.stringify(link, null, 2), { mode: 0o600 })
|
|
81
|
+
writeEncrypted(dir, atRestFor(dir), link)
|
|
43
82
|
}
|
|
44
83
|
|
|
45
84
|
/**
|