@dotrino/remote-agent 0.9.1 → 0.10.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 +0 -0
- package/e2e.js +0 -0
- package/index.js +0 -0
- package/node-globals.js +0 -0
- package/package.json +7 -7
- package/protocol.js +0 -0
- package/src/agent.js +12 -17
- package/src/client.js +2 -3
- package/src/discover.js +3 -3
- package/src/link.js +6 -13
package/README.md
CHANGED
|
File without changes
|
package/e2e.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
package/node-globals.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/remote-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"p2p"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@dotrino/identity": ">=0.
|
|
49
|
-
"@dotrino/proxy-client": ">=0.
|
|
50
|
-
"@dotrino/vault": ">=0.
|
|
48
|
+
"@dotrino/identity": ">=0.92.0",
|
|
49
|
+
"@dotrino/proxy-client": ">=0.18.2",
|
|
50
|
+
"@dotrino/vault": ">=0.64.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@dotrino/identity": "0.
|
|
54
|
-
"@dotrino/proxy-client": "0.
|
|
55
|
-
"@dotrino/vault": "0.
|
|
53
|
+
"@dotrino/identity": "0.92.0",
|
|
54
|
+
"@dotrino/proxy-client": "0.18.2",
|
|
55
|
+
"@dotrino/vault": "0.64.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/protocol.js
CHANGED
|
File without changes
|
package/src/agent.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import fs from 'node:fs'
|
|
23
23
|
import path from 'node:path'
|
|
24
|
-
import { verifyChain, signWithDevice, verifyDeviceSig,
|
|
25
|
-
import { sealersOf, memberCan } from '@dotrino/identity/acta'
|
|
24
|
+
import { verifyChain, signWithDevice, verifyDeviceSig, pubkeyId } from '@dotrino/identity/capabilities'
|
|
25
|
+
import { sealersOf, memberCan, checkVaultReply } from '@dotrino/identity/acta'
|
|
26
26
|
import { installNodeGlobals } from '../node-globals.js'
|
|
27
27
|
import { makeEphemeral, deriveKey, seal, open } from '../e2e.js'
|
|
28
28
|
import { HS, ACK, DATA, PING, PONG, ERROR, VMSG, SIGN_SCOPE, SESSION_TTL_MS, REVOKE_REFRESH_MS } from '../protocol.js'
|
|
@@ -111,9 +111,8 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
111
111
|
// Identificarse bajo la pubkey de ESTA máquina (firmado con su D).
|
|
112
112
|
const identify = async () => {
|
|
113
113
|
if (!client.token) return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await client.identify({ data, signature })
|
|
114
|
+
// El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
|
|
115
|
+
await client.identifyAs({ publickey: myPub, sign: (d) => signWithDevice({ privateJwk: link.device.privateJwk, data: d }) })
|
|
117
116
|
}
|
|
118
117
|
await identify()
|
|
119
118
|
client.on('token', () => { identify().catch(() => {}) })
|
|
@@ -192,14 +191,10 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
192
191
|
const res = await vaultRpc(VMSG.RENEW, VMSG.RENEWED, { op: 'renew', publickey: myPub, ts: Date.now() })
|
|
193
192
|
const cert = res?.cert
|
|
194
193
|
const acta = res?.acta
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
cert, expectedSub: myPub, expectedScope: SIGN_SCOPE,
|
|
200
|
-
actaSeq: acta.seq, sealers: sealersOf(acta)
|
|
201
|
-
})
|
|
202
|
-
if (!v.ok) throw new Error(v.reason)
|
|
194
|
+
// La regla del pilar, contra la bóveda a la que se le pidió (`master`). Aquí se exigía
|
|
195
|
+
// `acta.profileId === master`, que con una segunda bóveda nunca es verdad.
|
|
196
|
+
const chk = await checkVaultReply({ acta, cert, vault: master, sub: myPub, scope: SIGN_SCOPE })
|
|
197
|
+
if (!chk.ok) throw new Error('invalid renewed cert: ' + chk.reason)
|
|
203
198
|
link.cert = cert
|
|
204
199
|
link.actaSeq = acta.seq
|
|
205
200
|
saveLink(dir, link)
|
|
@@ -259,21 +254,21 @@ export async function startRemoteAgent (opts = {}) {
|
|
|
259
254
|
const chk = await verifyChain({ data, signature, cert, expectedScope: SIGN_SCOPE, ...contextoActa(), revoked: revokedSet })
|
|
260
255
|
if (!chk.ok) return send(from, { type: ERROR, error: 'no autorizado: ' + chk.reason })
|
|
261
256
|
// CERT ∩ ACTA. `verifyChain` comprueba QUIÉN EMITIÓ el papel; que el APARATO siga siendo
|
|
262
|
-
//
|
|
257
|
+
// isMember y pueda firmar lo dice el acta, y hay que preguntárselo aparte. Sin esto, un
|
|
263
258
|
// papel bien firmado por una selladora abría sesión aunque el acta no nombrara a ese
|
|
264
259
|
// aparato — o ya no lo nombrara. Bajo el modelo viejo daba igual, porque el papel ERA la
|
|
265
260
|
// autoridad y caducaba; con el papel atado al acta, el acta tiene que decidir.
|
|
266
261
|
//
|
|
267
262
|
// SE PREGUNTA POR EL PERMISO, NO POR «FIRMA POR LA PERSONA». Aquí se usaba
|
|
268
|
-
// `memberCanSign`, que a un
|
|
263
|
+
// `memberCanSign`, que a un isMember CON `cn` le dice que no salvo que se le nombre su
|
|
269
264
|
// cajón — y con razón: un servicio habla por la bóveda, no por su dueño. Pero eso es la
|
|
270
265
|
// pregunta de OTRO mostrador. Lo que pasa aquí es un saludo, y lo que prueba es «soy
|
|
271
266
|
// este aparato», no «hablo por ti»: exigirle lo segundo dejaba a TODO servicio sin poder
|
|
272
267
|
// abrir sesión con otro agente. El bot social se pasó así el 1 de septiembre, con un
|
|
273
268
|
// node de contenido encendido a su lado que le contestaba «ese aparato no firma por este
|
|
274
269
|
// perfil». Se le pide lo que corresponde: que el acta lo nombre y le reconozca `sign`.
|
|
275
|
-
const
|
|
276
|
-
if (!
|
|
270
|
+
const isMember = (link.acta?.members || []).some((m) => m?.pub === chk.device)
|
|
271
|
+
if (!isMember || !memberCan(link.acta, chk.device, 'sign')) {
|
|
277
272
|
return send(from, { type: ERROR, error: 'no autorizado: acta — este perfil no reconoce a ese aparato' })
|
|
278
273
|
}
|
|
279
274
|
if (data.op !== HS || typeof data.eph !== 'string') return send(from, { type: ERROR, error: 'handshake inválido' })
|
package/src/client.js
CHANGED
|
@@ -82,9 +82,8 @@ export class RemoteAgentClient {
|
|
|
82
82
|
const { id, cert } = this.link
|
|
83
83
|
const publickey = id.me?.publickey
|
|
84
84
|
if (!publickey) return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await this.client.identify({ data, signature, cert })
|
|
85
|
+
// El sobre lo arma el pilar (`identifyAs`), que le pone el destinatario.
|
|
86
|
+
await this.client.identifyAs({ publickey, sign: (d) => id.signData(d), cert })
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
async connect () {
|
package/src/discover.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
/**
|
|
25
25
|
* @param {object} id instancia de Identity (del vault) ya conectada.
|
|
26
26
|
* @param {string} [label] filtrar por servicio/label exacto (p. ej. `'content'`,
|
|
27
|
-
* `'ia-agent'`). Omitir = todos los que tengan
|
|
27
|
+
* `'ia-agent'`). Omitir = todos los que tengan nameOf y no sean `'cli'` (un navegador
|
|
28
28
|
* enrolado queda como `cli` y no atiende a nadie).
|
|
29
29
|
* @returns {Promise<Array<{sub:string,label:string,cn:string|null}>>} uno por miembro.
|
|
30
30
|
*/
|
|
@@ -37,10 +37,10 @@ export async function listAgentsByLabel (id, label) {
|
|
|
37
37
|
if (!acta) return []
|
|
38
38
|
|
|
39
39
|
const mine = id.me?.publickey
|
|
40
|
-
const
|
|
40
|
+
const nameOf = (m) => m.cn || m.label || null
|
|
41
41
|
return (acta.members || [])
|
|
42
42
|
.filter((m) => m?.pub && m.pub !== mine)
|
|
43
|
-
.filter((m) => (label ?
|
|
43
|
+
.filter((m) => (label ? nameOf(m) === label : (nameOf(m) && nameOf(m) !== 'cli')))
|
|
44
44
|
.map((m) => ({ sub: m.pub, label: m.label || m.cn || '', cn: m.cn || null }))
|
|
45
45
|
}
|
|
46
46
|
|
package/src/link.js
CHANGED
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
import fs from 'node:fs'
|
|
17
17
|
import path from 'node:path'
|
|
18
18
|
import os from 'node:os'
|
|
19
|
-
import { signWithDevice, pubkeyId
|
|
20
|
-
import { sealersOf } from '@dotrino/identity/acta'
|
|
19
|
+
import { signWithDevice, pubkeyId } from '@dotrino/identity/capabilities'
|
|
21
20
|
import { requestDevices, requestRenew } from '@dotrino/identity/vault/remote.js'
|
|
22
21
|
import { installNodeGlobals } from '../node-globals.js'
|
|
23
22
|
|
|
@@ -169,17 +168,11 @@ export async function renewLink (link, { dir = dataDir(), force = false } = {})
|
|
|
169
168
|
if (!force && !legado && !atrasado) return { renewed: false, seq: link.cert.seq, reason: 'not due' }
|
|
170
169
|
installNodeGlobals(dir)
|
|
171
170
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// SELLADORA de este perfil. Ya no se compara `cert.iss` con una llave fija — con varias
|
|
178
|
-
// bóvedas el emisor puede ser otra del mismo perfil; lo que se fija es el PERFIL.
|
|
179
|
-
if (!acta) throw new Error('the vault did not send its record: cannot check who signed this cert')
|
|
180
|
-
if (acta.profileId !== link.iss) throw new Error('the record is from a profile other than the pinned one')
|
|
181
|
-
const v = await verifyDelegation({ cert, expectedSub: link.device.publickey, actaSeq: acta.seq, sealers: sealersOf(acta) })
|
|
182
|
-
if (!v.ok) throw new Error(v.reason)
|
|
171
|
+
// `requestRenew` ya JUZGA lo que devuelve (`checkVaultReply` del pilar: acta bien
|
|
172
|
+
// firmada, esta bóveda puede sellarla, el papel lo firmó ella y es para esta llave) y
|
|
173
|
+
// lanza si no cuadra. Aquí se comparaba `acta.profileId` con `link.iss`, que solo vale
|
|
174
|
+
// en una cuenta que nació en esa bóveda: con una segunda bóveda no renovaba nunca.
|
|
175
|
+
const { cert, acta } = await requestRenew({ master: link.iss, proxy: link.proxy || 'wss://proxy.dotrino.com', device: link.device, cert: link.cert })
|
|
183
176
|
// SE GUARDA ANTES DE DAR NADA POR BUENO. Emitir un papel RETIRA el anterior, así que si
|
|
184
177
|
// esto no se persiste la máquina se queda usando uno revocado y fuera para siempre. Le
|
|
185
178
|
// pasó al registro de selladores en la migración, y por eso está dicho aquí.
|