@dotrino/terminal-agent 0.2.3 → 0.2.6
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/bin/cli.js +12 -8
- package/index.js +5 -1
- package/link.js +11 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -34,19 +34,23 @@ datos en ${dataDir()} (override DOTRINO_TERMINAL_DIR)`)
|
|
|
34
34
|
try {
|
|
35
35
|
if (cmd === 'enroll') {
|
|
36
36
|
console.log('Enlazar esta máquina con tu vault.')
|
|
37
|
-
console.log('
|
|
38
|
-
|
|
37
|
+
console.log('El código lo generas en el CERTIFICADOR (tu vault). Hay dos formas:')
|
|
38
|
+
console.log(' · Sin vault externo → abre https://terminal.dotrino.com, elige')
|
|
39
|
+
console.log(' "Usar este dispositivo como bóveda" → "Enlazar otra máquina" y copia el código.')
|
|
40
|
+
console.log(' · Con vault en un PC → ahí corre `dotrino-vault pair` y copia el QR/JSON.\n')
|
|
41
|
+
const text = await ask('Pega el código y Enter:\n> ')
|
|
39
42
|
const qr = parseQr(text)
|
|
40
|
-
console.log('\nConectando
|
|
43
|
+
console.log('\nConectando…')
|
|
41
44
|
const link = await enroll({
|
|
42
45
|
qr,
|
|
43
46
|
dir: opt('--dir'),
|
|
44
47
|
label: opt('--label') || 'terminal-agent',
|
|
45
|
-
onChallenge: ({ deviceId,
|
|
46
|
-
console.log('\n
|
|
47
|
-
console.log(` código: ${
|
|
48
|
-
console.log(` máquina ${deviceId}`)
|
|
49
|
-
console.log(
|
|
48
|
+
onChallenge: ({ deviceId, code }) => {
|
|
49
|
+
console.log('\n Escribe ESTE código en tu bóveda para aprobar esta máquina:')
|
|
50
|
+
console.log(` código: ${code}`)
|
|
51
|
+
console.log(` máquina: ${deviceId}`)
|
|
52
|
+
console.log(' (en terminal.dotrino.com escríbelo en el campo y pulsa "Aprobar";')
|
|
53
|
+
console.log(` en el PC del vault: dotrino-vault approve ${code})\n`)
|
|
50
54
|
console.log(' Esperando aprobación…')
|
|
51
55
|
}
|
|
52
56
|
})
|
package/index.js
CHANGED
|
@@ -28,7 +28,8 @@ import { loadLink, dataDir } from './link.js'
|
|
|
28
28
|
const require = createRequire(import.meta.url)
|
|
29
29
|
|
|
30
30
|
const T = {
|
|
31
|
-
HS: 'terminal.hs', ACK: 'terminal.hs.ack', CMD: 'terminal.cmd', OUT: 'terminal.out', ERROR: 'terminal.error'
|
|
31
|
+
HS: 'terminal.hs', ACK: 'terminal.hs.ack', CMD: 'terminal.cmd', OUT: 'terminal.out', ERROR: 'terminal.error',
|
|
32
|
+
PING: 'terminal.ping', PONG: 'terminal.pong'
|
|
32
33
|
}
|
|
33
34
|
const VMSG = { DEVICES: 'vault.devices', DEVICES_RESULT: 'vault.devices.result' }
|
|
34
35
|
const SIGN_SCOPE = 'vault:sign'
|
|
@@ -170,6 +171,9 @@ export async function startAgent (opts = {}) {
|
|
|
170
171
|
if (!payload || typeof payload !== 'object') return
|
|
171
172
|
if (payload.type === T.HS) handleHandshake(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
|
|
172
173
|
else if (payload.type === T.CMD) handleCmd(from, payload).catch((e) => send(from, { type: T.ERROR, error: e.message }))
|
|
174
|
+
// Sonda de presencia (liveness): el cliente hace ping y respondemos pong con el
|
|
175
|
+
// mismo nonce → así la app sabe que esta máquina está online (sin abrir sesión).
|
|
176
|
+
else if (payload.type === T.PING) send(from, { type: T.PONG, n: payload.n })
|
|
173
177
|
})
|
|
174
178
|
|
|
175
179
|
if (!opts.quiet) {
|
package/link.js
CHANGED
|
@@ -13,7 +13,7 @@ import fs from 'node:fs'
|
|
|
13
13
|
import path from 'node:path'
|
|
14
14
|
import os from 'node:os'
|
|
15
15
|
import {
|
|
16
|
-
makeDeviceKey, signWithDevice, verifyDelegation,
|
|
16
|
+
makeDeviceKey, signWithDevice, verifyDelegation, makePairingCode, pubkeyId
|
|
17
17
|
} from '@dotrino/identity/capabilities'
|
|
18
18
|
import { installNodeGlobals } from './node-globals.js'
|
|
19
19
|
|
|
@@ -58,22 +58,28 @@ async function freshClient (proxyUrl, dir) {
|
|
|
58
58
|
/**
|
|
59
59
|
* Enrola esta máquina contra el vault del QR. Devuelve y persiste
|
|
60
60
|
* `{ device, cert, iss, proxy, label }`.
|
|
61
|
-
* @param {(c:{deviceId:string,
|
|
61
|
+
* @param {(c:{deviceId:string,code:string})=>void} onChallenge mostrar el CÓDIGO para que un humano lo TIPEE en la bóveda al aprobar (el código NO viaja de aquí)
|
|
62
62
|
*/
|
|
63
63
|
export async function enroll ({ qr, label = 'terminal-agent', dir = dataDir(), onChallenge, timeoutMs = 180000 } = {}) {
|
|
64
64
|
const client = await freshClient(qr.proxy, dir)
|
|
65
65
|
try {
|
|
66
66
|
const device = await makeDeviceKey({ label })
|
|
67
67
|
const deviceId = (await pubkeyId(device.publickey)).slice(0, 8).toUpperCase().replace(/(.{4})(.{4})/, '$1-$2')
|
|
68
|
-
|
|
68
|
+
// Código de emparejamiento ALEATORIO (un secreto, NO derivable de valores públicos):
|
|
69
|
+
// lo mostramos y NO lo enviamos. La bóveda lo aprende solo cuando un humano lo tipea
|
|
70
|
+
// y nos lo ECHA de vuelta → así aprobar exige TENER esta máquina (de aquí sale el código).
|
|
71
|
+
const code = makePairingCode()
|
|
69
72
|
const data = { op: 'enroll', dpub: device.publickey, token: qr.token, sn: qr.sn, label, ts: Date.now() }
|
|
70
73
|
const { signature } = await signWithDevice({ privateJwk: device.privateJwk, data })
|
|
71
74
|
|
|
72
75
|
const done = new Promise((resolve, reject) => {
|
|
73
76
|
const off = client.on('message', (_from, p) => {
|
|
74
77
|
if (!p || typeof p !== 'object') return
|
|
75
|
-
if (p.type === MSG.ENROLL_CHALLENGE) onChallenge?.({ deviceId,
|
|
76
|
-
|
|
78
|
+
if (p.type === MSG.ENROLL_CHALLENGE) onChallenge?.({ deviceId, code })
|
|
79
|
+
// Aceptamos SOLO si el código echado coincide con el que generamos (anti
|
|
80
|
+
// aprobación-a-ciegas / bóveda impostora). Un eco distinto se IGNORA y seguimos
|
|
81
|
+
// esperando la aprobación correcta (o el timeout).
|
|
82
|
+
else if (p.type === MSG.ENROLLED) { if (String(p.code || '').trim() === code) { cleanup(); resolve(p) } }
|
|
77
83
|
else if (p.type === MSG.ERROR) { cleanup(); reject(new Error(p.error)) }
|
|
78
84
|
})
|
|
79
85
|
const t = setTimeout(() => { cleanup(); reject(new Error('timeout esperando la aprobación en el vault')) }, timeoutMs)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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": {
|