@camstack/system 1.2.444 → 1.2.445
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/dist/addon-runner.js +40 -31
- package/dist/addon-runner.mjs +41 -32
- package/dist/{agent-https-DlpTMDqA.js → agent-https-CiOW0-sj.js} +810 -12
- package/dist/{agent-https-U0d4uvn2.mjs → agent-https-D4Q8iFNd.mjs} +697 -13
- package/dist/auth/admin-token-manager.d.ts +9 -3
- package/dist/auth/api-key-manager.d.ts +9 -3
- package/dist/auth/auth-audit-log.d.ts +9 -3
- package/dist/auth/device-credential-manager.d.ts +5 -1
- package/dist/auth/external-identity-manager.d.ts +8 -21
- package/dist/auth/login-session-manager.d.ts +11 -3
- package/dist/auth/scoped-token-manager.d.ts +8 -52
- package/dist/auth/totp-manager.d.ts +11 -3
- package/dist/auth/user-manager.d.ts +10 -17
- package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/dist/builtins/alerts/alert-store.d.ts +32 -0
- package/dist/builtins/alerts/alerts.addon.d.ts +9 -2
- package/dist/builtins/alerts/alerts.addon.js +289 -150
- package/dist/builtins/alerts/alerts.addon.mjs +288 -150
- package/dist/builtins/alerts/record-kinds.d.ts +15 -0
- package/dist/builtins/autotrack/index.js +1 -1
- package/dist/builtins/autotrack/index.mjs +1 -1
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +1 -0
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +134 -193
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +134 -193
- package/dist/builtins/backup-orchestrator/destination-policy.d.ts +4 -2
- package/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +4 -2
- package/dist/builtins/backup-orchestrator/record-kinds.d.ts +58 -0
- package/dist/builtins/backup-orchestrator/schedule-store.d.ts +4 -2
- package/dist/builtins/backup-orchestrator/seed-marker-store.d.ts +4 -2
- package/dist/builtins/calendars/calendar-prefs-store.d.ts +13 -5
- package/dist/builtins/calendars/calendars.addon.d.ts +2 -2
- package/dist/builtins/calendars/calendars.addon.js +67 -64
- package/dist/builtins/calendars/calendars.addon.mjs +59 -64
- package/dist/builtins/calendars/record-kinds.d.ts +18 -0
- package/dist/builtins/camera-grid/index.js +1 -1
- package/dist/builtins/camera-grid/index.mjs +1 -1
- package/dist/builtins/cluster-agent/record-kinds.d.ts +36 -0
- package/dist/builtins/composer/composer.addon.js +2 -2
- package/dist/builtins/composer/composer.addon.mjs +2 -2
- package/dist/builtins/console-logging/index.js +1 -1
- package/dist/builtins/console-logging/index.mjs +1 -1
- package/dist/builtins/core-blocks/block-settings-store.d.ts +8 -4
- package/dist/builtins/core-blocks/core-block-store.d.ts +8 -16
- package/dist/builtins/core-blocks/core-blocks.addon.js +85 -112
- package/dist/builtins/core-blocks/core-blocks.addon.mjs +86 -113
- package/dist/builtins/core-blocks/index.mjs +1 -1
- package/dist/builtins/core-blocks/record-kinds.d.ts +26 -0
- package/dist/builtins/device-manager/device-manager.addon.js +111 -187
- package/dist/builtins/device-manager/device-manager.addon.mjs +110 -187
- package/dist/builtins/device-manager/device-tombstone-store.d.ts +9 -48
- package/dist/builtins/device-manager/record-kinds.d.ts +14 -0
- package/dist/builtins/hub-forwarder/index.js +1 -1
- package/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/dist/builtins/keychain/index.js +152 -22
- package/dist/builtins/keychain/index.mjs +152 -22
- package/dist/builtins/keychain/keychain-service.d.ts +3 -2
- package/dist/builtins/keychain/keychain-store.d.ts +13 -2
- package/dist/builtins/keychain/record-kinds.d.ts +16 -0
- package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/dist/builtins/local-auth/auth-schema.d.ts +3 -1
- package/dist/builtins/local-auth/local-auth.addon.js +2903 -2123
- package/dist/builtins/local-auth/local-auth.addon.mjs +2904 -2124
- package/dist/builtins/local-auth/oauth-session-manager.d.ts +8 -48
- package/dist/builtins/local-auth/record-kinds.d.ts +141 -0
- package/dist/builtins/local-network/local-network.addon.js +2 -2
- package/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/dist/builtins/loki-logging/index.js +1 -1
- package/dist/builtins/loki-logging/index.mjs +1 -1
- package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/dist/builtins/platform-probe/index.js +1 -1
- package/dist/builtins/platform-probe/index.mjs +1 -1
- package/dist/builtins/record-entries/index.js +1 -1
- package/dist/builtins/record-entries/index.mjs +1 -1
- package/dist/builtins/records/legacy-table-row-count.d.ts +5 -0
- package/dist/builtins/records/phase6-declare-gate.d.ts +28 -0
- package/dist/builtins/records-isolated.d.ts +10 -0
- package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/dist/builtins/snapshot/index.js +1 -1
- package/dist/builtins/snapshot/index.mjs +1 -1
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/dist/builtins/sqlite-storage/index.js +1 -1
- package/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/dist/builtins/sqlite-storage/integration-record-kinds.d.ts +30 -0
- package/dist/builtins/sqlite-storage/integration-registry.d.ts +10 -16
- package/dist/builtins/sqlite-storage/records/count-settings-array-legacy.d.ts +5 -0
- package/dist/builtins/sqlite-storage/records/count-settings-brokers-legacy.d.ts +6 -0
- package/dist/builtins/sqlite-storage/records/records-engine-types.d.ts +5 -0
- package/dist/builtins/sqlite-storage/records/records-engine.d.ts +4 -0
- package/dist/builtins/sqlite-storage/records/records-provider.d.ts +5 -1
- package/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +17 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +111 -3
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +111 -3
- package/dist/builtins/sqlite-storage/storage-admin-provider.d.ts +9 -1
- package/dist/builtins/storage-orchestrator/drain-state-store.d.ts +5 -2
- package/dist/builtins/storage-orchestrator/location-store.d.ts +7 -2
- package/dist/builtins/storage-orchestrator/record-kinds.d.ts +38 -0
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +2 -0
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +196 -5
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +195 -6
- package/dist/builtins/system-config/record-kinds.d.ts +32 -0
- package/dist/builtins/system-config/system-config.addon.js +53 -618
- package/dist/builtins/system-config/system-config.addon.mjs +29 -577
- package/dist/builtins/winston-logging/index.js +1 -1
- package/dist/builtins/winston-logging/index.mjs +1 -1
- package/dist/{composition-sources-C3rKncIF.mjs → composition-sources-BMt5cFYb.mjs} +1 -1
- package/dist/{composition-sources-NAPZddic.js → composition-sources-D3fi9Xns.js} +1 -1
- package/dist/{constants-BKX2QnIg.mjs → constants-BMHCxRzb.mjs} +1 -1
- package/dist/{constants-BXiNEIeV.js → constants-Br879Axi.js} +1 -1
- package/dist/{device-ca-DT9X2S6d.js → device-ca-CnJ_va7i.js} +1 -1
- package/dist/{device-ca-jxjSL8Ov.mjs → device-ca-T8osSMos.mjs} +1 -1
- package/dist/{dist-DERK-gP5.mjs → dist-BNunRyXT.mjs} +174 -58
- package/dist/{dist-D1vECb_6.js → dist-DgOG8flk.js} +233 -57
- package/dist/file-host-worker.js +1 -1
- package/dist/file-host-worker.mjs +1 -1
- package/dist/{hub-mdns-ciao-Cah9GCIg.js → hub-mdns-ciao-BIkTHq-n.js} +2 -2
- package/dist/{hub-mdns-ciao-CRaC97V0.mjs → hub-mdns-ciao-D16oRQ9K.mjs} +2 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3093 -2820
- package/dist/index.mjs +3065 -2809
- package/dist/kernel/index.d.ts +2 -0
- package/dist/kernel/moleculer/event-bus.d.ts +3 -1
- package/dist/kernel/moleculer/mesh-mtls/mesh-certificate-registry.d.ts +5 -1
- package/dist/kernel/moleculer/remote-logger.d.ts +2 -2
- package/dist/kernel/transport/cap-route-resolver.d.ts +9 -38
- package/dist/phase6-declare-gate-Ci1-8uUn.js +98 -0
- package/dist/phase6-declare-gate-tkKOEitw.mjs +93 -0
- package/dist/read-all-rows-CVoO1ONM.js +29 -0
- package/dist/read-all-rows-TaPqdWNF.mjs +25 -0
- package/dist/records/read-all-rows.d.ts +6 -0
- package/dist/{restore-archive-daKyE24F.mjs → restore-archive-DR9MtO7J.mjs} +339 -9
- package/dist/{restore-archive-Dy-qKTdF.js → restore-archive-DjJnCgap.js} +353 -5
- package/dist/tls/agent-https-names.d.ts +9 -13
- package/dist/{wal-maintenance-dAv4IdzC.js → wal-maintenance-CODGqhKY.js} +0 -0
- package/dist/{wal-maintenance-zRc24mOC.mjs → wal-maintenance-CfvgtQ7C.mjs} +0 -0
- package/package.json +1 -1
|
@@ -1,18 +1,672 @@
|
|
|
1
|
+
import { Di as defineRecordKinds } from "./dist-BNunRyXT.mjs";
|
|
1
2
|
import { S as backdatedNotBefore, _ as NameConstraints, a as KeyUsageFlags, c as Pkcs10CertificateRequest, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, g as GeneralSubtrees, h as GeneralSubtree, i as Extension, l as Pkcs10CertificateRequestGenerator, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension, v as GeneralName, x as AsnConvert } from "./x509.es-DK__ETIe.mjs";
|
|
3
|
+
import { c as SERVER_AUTH_OID$1, r as MESH_CA_COMMON_NAME, s as MESH_CA_VALIDITY_DAYS, t as CLIENT_AUTH_OID } from "./constants-BMHCxRzb.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
2
5
|
import { X509Certificate, createHash, createPrivateKey, randomBytes, webcrypto } from "node:crypto";
|
|
3
6
|
import { writeOwnerOnlyFileSync } from "@camstack/types/node";
|
|
4
7
|
import { isIP } from "node:net";
|
|
5
8
|
import { join } from "node:path";
|
|
6
9
|
import * as os$1 from "node:os";
|
|
7
10
|
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
-
//#region src/
|
|
11
|
+
//#region src/kernel/moleculer/mesh-mtls/mesh-ca.ts
|
|
12
|
+
/**
|
|
13
|
+
* Hub mesh CA — EC P-256, key in the keychain, cert in `cluster.meshCa`.
|
|
14
|
+
*
|
|
15
|
+
* Distinct from the HTTPS local CA (`tls/cert-issue.ts`, RSA): the mesh CA
|
|
16
|
+
* signs node leaves (CN = nodeID) and unlock-ticket JWS (ES256). Issuance uses
|
|
17
|
+
* `@peculiar/x509` over WebCrypto — same library the HTTPS path already uses
|
|
18
|
+
* (installed `1.14.3`; registry latest at adoption time was `2.1.0` — stay on
|
|
19
|
+
* the pinned range already shipping).
|
|
20
|
+
*/
|
|
21
|
+
cryptoProvider.set(webcrypto);
|
|
22
|
+
var MS_PER_DAY$2 = 864e5;
|
|
23
|
+
/** Key generation — EC P-256 (plan). WebCrypto DOM names are not in @types/node. */
|
|
24
|
+
var MESH_KEY_ALGORITHM = {
|
|
25
|
+
name: "ECDSA",
|
|
26
|
+
namedCurve: "P-256"
|
|
27
|
+
};
|
|
28
|
+
/** Signing — ECDSA with SHA-256. */
|
|
29
|
+
var MESH_SIGNING_ALGORITHM = {
|
|
30
|
+
name: "ECDSA",
|
|
31
|
+
hash: "SHA-256"
|
|
32
|
+
};
|
|
33
|
+
/** A node id: letters, digits, `.`, `_`, `-`; at most 63 characters; starts with a letter or digit. */
|
|
34
|
+
var NODE_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,62}$/i;
|
|
35
|
+
/** Ids no agent may take: the hub's own, whatever the case (D857). */
|
|
36
|
+
var RESERVED_NODE_IDS = new Set(["hub"]);
|
|
37
|
+
/** True for an id an agent may carry: the pattern, and not a reserved name. */
|
|
38
|
+
function isValidAgentNodeId(nodeId) {
|
|
39
|
+
return NODE_ID_PATTERN.test(nodeId) && !RESERVED_NODE_IDS.has(nodeId.toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
function freshSerial$1() {
|
|
42
|
+
return `00${randomBytes(16).toString("hex")}`;
|
|
43
|
+
}
|
|
44
|
+
function toPkcs8Pem$1(pkcs8) {
|
|
45
|
+
return `${PemConverter.encode(pkcs8, "PRIVATE KEY")}\n`;
|
|
46
|
+
}
|
|
47
|
+
function toCertPem$1(cert) {
|
|
48
|
+
return `${cert.toString("pem")}\n`;
|
|
49
|
+
}
|
|
50
|
+
async function exportKeyPem$1(key) {
|
|
51
|
+
return toPkcs8Pem$1(await webcrypto.subtle.exportKey("pkcs8", key));
|
|
52
|
+
}
|
|
53
|
+
/** SHA-256 fingerprint of the DER cert, colon-hex uppercase (Node style). */
|
|
54
|
+
function caFingerprint(certPem) {
|
|
55
|
+
return new X509Certificate(certPem).fingerprint256;
|
|
56
|
+
}
|
|
57
|
+
/** Compact fingerprint (lowercase hex, no colons). */
|
|
58
|
+
function caFingerprintCompact(certPem) {
|
|
59
|
+
return createHash("sha256").update(new X509Certificate(certPem).raw).digest("hex");
|
|
60
|
+
}
|
|
61
|
+
async function generateMeshCa(now = /* @__PURE__ */ new Date()) {
|
|
62
|
+
const keys = await webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
|
|
63
|
+
const extensions = [
|
|
64
|
+
new BasicConstraintsExtension(true, 0, true),
|
|
65
|
+
new KeyUsagesExtension(KeyUsageFlags.keyCertSign | KeyUsageFlags.cRLSign, true),
|
|
66
|
+
await SubjectKeyIdentifierExtension.create(keys.publicKey)
|
|
67
|
+
];
|
|
68
|
+
const cert = await X509CertificateGenerator.createSelfSigned({
|
|
69
|
+
serialNumber: freshSerial$1(),
|
|
70
|
+
name: `CN=${MESH_CA_COMMON_NAME}`,
|
|
71
|
+
notBefore: backdatedNotBefore(now),
|
|
72
|
+
notAfter: new Date(now.getTime() + MESH_CA_VALIDITY_DAYS * MS_PER_DAY$2),
|
|
73
|
+
keys,
|
|
74
|
+
signingAlgorithm: MESH_SIGNING_ALGORITHM,
|
|
75
|
+
extensions
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
certPem: toCertPem$1(cert),
|
|
79
|
+
keyPem: await exportKeyPem$1(keys.privateKey),
|
|
80
|
+
cert,
|
|
81
|
+
privateKey: keys.privateKey,
|
|
82
|
+
publicKey: keys.publicKey
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function loadMeshCa(certPem, keyPem) {
|
|
86
|
+
const cert = new X509Certificate$1(certPem);
|
|
87
|
+
return {
|
|
88
|
+
certPem,
|
|
89
|
+
keyPem,
|
|
90
|
+
cert,
|
|
91
|
+
privateKey: await webcrypto.subtle.importKey("pkcs8", PemConverter.decodeFirst(keyPem), MESH_KEY_ALGORITHM, true, ["sign"]),
|
|
92
|
+
publicKey: await cert.publicKey.export(webcrypto)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Issue a leaf from a CSR. CN must be present; when `expectedNodeId` is set
|
|
97
|
+
* it must match. Validity: 30 days.
|
|
98
|
+
*/
|
|
99
|
+
async function issueMeshLeafFromCsr(ca, csrPem, opts = {}) {
|
|
100
|
+
const csr = new Pkcs10CertificateRequest(csrPem);
|
|
101
|
+
if (!await csr.verify(webcrypto)) throw new Error("CSR signature is invalid");
|
|
102
|
+
const cn = subjectCn(csr.subject);
|
|
103
|
+
if (cn === null || cn.length === 0) throw new Error("CSR subject has no CN");
|
|
104
|
+
if (opts.allowReserved !== true && !isValidAgentNodeId(cn)) throw new Error(`CSR CN '${cn}' is not an id an agent may carry`);
|
|
105
|
+
if (opts.expectedNodeId !== void 0 && opts.expectedNodeId !== cn) throw new Error(`CSR CN '${cn}' does not match the token nodeId '${opts.expectedNodeId}'`);
|
|
106
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
107
|
+
const validDays = opts.validDays ?? 30;
|
|
108
|
+
const serialNumber = freshSerial$1();
|
|
109
|
+
const notAfter = new Date(now.getTime() + validDays * MS_PER_DAY$2);
|
|
110
|
+
const extensions = [
|
|
111
|
+
new BasicConstraintsExtension(false, void 0, true),
|
|
112
|
+
new KeyUsagesExtension(KeyUsageFlags.digitalSignature, true),
|
|
113
|
+
new ExtendedKeyUsageExtension([SERVER_AUTH_OID$1, CLIENT_AUTH_OID]),
|
|
114
|
+
await SubjectKeyIdentifierExtension.create(csr.publicKey),
|
|
115
|
+
await AuthorityKeyIdentifierExtension.create(ca.cert)
|
|
116
|
+
];
|
|
117
|
+
return {
|
|
118
|
+
certPem: toCertPem$1(await X509CertificateGenerator.create({
|
|
119
|
+
serialNumber,
|
|
120
|
+
subject: `CN=${cn}`,
|
|
121
|
+
issuer: ca.cert.subject,
|
|
122
|
+
notBefore: backdatedNotBefore(now),
|
|
123
|
+
notAfter,
|
|
124
|
+
publicKey: csr.publicKey,
|
|
125
|
+
signingKey: ca.privateKey,
|
|
126
|
+
signingAlgorithm: MESH_SIGNING_ALGORITHM,
|
|
127
|
+
extensions
|
|
128
|
+
})),
|
|
129
|
+
serialNumber,
|
|
130
|
+
notAfter,
|
|
131
|
+
commonName: cn
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** Issue a leaf for a known nodeID with a freshly generated key pair (tests / hub self). */
|
|
135
|
+
async function issueMeshLeafForNode(ca, nodeId, opts = {}) {
|
|
136
|
+
const keys = await webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
|
|
137
|
+
return {
|
|
138
|
+
...await issueMeshLeafFromCsr(ca, await createMeshCsrPem(keys, nodeId), {
|
|
139
|
+
expectedNodeId: nodeId,
|
|
140
|
+
now: opts.now,
|
|
141
|
+
validDays: opts.validDays,
|
|
142
|
+
allowReserved: true
|
|
143
|
+
}),
|
|
144
|
+
keyPem: await exportKeyPem$1(keys.privateKey)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function subjectCn(subject) {
|
|
148
|
+
return /(?:^|,)\s*CN\s*=\s*([^,]+)/i.exec(subject)?.[1]?.trim() ?? null;
|
|
149
|
+
}
|
|
150
|
+
async function createMeshCsrPem(keys, commonName) {
|
|
151
|
+
return `${(await Pkcs10CertificateRequestGenerator.create({
|
|
152
|
+
name: `CN=${commonName}`,
|
|
153
|
+
keys,
|
|
154
|
+
signingAlgorithm: MESH_SIGNING_ALGORITHM
|
|
155
|
+
})).toString("pem")}\n`;
|
|
156
|
+
}
|
|
157
|
+
async function generateMeshKeyPair() {
|
|
158
|
+
return webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
|
|
159
|
+
}
|
|
160
|
+
async function exportMeshPrivateKeyPem(key) {
|
|
161
|
+
return exportKeyPem$1(key);
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/kernel/moleculer/mesh-mtls/mesh-certificate-registry.ts
|
|
165
|
+
/**
|
|
166
|
+
* The hub's record of every mesh leaf (D856): which certificate each node holds,
|
|
167
|
+
* when it expires, and which serials are revoked.
|
|
168
|
+
*
|
|
169
|
+
* Three ways a row appears:
|
|
170
|
+
* - `enroll` / `renewal` / `boot` - the hub issued it and wrote it down at the
|
|
171
|
+
* moment of issuing (the authoritative record);
|
|
172
|
+
* - `observed` - a node enrolled before this record existed (or by a path that
|
|
173
|
+
* did not write it) presented this leaf on its LIVE mutual-TLS connection.
|
|
174
|
+
*
|
|
175
|
+
* Revoked serials are persisted here and replayed into the in-memory CRL at boot,
|
|
176
|
+
* so a revocation survives a hub restart. Hub only: agents persist none of it.
|
|
177
|
+
*/
|
|
9
178
|
/**
|
|
10
179
|
* @durable class=config owner=system-config
|
|
11
|
-
* write="the hub records
|
|
12
|
-
* node
|
|
13
|
-
* retention="
|
|
14
|
-
*
|
|
180
|
+
* write="the hub records every mesh leaf it issues (enroll, renewal, boot) and every
|
|
181
|
+
* leaf a connected node is observed presenting; a revocation stamps revokedAt"
|
|
182
|
+
* retention="a revoked or expired row is kept 90 days past its end, then reaped; a
|
|
183
|
+
* live row is never deleted. Forgetting a node does not delete its rows."
|
|
15
184
|
*/
|
|
185
|
+
var MESH_NODE_CERTIFICATES_COLLECTION = "mesh_node_certificates";
|
|
186
|
+
var MESH_NODE_CERTIFICATES_COLUMNS = [
|
|
187
|
+
{
|
|
188
|
+
name: "id",
|
|
189
|
+
type: "TEXT",
|
|
190
|
+
primaryKey: true,
|
|
191
|
+
notNull: true
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "nodeId",
|
|
195
|
+
type: "TEXT",
|
|
196
|
+
notNull: true
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: "serial",
|
|
200
|
+
type: "TEXT",
|
|
201
|
+
notNull: true
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "fingerprint",
|
|
205
|
+
type: "TEXT",
|
|
206
|
+
notNull: true
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "notBefore",
|
|
210
|
+
type: "INTEGER",
|
|
211
|
+
notNull: true
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "notAfter",
|
|
215
|
+
type: "INTEGER",
|
|
216
|
+
notNull: true
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "issuedAt",
|
|
220
|
+
type: "INTEGER",
|
|
221
|
+
notNull: true
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "issuedVia",
|
|
225
|
+
type: "TEXT",
|
|
226
|
+
notNull: true
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "revokedAt",
|
|
230
|
+
type: "INTEGER"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "revokedReason",
|
|
234
|
+
type: "TEXT"
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
var RETENTION_MS = 90 * 864e5;
|
|
238
|
+
/**
|
|
239
|
+
* A leaf the hub signed for a renewal that did not complete. It must not be the node's
|
|
240
|
+
* `current` leaf, but it is NOT on the CRL: the node may still hold it (the swap
|
|
241
|
+
* could have landed without the hub seeing it), and cutting it off would be the
|
|
242
|
+
* outage the hand-over exists to prevent. If the node is later seen presenting it, it
|
|
243
|
+
* is reinstated.
|
|
244
|
+
*/
|
|
245
|
+
var RENEWAL_ABANDONED = "renewal-abandoned";
|
|
246
|
+
var VIAS = [
|
|
247
|
+
"enroll",
|
|
248
|
+
"pairing",
|
|
249
|
+
"renewal",
|
|
250
|
+
"boot",
|
|
251
|
+
"observed"
|
|
252
|
+
];
|
|
253
|
+
/** CN, serial, fingerprint and validity of a leaf PEM (or DER). */
|
|
254
|
+
function describeMeshLeaf(cert) {
|
|
255
|
+
const x509 = new X509Certificate(cert);
|
|
256
|
+
return {
|
|
257
|
+
cn: subjectCn(x509.subject) ?? "",
|
|
258
|
+
serial: x509.serialNumber,
|
|
259
|
+
fingerprint: x509.fingerprint256,
|
|
260
|
+
notBefore: Date.parse(x509.validFrom),
|
|
261
|
+
notAfter: Date.parse(x509.validTo)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function normalizeSerial(serial) {
|
|
265
|
+
return serial.replace(/^0x/i, "").replace(/:/g, "").toLowerCase();
|
|
266
|
+
}
|
|
267
|
+
function parse$1(data) {
|
|
268
|
+
const str = (k) => {
|
|
269
|
+
const v = data[k];
|
|
270
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
271
|
+
};
|
|
272
|
+
const num = (k) => {
|
|
273
|
+
const v = data[k];
|
|
274
|
+
return typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
275
|
+
};
|
|
276
|
+
const nodeId = str("nodeId");
|
|
277
|
+
const serial = str("serial");
|
|
278
|
+
const fingerprint = str("fingerprint");
|
|
279
|
+
const notBefore = num("notBefore");
|
|
280
|
+
const notAfter = num("notAfter");
|
|
281
|
+
const issuedAt = num("issuedAt");
|
|
282
|
+
if (nodeId === null || serial === null || fingerprint === null || notBefore === null || notAfter === null || issuedAt === null) return null;
|
|
283
|
+
return {
|
|
284
|
+
nodeId,
|
|
285
|
+
serial,
|
|
286
|
+
fingerprint,
|
|
287
|
+
notBefore,
|
|
288
|
+
notAfter,
|
|
289
|
+
issuedAt,
|
|
290
|
+
issuedVia: VIAS.find((v) => v === data["issuedVia"]) ?? "observed",
|
|
291
|
+
revokedAt: num("revokedAt"),
|
|
292
|
+
revokedReason: str("revokedReason")
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
var MeshCertificateRegistry = class {
|
|
296
|
+
store;
|
|
297
|
+
deps;
|
|
298
|
+
rows = /* @__PURE__ */ new Map();
|
|
299
|
+
constructor(store, deps = {}) {
|
|
300
|
+
this.store = store;
|
|
301
|
+
this.deps = deps;
|
|
302
|
+
}
|
|
303
|
+
recordToBody(record) {
|
|
304
|
+
return {
|
|
305
|
+
nodeId: record.nodeId,
|
|
306
|
+
serial: record.serial,
|
|
307
|
+
fingerprint: record.fingerprint,
|
|
308
|
+
notBefore: record.notBefore,
|
|
309
|
+
notAfter: record.notAfter,
|
|
310
|
+
issuedAt: record.issuedAt,
|
|
311
|
+
issuedVia: record.issuedVia,
|
|
312
|
+
revokedAt: record.revokedAt,
|
|
313
|
+
revokedReason: record.revokedReason
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
now() {
|
|
317
|
+
return (this.deps.now ?? Date.now)();
|
|
318
|
+
}
|
|
319
|
+
async load() {
|
|
320
|
+
const kind = this.deps.meshKind ?? null;
|
|
321
|
+
if (kind !== null) {
|
|
322
|
+
const page = await kind.query({ limit: 1e4 });
|
|
323
|
+
for (const row of page.records) {
|
|
324
|
+
const { fingerprint: _fp, ...body } = row.data;
|
|
325
|
+
const record = parse$1({
|
|
326
|
+
...body,
|
|
327
|
+
fingerprint: row.id
|
|
328
|
+
});
|
|
329
|
+
if (record !== null) this.rows.set(record.fingerprint, record);
|
|
330
|
+
}
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const rows = await this.store.query.query({ collection: MESH_NODE_CERTIFICATES_COLLECTION });
|
|
334
|
+
for (const row of rows) {
|
|
335
|
+
const record = parse$1(row.data);
|
|
336
|
+
if (record !== null) this.rows.set(record.fingerprint, record);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** Write down a leaf the hub just issued. Idempotent per fingerprint. */
|
|
340
|
+
async recordIssued(nodeId, certPem, via) {
|
|
341
|
+
const leaf = describeMeshLeaf(certPem);
|
|
342
|
+
const existing = this.rows.get(leaf.fingerprint);
|
|
343
|
+
if (existing !== void 0) return existing;
|
|
344
|
+
const record = {
|
|
345
|
+
nodeId,
|
|
346
|
+
serial: leaf.serial,
|
|
347
|
+
fingerprint: leaf.fingerprint,
|
|
348
|
+
notBefore: leaf.notBefore,
|
|
349
|
+
notAfter: leaf.notAfter,
|
|
350
|
+
issuedAt: this.now(),
|
|
351
|
+
issuedVia: via,
|
|
352
|
+
revokedAt: null,
|
|
353
|
+
revokedReason: null
|
|
354
|
+
};
|
|
355
|
+
await this.insert(record);
|
|
356
|
+
this.deps.logger?.info("Mesh certificate recorded", {
|
|
357
|
+
tags: { nodeId },
|
|
358
|
+
meta: {
|
|
359
|
+
via,
|
|
360
|
+
serial: leaf.serial,
|
|
361
|
+
notAfter: new Date(leaf.notAfter).toISOString()
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return record;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* A node was seen presenting `leaf` on its live connection. A leaf the hub already
|
|
368
|
+
* knows is left alone; an unknown one is recorded `observed` (a node enrolled
|
|
369
|
+
* before this record existed).
|
|
370
|
+
*/
|
|
371
|
+
async recordObserved(nodeId, leaf) {
|
|
372
|
+
const known = this.rows.get(leaf.fingerprint);
|
|
373
|
+
if (known !== void 0) {
|
|
374
|
+
if (known.revokedReason !== "renewal-abandoned") return known.revokedAt === null ? this.abandonRenewalsNewerThan(known) : false;
|
|
375
|
+
const reinstated = {
|
|
376
|
+
...known,
|
|
377
|
+
revokedAt: null,
|
|
378
|
+
revokedReason: null
|
|
379
|
+
};
|
|
380
|
+
this.rows.set(known.fingerprint, reinstated);
|
|
381
|
+
await this.persist(reinstated);
|
|
382
|
+
this.deps.logger?.warn("An abandoned renewal leaf is in use - reinstated", {
|
|
383
|
+
tags: { nodeId },
|
|
384
|
+
meta: { serial: known.serial }
|
|
385
|
+
});
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
const record = {
|
|
389
|
+
nodeId,
|
|
390
|
+
serial: leaf.serial,
|
|
391
|
+
fingerprint: leaf.fingerprint,
|
|
392
|
+
notBefore: leaf.notBefore,
|
|
393
|
+
notAfter: leaf.notAfter,
|
|
394
|
+
issuedAt: this.now(),
|
|
395
|
+
issuedVia: "observed",
|
|
396
|
+
revokedAt: null,
|
|
397
|
+
revokedReason: null
|
|
398
|
+
};
|
|
399
|
+
await this.insert(record);
|
|
400
|
+
this.deps.logger?.info("Mesh certificate observed on a live connection and recorded", {
|
|
401
|
+
tags: { nodeId },
|
|
402
|
+
meta: {
|
|
403
|
+
serial: leaf.serial,
|
|
404
|
+
fingerprint: leaf.fingerprint
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
list(nodeId) {
|
|
410
|
+
return [...this.rows.values()].filter((r) => nodeId === void 0 || r.nodeId === nodeId).toSorted((a, b) => b.issuedAt - a.issuedAt);
|
|
411
|
+
}
|
|
412
|
+
/** The newest non-revoked leaf of a node, or `undefined`. */
|
|
413
|
+
currentFor(nodeId) {
|
|
414
|
+
return this.list(nodeId).find((r) => r.revokedAt === null);
|
|
415
|
+
}
|
|
416
|
+
/** Every non-revoked leaf of a node (a renewal in flight has two). */
|
|
417
|
+
liveFor(nodeId) {
|
|
418
|
+
return this.list(nodeId).filter((r) => r.revokedAt === null);
|
|
419
|
+
}
|
|
420
|
+
/** Stamp a leaf revoked (and mirror it into `crl`). `false` when unknown or already revoked. */
|
|
421
|
+
async revoke(fingerprint, reason, crl) {
|
|
422
|
+
const record = this.rows.get(fingerprint);
|
|
423
|
+
if (record === void 0 || record.revokedAt !== null) return false;
|
|
424
|
+
const revoked = {
|
|
425
|
+
...record,
|
|
426
|
+
revokedAt: this.now(),
|
|
427
|
+
revokedReason: reason
|
|
428
|
+
};
|
|
429
|
+
this.rows.set(fingerprint, revoked);
|
|
430
|
+
crl?.revoke(record.serial);
|
|
431
|
+
await this.persist(revoked);
|
|
432
|
+
this.deps.logger?.warn("Mesh certificate revoked", {
|
|
433
|
+
tags: { nodeId: record.nodeId },
|
|
434
|
+
meta: {
|
|
435
|
+
serial: record.serial,
|
|
436
|
+
reason
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Operator revocation of a whole node: EVERY leaf of the node that is not already on the
|
|
443
|
+
* CRL goes on it - the current one, an observed one, a renewal one, and a leaf that was set
|
|
444
|
+
* aside (`renewal-abandoned`: a copy of it may sit on a stolen box, and it must not stay
|
|
445
|
+
* valid just because the hub once set it aside). Returns the serials put on the CRL.
|
|
446
|
+
* A leaf revoked this way is never reinstated by `recordObserved`.
|
|
447
|
+
*/
|
|
448
|
+
async revokeAllForNode(nodeId, reason, crl, keepFingerprint) {
|
|
449
|
+
const serials = [];
|
|
450
|
+
for (const record of this.list(nodeId)) {
|
|
451
|
+
if (keepFingerprint !== void 0 && record.fingerprint === keepFingerprint) continue;
|
|
452
|
+
if (record.revokedAt !== null && record.revokedReason !== "renewal-abandoned") continue;
|
|
453
|
+
const revoked = {
|
|
454
|
+
...record,
|
|
455
|
+
revokedAt: record.revokedAt ?? this.now(),
|
|
456
|
+
revokedReason: reason
|
|
457
|
+
};
|
|
458
|
+
this.rows.set(record.fingerprint, revoked);
|
|
459
|
+
crl.revoke(record.serial);
|
|
460
|
+
await this.persist(revoked);
|
|
461
|
+
serials.push(record.serial);
|
|
462
|
+
}
|
|
463
|
+
if (serials.length > 0) this.deps.logger?.warn("Every mesh certificate of the node revoked", {
|
|
464
|
+
tags: { nodeId },
|
|
465
|
+
meta: {
|
|
466
|
+
serials,
|
|
467
|
+
reason
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
return serials;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* At boot: a node with TWO live leaves had a renewal in flight when the hub stopped. The
|
|
474
|
+
* newer (renewal) one is set aside - it is not the node's current leaf until the node is
|
|
475
|
+
* seen presenting it, which reinstates it. It is NOT put on the CRL.
|
|
476
|
+
*/
|
|
477
|
+
async settleInterruptedRenewals() {
|
|
478
|
+
let settled = 0;
|
|
479
|
+
const byNode = /* @__PURE__ */ new Map();
|
|
480
|
+
for (const record of this.rows.values()) {
|
|
481
|
+
if (record.revokedAt !== null) continue;
|
|
482
|
+
byNode.set(record.nodeId, [...byNode.get(record.nodeId) ?? [], record]);
|
|
483
|
+
}
|
|
484
|
+
for (const records of byNode.values()) {
|
|
485
|
+
if (records.length < 2) continue;
|
|
486
|
+
for (const record of records) if (record.issuedVia === "renewal" && await this.abandon(record.fingerprint)) settled += 1;
|
|
487
|
+
}
|
|
488
|
+
return settled;
|
|
489
|
+
}
|
|
490
|
+
/** Set a never-completed renewal leaf aside (not current, NOT on the CRL). */
|
|
491
|
+
/** Fingerprints of renewal leaves whose handover is running right now (this process only). */
|
|
492
|
+
renewalsInFlight = /* @__PURE__ */ new Set();
|
|
493
|
+
/**
|
|
494
|
+
* A renewal's leaf is "in flight" from signing until the handover ends. While it is, a node seen
|
|
495
|
+
* presenting its OLD leaf is simply not swapped yet: the new leaf is not set aside (that would
|
|
496
|
+
* flap set-aside / reinstate on the node's first connection with it).
|
|
497
|
+
*/
|
|
498
|
+
beginRenewal(fingerprint) {
|
|
499
|
+
this.renewalsInFlight.add(fingerprint);
|
|
500
|
+
}
|
|
501
|
+
endRenewal(fingerprint) {
|
|
502
|
+
this.renewalsInFlight.delete(fingerprint);
|
|
503
|
+
}
|
|
504
|
+
async abandonRenewalsNewerThan(presented) {
|
|
505
|
+
let changed = false;
|
|
506
|
+
for (const record of this.liveFor(presented.nodeId)) {
|
|
507
|
+
if (record.fingerprint === presented.fingerprint) continue;
|
|
508
|
+
if (record.issuedVia !== "renewal" || record.issuedAt <= presented.issuedAt) continue;
|
|
509
|
+
if (this.renewalsInFlight.has(record.fingerprint)) continue;
|
|
510
|
+
if (await this.abandon(record.fingerprint)) changed = true;
|
|
511
|
+
}
|
|
512
|
+
return changed;
|
|
513
|
+
}
|
|
514
|
+
async abandon(fingerprint) {
|
|
515
|
+
const record = this.rows.get(fingerprint);
|
|
516
|
+
if (record === void 0 || record.revokedAt !== null) return false;
|
|
517
|
+
const abandoned = {
|
|
518
|
+
...record,
|
|
519
|
+
revokedAt: this.now(),
|
|
520
|
+
revokedReason: RENEWAL_ABANDONED
|
|
521
|
+
};
|
|
522
|
+
this.rows.set(fingerprint, abandoned);
|
|
523
|
+
await this.persist(abandoned);
|
|
524
|
+
this.deps.logger?.warn("Renewal leaf set aside (not current, not on the CRL)", {
|
|
525
|
+
tags: { nodeId: record.nodeId },
|
|
526
|
+
meta: { serial: record.serial }
|
|
527
|
+
});
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
/** Replay every persisted revocation into `crl` (hub boot). Set-aside leaves are not revocations. */
|
|
531
|
+
restoreCrl(crl) {
|
|
532
|
+
let restored = 0;
|
|
533
|
+
for (const record of this.rows.values()) {
|
|
534
|
+
if (record.revokedAt === null || record.revokedReason === "renewal-abandoned") continue;
|
|
535
|
+
crl.revoke(record.serial);
|
|
536
|
+
restored += 1;
|
|
537
|
+
}
|
|
538
|
+
return restored;
|
|
539
|
+
}
|
|
540
|
+
/** Is `serial` listed as revoked here? */
|
|
541
|
+
isRevoked(serial) {
|
|
542
|
+
const wanted = normalizeSerial(serial);
|
|
543
|
+
for (const record of this.rows.values()) if (record.revokedAt !== null && record.revokedReason !== "renewal-abandoned" && normalizeSerial(record.serial) === wanted) return true;
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
async reap() {
|
|
547
|
+
const cutoff = this.now() - RETENTION_MS;
|
|
548
|
+
const dead = [...this.rows.values()].filter((r) => (r.revokedAt ?? r.notAfter) < cutoff);
|
|
549
|
+
for (const r of dead) {
|
|
550
|
+
this.rows.delete(r.fingerprint);
|
|
551
|
+
await this.deleteRow(r.fingerprint);
|
|
552
|
+
}
|
|
553
|
+
return dead.length;
|
|
554
|
+
}
|
|
555
|
+
async insert(record) {
|
|
556
|
+
this.rows.set(record.fingerprint, record);
|
|
557
|
+
const kind = this.deps.meshKind ?? null;
|
|
558
|
+
if (kind !== null) {
|
|
559
|
+
const parsed = systemConfigRecordKinds["mesh-node-certificates"].schema.safeParse(this.recordToBody(record));
|
|
560
|
+
if (!parsed.success) throw new Error(parsed.error.message);
|
|
561
|
+
await kind.put({
|
|
562
|
+
id: record.fingerprint,
|
|
563
|
+
data: parsed.data
|
|
564
|
+
});
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
await this.store.insert.mutate({
|
|
568
|
+
collection: MESH_NODE_CERTIFICATES_COLLECTION,
|
|
569
|
+
record: {
|
|
570
|
+
id: record.fingerprint,
|
|
571
|
+
data: { ...record }
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
async deleteRow(fingerprint) {
|
|
576
|
+
const kind = this.deps.meshKind ?? null;
|
|
577
|
+
if (kind !== null) {
|
|
578
|
+
await kind.delete(fingerprint);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
await this.store.delete.mutate({
|
|
582
|
+
collection: MESH_NODE_CERTIFICATES_COLLECTION,
|
|
583
|
+
key: fingerprint
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
async persist(record) {
|
|
587
|
+
try {
|
|
588
|
+
const kind = this.deps.meshKind ?? null;
|
|
589
|
+
if (kind !== null) {
|
|
590
|
+
const parsed = systemConfigRecordKinds["mesh-node-certificates"].schema.safeParse(this.recordToBody(record));
|
|
591
|
+
if (!parsed.success) throw new Error(parsed.error.message);
|
|
592
|
+
await kind.put({
|
|
593
|
+
id: record.fingerprint,
|
|
594
|
+
data: parsed.data
|
|
595
|
+
});
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
await this.store.update.mutate({
|
|
599
|
+
collection: MESH_NODE_CERTIFICATES_COLLECTION,
|
|
600
|
+
id: record.fingerprint,
|
|
601
|
+
data: { ...record }
|
|
602
|
+
});
|
|
603
|
+
} catch (error) {
|
|
604
|
+
this.deps.logger?.error("Mesh certificate write failed - the change holds until restart", {
|
|
605
|
+
tags: { nodeId: record.nodeId },
|
|
606
|
+
meta: { error: error instanceof Error ? error.message : String(error) }
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var SLOT$1 = Symbol.for("camstack.mesh.certificate-registry");
|
|
612
|
+
function setProcessMeshCertificateRegistry(registry) {
|
|
613
|
+
if (registry === null) Reflect.deleteProperty(globalThis, SLOT$1);
|
|
614
|
+
else Reflect.set(globalThis, SLOT$1, registry);
|
|
615
|
+
}
|
|
616
|
+
function getProcessMeshCertificateRegistry() {
|
|
617
|
+
const value = Reflect.get(globalThis, SLOT$1);
|
|
618
|
+
return value !== null && typeof value === "object" && typeof Reflect.get(value, "recordIssued") === "function" ? value : null;
|
|
619
|
+
}
|
|
620
|
+
var MeshNodeCertificateBodySchema = z.object({
|
|
621
|
+
nodeId: z.string(),
|
|
622
|
+
serial: z.string(),
|
|
623
|
+
fingerprint: z.string(),
|
|
624
|
+
notBefore: z.number(),
|
|
625
|
+
notAfter: z.number(),
|
|
626
|
+
issuedAt: z.number(),
|
|
627
|
+
issuedVia: z.string(),
|
|
628
|
+
revokedAt: z.number().nullish(),
|
|
629
|
+
revokedReason: z.string().nullish()
|
|
630
|
+
});
|
|
631
|
+
var AgentHttpsNameBodySchema = z.object({
|
|
632
|
+
names: z.array(z.string()).readonly(),
|
|
633
|
+
issuedAt: z.number()
|
|
634
|
+
});
|
|
635
|
+
var _systemConfigRecordKinds = defineRecordKinds({
|
|
636
|
+
"mesh-node-certificates": {
|
|
637
|
+
schema: MeshNodeCertificateBodySchema,
|
|
638
|
+
class: "config",
|
|
639
|
+
writeTrigger: "mesh pairing, renewal, revocation (CRL mirror refreshed from rows)",
|
|
640
|
+
device: "none",
|
|
641
|
+
at: "none",
|
|
642
|
+
indexes: [{
|
|
643
|
+
name: "node",
|
|
644
|
+
fields: ["nodeId"]
|
|
645
|
+
}, {
|
|
646
|
+
name: "fingerprint",
|
|
647
|
+
fields: ["fingerprint"]
|
|
648
|
+
}],
|
|
649
|
+
retention: {
|
|
650
|
+
owner: "system-config",
|
|
651
|
+
reason: "daily reap removes revoked/expired rows older than 90 days"
|
|
652
|
+
},
|
|
653
|
+
adoptsFrom: MESH_NODE_CERTIFICATES_COLLECTION
|
|
654
|
+
},
|
|
655
|
+
"agent-https-names": {
|
|
656
|
+
schema: AgentHttpsNameBodySchema,
|
|
657
|
+
class: "config",
|
|
658
|
+
writeTrigger: "agent HTTPS certificate issuance records the CN/SAN set",
|
|
659
|
+
device: "none",
|
|
660
|
+
at: "none",
|
|
661
|
+
retention: { none: "one row per node id" },
|
|
662
|
+
adoptsFrom: AGENT_HTTPS_NAMES_COLLECTION
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
var systemConfigRecordKinds = _systemConfigRecordKinds;
|
|
666
|
+
_systemConfigRecordKinds["mesh-node-certificates"];
|
|
667
|
+
_systemConfigRecordKinds["agent-https-names"];
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/tls/agent-https-names.ts
|
|
16
670
|
var AGENT_HTTPS_NAMES_COLLECTION = "agent_https_names";
|
|
17
671
|
var AGENT_HTTPS_NAMES_COLUMNS = [
|
|
18
672
|
{
|
|
@@ -33,23 +687,34 @@ var AGENT_HTTPS_NAMES_COLUMNS = [
|
|
|
33
687
|
}
|
|
34
688
|
];
|
|
35
689
|
var AgentHttpsNames = class {
|
|
36
|
-
store;
|
|
37
690
|
byNode = /* @__PURE__ */ new Map();
|
|
38
|
-
|
|
39
|
-
|
|
691
|
+
kind;
|
|
692
|
+
store;
|
|
693
|
+
constructor(deps) {
|
|
694
|
+
if ("agentHttpsNamesKind" in deps) {
|
|
695
|
+
this.kind = deps.agentHttpsNamesKind;
|
|
696
|
+
this.store = deps.legacyStore ?? null;
|
|
697
|
+
} else {
|
|
698
|
+
this.kind = null;
|
|
699
|
+
this.store = deps;
|
|
700
|
+
}
|
|
40
701
|
}
|
|
41
702
|
async load() {
|
|
703
|
+
const kind = this.kind;
|
|
704
|
+
if (kind !== null) {
|
|
705
|
+
const page = await kind.query({ limit: 1e4 });
|
|
706
|
+
for (const row of page.records) this.byNode.set(row.id, row.data.names.map((n) => n.toLowerCase()));
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
42
709
|
const rows = await this.store.query.query({ collection: AGENT_HTTPS_NAMES_COLLECTION });
|
|
43
710
|
for (const row of rows) {
|
|
44
711
|
const names = row.data["names"];
|
|
45
712
|
if (Array.isArray(names)) this.byNode.set(row.id, names.filter((n) => typeof n === "string").map((n) => n.toLowerCase()));
|
|
46
713
|
}
|
|
47
714
|
}
|
|
48
|
-
/** The names certified to `nodeId` (its id and the address of its live mesh socket), or `null`. */
|
|
49
715
|
namesOf(nodeId) {
|
|
50
716
|
return this.byNode.get(nodeId) ?? null;
|
|
51
717
|
}
|
|
52
|
-
/** Every name certified to a node other than `nodeId`. */
|
|
53
718
|
takenByOthers(nodeId) {
|
|
54
719
|
const out = /* @__PURE__ */ new Set();
|
|
55
720
|
for (const [id, names] of this.byNode) {
|
|
@@ -58,9 +723,13 @@ var AgentHttpsNames = class {
|
|
|
58
723
|
}
|
|
59
724
|
return out;
|
|
60
725
|
}
|
|
61
|
-
/** Free every name certified to a node that was forgotten. */
|
|
62
726
|
async release(nodeId) {
|
|
63
727
|
if (!this.byNode.delete(nodeId)) return false;
|
|
728
|
+
const kind = this.kind;
|
|
729
|
+
if (kind !== null) {
|
|
730
|
+
await kind.delete(nodeId);
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
64
733
|
await this.store.delete.mutate({
|
|
65
734
|
collection: AGENT_HTTPS_NAMES_COLLECTION,
|
|
66
735
|
key: nodeId
|
|
@@ -71,9 +740,24 @@ var AgentHttpsNames = class {
|
|
|
71
740
|
const lowered = names.map((n) => n.toLowerCase());
|
|
72
741
|
const existed = this.byNode.has(nodeId);
|
|
73
742
|
this.byNode.set(nodeId, lowered);
|
|
743
|
+
const issuedAt = Date.now();
|
|
744
|
+
const body = {
|
|
745
|
+
names: lowered,
|
|
746
|
+
issuedAt
|
|
747
|
+
};
|
|
748
|
+
const kind = this.kind;
|
|
749
|
+
if (kind !== null) {
|
|
750
|
+
const parsed = systemConfigRecordKinds["agent-https-names"].schema.safeParse(body);
|
|
751
|
+
if (!parsed.success) throw new Error(parsed.error.message);
|
|
752
|
+
await kind.put({
|
|
753
|
+
id: nodeId,
|
|
754
|
+
data: parsed.data
|
|
755
|
+
});
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
74
758
|
const data = {
|
|
75
759
|
names: lowered,
|
|
76
|
-
issuedAt
|
|
760
|
+
issuedAt
|
|
77
761
|
};
|
|
78
762
|
if (existed) await this.store.update.mutate({
|
|
79
763
|
collection: AGENT_HTTPS_NAMES_COLLECTION,
|
|
@@ -943,4 +1627,4 @@ function pemDigest(pem) {
|
|
|
943
1627
|
return createHash("sha256").update(pem).digest("hex").slice(0, 16);
|
|
944
1628
|
}
|
|
945
1629
|
//#endregion
|
|
946
|
-
export { isConstrainedCa as A, MAX_LEAF_VALIDITY_DAYS as C, PERMITTED_DNS_SUFFIXES as D, reasonRequiresNewCa as E, AGENT_HTTPS_NAMES_COLLECTION as F, AGENT_HTTPS_NAMES_COLUMNS as I, AgentHttpsNames as L, permitsIdentity as M, permitsName as N, PERMITTED_IP_RANGES as O, readNameConstraints as P, getProcessAgentHttpsNames as R, LEAF_RENEWAL_WINDOW_DAYS as S, evaluateExistingCert as T, issueLeaf as _, collectAgentNames as a, systemHostFacts as b, installAgentHttps as c, issueAgentHttpsLeaf as d, loadAgentHttps as f, generateCa as g, CA_COMMON_NAME as h, certificateNames as i, isLocalOnlyHostname as j, buildNameConstraintSet as k, isContainerBridgeAddress as l, pinnedHttpsCaFingerprint as m, acceptAgentSans as n, createAgentHttpsRequest as o, pemDigest as p, agentHttpsPaths as r, describeHttpsLeaf as s, AgentHttpsInstallError as t, isPrivateAddress as u, loadCa as v, SERVER_AUTH_OID as w, CA_VALIDITY_DAYS as x, collectCertIdentity as y, setProcessAgentHttpsNames as z };
|
|
1630
|
+
export { generateMeshKeyPair as $, isConstrainedCa as A, systemConfigRecordKinds as B, MAX_LEAF_VALIDITY_DAYS as C, PERMITTED_DNS_SUFFIXES as D, reasonRequiresNewCa as E, AGENT_HTTPS_NAMES_COLLECTION as F, describeMeshLeaf as G, MESH_NODE_CERTIFICATES_COLUMNS as H, AGENT_HTTPS_NAMES_COLUMNS as I, caFingerprint as J, getProcessMeshCertificateRegistry as K, AgentHttpsNames as L, permitsIdentity as M, permitsName as N, PERMITTED_IP_RANGES as O, readNameConstraints as P, generateMeshCa as Q, getProcessAgentHttpsNames as R, LEAF_RENEWAL_WINDOW_DAYS as S, evaluateExistingCert as T, MeshCertificateRegistry as U, MESH_NODE_CERTIFICATES_COLLECTION as V, RENEWAL_ABANDONED as W, createMeshCsrPem as X, caFingerprintCompact as Y, exportMeshPrivateKeyPem as Z, issueLeaf as _, collectAgentNames as a, systemHostFacts as b, installAgentHttps as c, issueAgentHttpsLeaf as d, isValidAgentNodeId as et, loadAgentHttps as f, generateCa as g, CA_COMMON_NAME as h, certificateNames as i, subjectCn as it, isLocalOnlyHostname as j, buildNameConstraintSet as k, isContainerBridgeAddress as l, pinnedHttpsCaFingerprint as m, acceptAgentSans as n, issueMeshLeafFromCsr as nt, createAgentHttpsRequest as o, pemDigest as p, setProcessMeshCertificateRegistry as q, agentHttpsPaths as r, loadMeshCa as rt, describeHttpsLeaf as s, AgentHttpsInstallError as t, issueMeshLeafForNode as tt, isPrivateAddress as u, loadCa as v, SERVER_AUTH_OID as w, CA_VALIDITY_DAYS as x, collectCertIdentity as y, setProcessAgentHttpsNames as z };
|