@dotrino/identity 0.135.1 → 0.136.1
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/package.json +16 -3
- package/src/index.d.ts +86 -3
- package/types/acta.d.ts +652 -0
- package/types/assertion.d.ts +208 -0
- package/types/avatar.d.ts +11 -0
- package/types/capabilities.d.ts +188 -0
- package/types/content.d.ts +191 -0
- package/types/core.d.ts +1168 -0
- package/types/keyid.d.ts +12 -0
- package/types/machine.d.ts +54 -0
- package/types/peerSync.d.ts +33 -0
- package/types/remote.d.ts +181 -0
- package/types/session.d.ts +163 -0
- package/types/sessionFlow.d.ts +86 -0
- package/types/vaultSeal.d.ts +58 -0
- package/vault/acta.js +2 -2
- package/vault/core.js +22 -16
- package/vault/remote.js +54 -29
- package/vault/vaultSeal.js +126 -0
- package/vault/vendor/compat/VERSION.txt +1 -1
- package/vault/vendor/compat/advisory.js +58 -8
- package/vault/vendor/compat/index.js +57 -6
- package/vault/vendor/compat/ranges.js +12 -2
- package/vault/vendor/proxy-client/VERSION.txt +1 -1
- package/vault/vendor/proxy-client/client.js +41 -19
- package/vault/vendor/roadmap/manifests.js +23 -23
- package/vault/vendor/store/VERSION.txt +1 -1
- package/vault/vendor/vault/VERSION.txt +1 -1
- package/vault/vendor/vault/core/libVersion.js +1 -1
- package/vault/vendor/vault/core/transport.js +15 -3
- package/vault/vendor/vault/core/vault.js +71 -1
- package/vault/vendor/vault/protocol.js +25 -0
|
@@ -81,12 +81,16 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
|
|
|
81
81
|
// CON QUÉ SE ABRE LO QUE NOS SELLAN (`commKey.encKeypair`): sin esto la bóveda no podía
|
|
82
82
|
// recibir nada sellado, y una hermana cerrada no habría podido abrir los cajones que le
|
|
83
83
|
// manda la otra. El pilar anuncia la pública al identificarse con la llave de comunicación.
|
|
84
|
-
|
|
84
|
+
let enc = commKey?.pub?.() && typeof commKey.encKeypair === 'function'
|
|
85
85
|
? await commKey.encKeypair().catch((e) => { log('[vault] no transport encryption key: ' + e.message); return null })
|
|
86
86
|
: null
|
|
87
|
-
|
|
87
|
+
// Y A QUIEN CREA EL CLIENTE TAMBIÉN se le pasa (la extensión, la pestaña): sin esto una bóveda
|
|
88
|
+
// de navegador no anunciaba llave de cifrado, y lo que sus aparatos le sellan
|
|
89
|
+
// (`docs/sealed-requests.md`) no tenía con qué abrirse.
|
|
90
|
+
const encOpts = enc ? { myEncPub: enc.encPub, myEncPrivateKey: enc.privateKey } : {}
|
|
91
|
+
const client = makeClient ? makeClient({ url, acceptDirectFrom: inActa, ...encOpts }) : new WebSocketProxyClient({
|
|
88
92
|
url, enableWebRTC: true, acceptDirectFrom: inActa, autoReconnect: true,
|
|
89
|
-
...
|
|
93
|
+
...encOpts,
|
|
90
94
|
maxReconnectAttempts: 100000, reconnectDelay: 4000,
|
|
91
95
|
// EL BLUETOOTH (proxy-client docs/bluetooth.md) lo decide la plataforma: el binario en
|
|
92
96
|
// Linux sí; la pestaña y la extensión no pueden. Misma puerta que WebRTC (`inActa`).
|
|
@@ -118,6 +122,14 @@ export async function createTransport ({ identity, url = DEFAULT_PROXY, commKey
|
|
|
118
122
|
const record = (await identity.profileActa?.().catch(() => null))?.acta || null
|
|
119
123
|
seenActa = record // la copia que mira la puerta del canal directo
|
|
120
124
|
const comm = commKey?.pub?.() || null
|
|
125
|
+
// LA LLAVE DE CIFRADO TAMBIÉN SI LA DE COMUNICACIÓN SE ESTRENÓ DESPUÉS de crear el cliente
|
|
126
|
+
// (un perfil con contraseña la estrena al abrirse). Sin esto la bóveda volvía a la red con
|
|
127
|
+
// su llave nueva pero sin anunciar con qué se le sella, y lo que sus aparatos le mandan
|
|
128
|
+
// sellado (`docs/sealed-requests.md`) no tenía con qué abrirse.
|
|
129
|
+
if (comm && !enc && typeof commKey.encKeypair === 'function') {
|
|
130
|
+
enc = await commKey.encKeypair().catch((e) => { log('[vault] no transport encryption key: ' + e.message); return null })
|
|
131
|
+
if (enc) client.updateConfig?.({ myEncPub: enc.encPub, myEncPrivateKey: enc.privateKey })
|
|
132
|
+
}
|
|
121
133
|
// ¿Nos nombra el acta? Con `cn` o sin él, lo que el proxio mira es la pertenencia.
|
|
122
134
|
const isMember = comm && (record?.members || []).some((m) => m?.pub === comm)
|
|
123
135
|
|
|
@@ -46,7 +46,7 @@ import { BACKUP_VERSION, PASSWORDS_DRAWER, wants, assertSelected, planImport, re
|
|
|
46
46
|
import { openSealKeys } from './sealKey.js'
|
|
47
47
|
import { openCommKey, COMM_CN, COMM_CAPS } from './commKey.js'
|
|
48
48
|
import { seal } from '../sealed.js'
|
|
49
|
-
import { MSG, SCOPE, secretsScope, isValidSecretsNs, VAULT_PROTOCOL, VAULT_SPEAKS } from '../protocol.js'
|
|
49
|
+
import { MSG, SCOPE, secretsScope, isValidSecretsNs, VAULT_PROTOCOL, VAULT_SPEAKS, SEALED_REQUEST_TYPES, unsealedRequestsAllowed, UNSEALED_REQUESTS_UNTIL_TEXT } from '../protocol.js'
|
|
50
50
|
import { sha256Hex } from './sha256.js'
|
|
51
51
|
import { sealHead, ANCHOR_EVERY_MS, ANCHOR_FIRST_MS } from './logAnchor.js'
|
|
52
52
|
import { createGate } from './gate.js'
|
|
@@ -656,6 +656,63 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
656
656
|
*/
|
|
657
657
|
const channels = new Map()
|
|
658
658
|
|
|
659
|
+
/**
|
|
660
|
+
* LA RESPUESTA A UNA PETICIÓN SELLADA VUELVE SELLADA (`docs/sealed-requests.md`).
|
|
661
|
+
*
|
|
662
|
+
* El aparato mete en lo firmado una llave de un solo uso (`data.rek`), y a esa llave se le
|
|
663
|
+
* sella todo lo que se le conteste a ESA petición. Se hace con un canal más de `channels`
|
|
664
|
+
* —como el socket local—, así que ningún mostrador tiene que saber nada: contesta a `from`
|
|
665
|
+
* como siempre y el canal sella. El canal es por conexión Y llave: dos peticiones por la
|
|
666
|
+
* misma conexión con llaves distintas no se pisan, y un tercero que escriba «desde» ese
|
|
667
|
+
* token con otra llave se lleva su propio canal, no el del aparato.
|
|
668
|
+
*
|
|
669
|
+
* Viven lo que puede tardar la respuesta más lenta (un pedido que espera al teléfono) y se
|
|
670
|
+
* podan por antigüedad; si ya no está, la respuesta a un pedido aprobado sale por la cola
|
|
671
|
+
* del aparato, como antes.
|
|
672
|
+
*/
|
|
673
|
+
const SEALED_CHANNEL_TTL_MS = 24 * 60 * 60 * 1000
|
|
674
|
+
const SEALED_CHANNELS_MAX = 5000
|
|
675
|
+
const sealedChannelAt = new Map()
|
|
676
|
+
function sealedChannel (token, rek) {
|
|
677
|
+
const id = `sealed:${token}:${sha256Hex(rek).slice(0, 16)}`
|
|
678
|
+
const now = Date.now()
|
|
679
|
+
if (!channels.has(id)) {
|
|
680
|
+
for (const [k, t] of sealedChannelAt) {
|
|
681
|
+
if (now - t < SEALED_CHANNEL_TTL_MS && sealedChannelAt.size < SEALED_CHANNELS_MAX) break
|
|
682
|
+
sealedChannelAt.delete(k); channels.delete(k)
|
|
683
|
+
}
|
|
684
|
+
// EN ORDEN: sellar es asíncrono, y dos respuestas seguidas podían adelantarse una a la
|
|
685
|
+
// otra. El orden importa (el aviso firmado de expulsión va ANTES del «no», porque el
|
|
686
|
+
// aparato deja de escuchar al recibir el «no»), así que salen en fila.
|
|
687
|
+
let tail = Promise.resolve()
|
|
688
|
+
channels.set(id, (obj) => {
|
|
689
|
+
tail = tail.then(() => client.sendSealedTo(token, obj, { peerEncPub: rek, pilar: true }))
|
|
690
|
+
.catch((e) => log(`[vault] could not send a sealed reply (${e.code || 'error'}): ${e.message}`))
|
|
691
|
+
})
|
|
692
|
+
}
|
|
693
|
+
sealedChannelAt.delete(id)
|
|
694
|
+
sealedChannelAt.set(id, now)
|
|
695
|
+
return id
|
|
696
|
+
}
|
|
697
|
+
const unsealedTold = new Map()
|
|
698
|
+
/** MIGRACIÓN (caduca 2026-12-15): una petición en claro de un cliente viejo. */
|
|
699
|
+
function unsealedRequest (from, payload) {
|
|
700
|
+
const type = String(payload.type)
|
|
701
|
+
if (!unsealedRequestsAllowed()) {
|
|
702
|
+
audit('rejected', { what: type, reason: 'unsealed' })
|
|
703
|
+
reply(from, { type: MSG.ERROR, error: `${type}: requests must be sealed to this vault — update the client`, code: 'request-unsealed' })
|
|
704
|
+
return false
|
|
705
|
+
}
|
|
706
|
+
const t = Date.now()
|
|
707
|
+
if (t - (unsealedTold.get(type) || 0) > 60 * 60 * 1000) {
|
|
708
|
+
unsealedTold.set(type, t)
|
|
709
|
+
log(`[vault] ${type} arrived UNSEALED from an old client: served until ${UNSEALED_REQUESTS_UNTIL_TEXT} (migration), then refused — update it`)
|
|
710
|
+
}
|
|
711
|
+
return true
|
|
712
|
+
}
|
|
713
|
+
const SEALED_TYPES = new Set(SEALED_REQUEST_TYPES)
|
|
714
|
+
|
|
715
|
+
|
|
659
716
|
/**
|
|
660
717
|
* QUÉ SOMOS, Y QUÉ CORRE CADA APARATO (CONVENCIONES §14, `@dotrino/compat`).
|
|
661
718
|
*
|
|
@@ -2575,6 +2632,19 @@ export async function startVault ({ platform, proxyUrl, log = console.log, onEnr
|
|
|
2575
2632
|
if (pass.throttled) reply(from, { type: MSG.ERROR, error: 'too many tries: wait before trying again', code: 'too-many-tries', waitMs: pass.waitMs })
|
|
2576
2633
|
return
|
|
2577
2634
|
}
|
|
2635
|
+
// ¿SELLADA? Por el socket local (`channels`) no hace falta: no toca la red. Por el proxio,
|
|
2636
|
+
// lo que pide un aparato tiene que venir sellado, y su respuesta vuelve sellada a `rek`.
|
|
2637
|
+
if (SEALED_TYPES.has(payload.type) && !channels.has(from)) {
|
|
2638
|
+
if (meta?.sealed) {
|
|
2639
|
+
const rek = payload?.data?.rek
|
|
2640
|
+
if (!ActaPilar.isEncPub(rek)) {
|
|
2641
|
+
// Sellada pero sin a dónde sellar la respuesta: contestar en claro sería deshacer el
|
|
2642
|
+
// sobre de la petición. Se dice, en claro y sin nada del aparato dentro.
|
|
2643
|
+
return reply(from, { type: MSG.ERROR, error: `${payload.type}: a sealed request needs data.rek to seal the reply to`, code: 'no-reply-key' })
|
|
2644
|
+
}
|
|
2645
|
+
from = sealedChannel(from, rek)
|
|
2646
|
+
} else if (!unsealedRequest(from, payload)) return
|
|
2647
|
+
}
|
|
2578
2648
|
try {
|
|
2579
2649
|
if (payload.type === MSG.HELLO) return desk.handleHello(from, payload)
|
|
2580
2650
|
if (payload.type === MSG.ENROLL) return await desk.handleEnroll(from, payload)
|
|
@@ -168,3 +168,28 @@ export const VAULT_PROTOCOL = 1
|
|
|
168
168
|
|
|
169
169
|
/** Los protocolos que esta build entiende. Al añadir el 2, aquí van `[1, 2]`. */
|
|
170
170
|
export const VAULT_SPEAKS = [1]
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* LAS PETICIONES DE UN APARATO A SU BÓVEDA VAN SELLADAS (regla `encrypted`, dueño 2026-10-26:
|
|
174
|
+
* nada viaja en claro por la red). El aparato sella la petición ENTERA a la llave de cifrado
|
|
175
|
+
* del transporte de la bóveda (`sendSealed` del pilar, `@dotrino/identity/vault-seal`) y mete
|
|
176
|
+
* dentro de lo firmado la llave de un solo uso a la que se le sella la respuesta (`data.rek`).
|
|
177
|
+
* Diseño: `docs/sealed-requests.md`.
|
|
178
|
+
*
|
|
179
|
+
* Estos son los tipos que lo exigen: lo que pide un aparato con su firma. El emparejamiento,
|
|
180
|
+
* la entrada con contraseña y lo que se cruzan las bóvedas siguen su propio camino.
|
|
181
|
+
*/
|
|
182
|
+
export const SEALED_REQUEST_TYPES = Object.freeze([
|
|
183
|
+
MSG.SIGN, MSG.GET, MSG.STORE, MSG.CHECK, MSG.DEVICES, MSG.RENEW, MSG.SECRETS,
|
|
184
|
+
MSG.ADMIN, MSG.RENOUNCE, MSG.INCIDENT, MSG.REWRAP_OK
|
|
185
|
+
])
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* MIGRACIÓN — CADUCA EL 2026-12-15. Hasta esa fecha una petición de esos tipos que llega en
|
|
189
|
+
* claro (un cliente viejo) se atiende y se apunta en el log; desde esa fecha se rechaza con
|
|
190
|
+
* `request-unsealed`. Lo cubre `test/sealed-requests.test.mjs`. Quitar en cuanto pase.
|
|
191
|
+
*/
|
|
192
|
+
export const UNSEALED_REQUESTS_UNTIL = Date.UTC(2026, 11, 15)
|
|
193
|
+
export const UNSEALED_REQUESTS_UNTIL_TEXT = '2026-12-15'
|
|
194
|
+
/** ¿Todavía se atiende una petición en claro? (migración, ver arriba) */
|
|
195
|
+
export const unsealedRequestsAllowed = (now = Date.now()) => now < UNSEALED_REQUESTS_UNTIL
|