@dotrino/vault 0.16.0 → 0.17.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/package.json +1 -1
- package/src/atrest.js +0 -0
- package/src/service.js +15 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Usa ESTE dispositivo (navegador) como bóveda/CA del ecosistema Dotrino: atiende enrolamientos por el proxy y firma certificados de delegación a tus máquinas. Incluye el cliente de SERVICIO (Node): un proyecto se enrola una vez y jala sus credenciales del vault en vez del .env (`import '@dotrino/vault/config'`).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/atrest.js
ADDED
|
Binary file
|
package/src/service.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import { MSG, secretsScope, isValidSecretsNs } from './protocol.js'
|
|
28
28
|
import { makeEphemeralKey, openSealed } from './sealed.js'
|
|
29
29
|
import { parseInvite } from './invite.js'
|
|
30
|
+
import { atRestFor } from './atrest.js'
|
|
30
31
|
|
|
31
32
|
const IDENTITY_FILE = 'service-identity.json'
|
|
32
33
|
const FRESH_WINDOW_MS = 5 * 60 * 1000
|
|
@@ -169,15 +170,26 @@ function waitForMsg (client, predicate, timeoutMs = 30000) {
|
|
|
169
170
|
|
|
170
171
|
const identityFileOf = (dir) => path.join(dir, IDENTITY_FILE)
|
|
171
172
|
|
|
172
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Lee la identidad persistida del servicio ({device, cert, iss, proxy, ns}) o null.
|
|
175
|
+
*
|
|
176
|
+
* CIFRADA EN REPOSO (`atrest.js`) con una clave ligada a ESTA máquina: el archivo
|
|
177
|
+
* lleva la llave privada del dispositivo, así que copiarlo a otro equipo no sirve.
|
|
178
|
+
* Un archivo de una versión anterior (en claro) se lee igual y queda cifrado en la
|
|
179
|
+
* primera escritura.
|
|
180
|
+
*/
|
|
173
181
|
export function readServiceIdentity (dir) {
|
|
174
|
-
try {
|
|
182
|
+
try {
|
|
183
|
+
const text = fs.readFileSync(identityFileOf(dir), 'utf8')
|
|
184
|
+
return JSON.parse(atRestFor(dir).decrypt(text))
|
|
185
|
+
} catch (_) { return null }
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
function writeServiceIdentity (dir, obj) {
|
|
178
189
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
179
190
|
const f = identityFileOf(dir)
|
|
180
|
-
|
|
191
|
+
const blob = atRestFor(dir).encrypt(JSON.stringify(obj, null, 2))
|
|
192
|
+
fs.writeFileSync(f, blob, { mode: 0o600 })
|
|
181
193
|
}
|
|
182
194
|
|
|
183
195
|
/**
|