@camstack/system 1.2.381 → 1.2.383
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 +4 -2
- package/dist/addon-runner.mjs +4 -2
- package/dist/addon-utils.js +1 -1
- package/dist/addon-utils.mjs +1 -1
- package/dist/auth/admin-token-manager.d.ts +75 -0
- package/dist/auth/api-key-manager.d.ts +1 -14
- package/dist/auth/auth-audit-log.d.ts +59 -0
- package/dist/auth/auth-manager.d.ts +28 -16
- package/dist/auth/cidr.d.ts +22 -0
- package/dist/auth/login-session-manager.d.ts +158 -0
- package/dist/auth/user-management-internal.d.ts +69 -0
- 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/alerts.addon.js +1 -1
- package/dist/builtins/alerts/alerts.addon.mjs +1 -1
- 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 +14 -0
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +291 -3631
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +284 -3617
- package/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +36 -0
- package/dist/builtins/backup-orchestrator/manifest-store.d.ts +19 -1
- package/dist/builtins/backup-orchestrator/restore-archive.d.ts +24 -0
- package/dist/builtins/calendars/calendars.addon.js +1 -1
- package/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/dist/builtins/camera-grid/index.js +1 -1
- package/dist/builtins/camera-grid/index.mjs +1 -1
- 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/core-blocks.addon.js +2 -2
- package/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
- package/dist/builtins/device-manager/device-manager.addon.js +2 -2
- package/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
- package/dist/builtins/hub-forwarder/index.js +1 -1
- package/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/dist/builtins/keychain/index.js +1110 -735
- package/dist/builtins/keychain/index.mjs +1109 -734
- package/dist/builtins/keychain/keychain-reset-trigger.d.ts +25 -0
- package/dist/builtins/keychain/keychain-service.d.ts +36 -3
- package/dist/builtins/keychain/keychain-store.d.ts +24 -1
- package/dist/builtins/keychain/system-held-secrets.d.ts +2 -1
- 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/local-auth.addon.d.ts +16 -0
- package/dist/builtins/local-auth/local-auth.addon.js +1028 -294
- package/dist/builtins/local-auth/local-auth.addon.mjs +1035 -299
- package/dist/builtins/local-network/local-network.addon.js +3 -3
- package/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/dist/builtins/loki-logging/index.js +97 -29
- package/dist/builtins/loki-logging/index.mjs +97 -29
- package/dist/builtins/loki-logging/loki-logging.addon.d.ts +7 -23
- package/dist/builtins/loki-logging/retire-enabled-flag.d.ts +23 -0
- 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/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/sqlite-settings.addon.js +0 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +2 -2
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +2 -2
- package/dist/builtins/system-backup/backup-encryption.d.ts +57 -0
- package/dist/builtins/system-backup/system-backup.service.d.ts +16 -1
- package/dist/builtins/system-config/cluster-secret-keeper.d.ts +7 -0
- package/dist/builtins/system-config/index.d.ts +1 -0
- package/dist/builtins/system-config/index.js +2 -0
- package/dist/builtins/system-config/index.mjs +2 -2
- package/dist/builtins/system-config/mesh-actions.d.ts +19 -0
- package/dist/builtins/system-config/system-config.addon.d.ts +47 -4
- package/dist/builtins/system-config/system-config.addon.js +87858 -43
- package/dist/builtins/system-config/system-config.addon.mjs +87813 -39
- package/dist/builtins/winston-logging/index.js +1 -1
- package/dist/builtins/winston-logging/index.mjs +1 -1
- package/dist/{child-cap-dispatch-hf-Gce_4.js → child-cap-dispatch-BD8fhJ1b.js} +7 -4
- package/dist/{child-cap-dispatch-BTe4eKep.mjs → child-cap-dispatch-C68N2a6Y.mjs} +11 -8
- package/dist/{composition-sources-4SmsP0O4.js → composition-sources-ChpT_Yw4.js} +1 -1
- package/dist/{composition-sources-CgOQVIwa.mjs → composition-sources-DM7Ft_tp.mjs} +1 -1
- package/dist/{cluster-secret-BUiG8DCo.js → constants-CDpry1_T.js} +82 -1
- package/dist/{cluster-secret-DgJTZ4qY.mjs → constants-e3mCa1jG.mjs} +23 -2
- package/dist/{dist-BugrtARh.js → dist-CUNGH0fs.js} +1755 -157
- package/dist/{dist-BC0GnGeg.mjs → dist-osl3bkF0.mjs} +1732 -158
- package/dist/{event-loop-stall-monitor-GgpnfAC0.mjs → event-loop-stall-monitor-BeeWMnyT.mjs} +15 -15
- package/dist/{event-loop-stall-monitor-CnQ-K6Gn.js → event-loop-stall-monitor-Dk28EF8B.js} +15 -15
- package/dist/{hub-cap-forward-CH6_VWVO.mjs → hub-cap-forward-CDiN1p98.mjs} +18 -2
- package/dist/{hub-cap-forward-COCmYaup.js → hub-cap-forward-W8oEm4ME.js} +23 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +1023 -83525
- package/dist/index.mjs +1218 -83794
- package/dist/{jwt-signing-key-CsuVKA1W.mjs → jwt-signing-key-MQLxLfgF.mjs} +1 -1
- package/dist/{jwt-signing-key-CjoZcol8.js → jwt-signing-key-WI6z7JBo.js} +1 -1
- package/dist/kernel/index.d.ts +17 -1
- package/dist/kernel/moleculer/agent-mesh-authenticator.d.ts +41 -0
- package/dist/kernel/moleculer/broker-factory.d.ts +25 -2
- package/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +1 -0
- package/dist/kernel/moleculer/hub-service.d.ts +9 -0
- package/dist/kernel/moleculer/mesh-access-middleware.d.ts +33 -0
- package/dist/kernel/moleculer/mesh-auth-mode.d.ts +64 -0
- package/dist/kernel/moleculer/mesh-authenticator.d.ts +71 -0
- package/dist/kernel/moleculer/mesh-auto-enforce.d.ts +26 -0
- package/dist/kernel/moleculer/mesh-join-client.d.ts +51 -0
- package/dist/kernel/moleculer/mesh-join-proof.d.ts +39 -0
- package/dist/kernel/moleculer/mesh-mtls/constants.d.ts +20 -0
- package/dist/kernel/moleculer/mesh-mtls/index.d.ts +9 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-ca-keeper.d.ts +55 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-ca.d.ts +45 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-crl.d.ts +16 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-enroll.d.ts +27 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-join-token.d.ts +55 -0
- package/dist/kernel/moleculer/mesh-mtls/mesh-tls-enabler.d.ts +5 -0
- package/dist/kernel/moleculer/mesh-mtls/tls-tcp-transporter.d.ts +92 -0
- package/dist/kernel/system-settings-policy.d.ts +4 -3
- package/dist/kernel/transport/hub-cap-forward.d.ts +14 -3
- package/dist/kernel/transport/index.d.ts +1 -1
- package/dist/ms-DlIWNkkk.mjs +160 -0
- package/dist/ms-t68_FaqE.js +171 -0
- package/dist/restore-archive-C5f9yX90.js +4139 -0
- package/dist/restore-archive-CZRtI1k9.mjs +4045 -0
- package/dist/{retired-settings-keys-MCVhxPkJ.mjs → retired-settings-keys-LuDd4y3M.mjs} +1 -1
- package/dist/{retired-settings-keys-DCuetwOt.js → retired-settings-keys-WLrbzdPR.js} +1 -1
- package/dist/tls-BWpwU-d5.js +1160 -0
- package/dist/tls-C2NT-Orr.mjs +949 -0
- package/dist/{tls-CCMX7MjX.js → x509.es-BhTzcFhZ.js} +65 -1108
- package/dist/{tls-CJHogwTl.mjs → x509.es-Xf3K_brW.mjs} +40 -950
- package/package.json +3 -2
|
@@ -1,344 +1,4 @@
|
|
|
1
1
|
import { r as __exportAll, t as __commonJSMin } from "./chunk-CNf5ZN-e.mjs";
|
|
2
|
-
import { X509Certificate, createPrivateKey, randomBytes, webcrypto } from "node:crypto";
|
|
3
|
-
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import * as os from "node:os";
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { createServer } from "node:http";
|
|
8
|
-
import { isIP } from "node:net";
|
|
9
|
-
//#region src/http/lan-http-bind.ts
|
|
10
|
-
/**
|
|
11
|
-
* Second HTTP listener that shares the hub's existing request handler.
|
|
12
|
-
*
|
|
13
|
-
* Fastify is one protocol per instance; HTTPS stays on :4443 and this
|
|
14
|
-
* binds a plain `http.Server` that emits `request` AND `upgrade` onto the
|
|
15
|
-
* same handler graph (tRPC HTTP, cookies, data-plane, static, tRPC WS).
|
|
16
|
-
*
|
|
17
|
-
* Forwarding only `request` is not enough: the viewer speaks tRPC exclusively
|
|
18
|
-
* over WebSocket (`wsLink`). `/health` wins the LAN race, then `ws://…/trpc`
|
|
19
|
-
* hangs because nobody handles the upgrade on this socket.
|
|
20
|
-
*/
|
|
21
|
-
var DEFAULT_HTTP_PORT = 4480;
|
|
22
|
-
var handlers = null;
|
|
23
|
-
var server = null;
|
|
24
|
-
var pending = null;
|
|
25
|
-
var state = {
|
|
26
|
-
listening: false,
|
|
27
|
-
error: null,
|
|
28
|
-
port: DEFAULT_HTTP_PORT
|
|
29
|
-
};
|
|
30
|
-
var boundRequestedHost = null;
|
|
31
|
-
var DEFAULT_LAN_HTTP_PORT = DEFAULT_HTTP_PORT;
|
|
32
|
-
/** Map "all IPv4" to dual-stack IPv6 (`::`, ipv6Only false) so IPv4 still works. */
|
|
33
|
-
function allFamiliesListenHost(host) {
|
|
34
|
-
if (host === "0.0.0.0" || host === "*" || host === "") return {
|
|
35
|
-
host: "::",
|
|
36
|
-
ipv6Only: false
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
host,
|
|
40
|
-
ipv6Only: false
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function registerLanHttpHandler(next) {
|
|
44
|
-
handlers = next;
|
|
45
|
-
}
|
|
46
|
-
function readLanHttpState() {
|
|
47
|
-
return state;
|
|
48
|
-
}
|
|
49
|
-
async function applyLanHttp(options) {
|
|
50
|
-
pending = options;
|
|
51
|
-
if (!options.enabled) {
|
|
52
|
-
await closeLanHttp();
|
|
53
|
-
state = {
|
|
54
|
-
listening: false,
|
|
55
|
-
error: null,
|
|
56
|
-
port: options.port
|
|
57
|
-
};
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
if (handlers === null) {
|
|
61
|
-
state = {
|
|
62
|
-
listening: false,
|
|
63
|
-
error: "HTTP listener is not registered yet",
|
|
64
|
-
port: options.port
|
|
65
|
-
};
|
|
66
|
-
return state;
|
|
67
|
-
}
|
|
68
|
-
if (server !== null && state.listening && (options.port === 0 || state.port === options.port) && boundRequestedHost === options.host) return state;
|
|
69
|
-
await closeLanHttp();
|
|
70
|
-
try {
|
|
71
|
-
const bound = await listenHttp(options.port, options.host, handlers);
|
|
72
|
-
server = bound;
|
|
73
|
-
boundRequestedHost = options.host;
|
|
74
|
-
const addr = bound.address();
|
|
75
|
-
state = {
|
|
76
|
-
listening: true,
|
|
77
|
-
error: null,
|
|
78
|
-
port: typeof addr === "object" && addr !== null ? addr.port : options.port
|
|
79
|
-
};
|
|
80
|
-
return state;
|
|
81
|
-
} catch (err) {
|
|
82
|
-
server = null;
|
|
83
|
-
state = {
|
|
84
|
-
listening: false,
|
|
85
|
-
error: err instanceof Error ? err.message : String(err),
|
|
86
|
-
port: options.port
|
|
87
|
-
};
|
|
88
|
-
return state;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/** After the hub registers the Fastify request handler, bind whatever was pending. */
|
|
92
|
-
async function bindPendingLanHttp() {
|
|
93
|
-
if (pending === null) return applyLanHttp({
|
|
94
|
-
enabled: true,
|
|
95
|
-
port: DEFAULT_HTTP_PORT,
|
|
96
|
-
host: "0.0.0.0"
|
|
97
|
-
});
|
|
98
|
-
return applyLanHttp(pending);
|
|
99
|
-
}
|
|
100
|
-
async function closeLanHttp() {
|
|
101
|
-
const current = server;
|
|
102
|
-
server = null;
|
|
103
|
-
boundRequestedHost = null;
|
|
104
|
-
if (current === null) return;
|
|
105
|
-
await new Promise((resolve) => {
|
|
106
|
-
current.close(() => resolve());
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function listenHttp(port, host, next) {
|
|
110
|
-
const resolved = allFamiliesListenHost(host);
|
|
111
|
-
return listenOn(port, resolved, next).catch((err) => {
|
|
112
|
-
if (resolved.host === "::" && host !== "::") return listenOn(port, {
|
|
113
|
-
host: "0.0.0.0",
|
|
114
|
-
ipv6Only: false
|
|
115
|
-
}, next);
|
|
116
|
-
throw err;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function listenOn(port, bind, next) {
|
|
120
|
-
return new Promise((resolve, reject) => {
|
|
121
|
-
const created = createServer(next.onRequest);
|
|
122
|
-
created.on("upgrade", next.onUpgrade);
|
|
123
|
-
const onError = (err) => {
|
|
124
|
-
created.off("listening", onListening);
|
|
125
|
-
created.close();
|
|
126
|
-
reject(err);
|
|
127
|
-
};
|
|
128
|
-
const onListening = () => {
|
|
129
|
-
created.off("error", onError);
|
|
130
|
-
resolve(created);
|
|
131
|
-
};
|
|
132
|
-
created.once("error", onError);
|
|
133
|
-
created.once("listening", onListening);
|
|
134
|
-
created.listen({
|
|
135
|
-
port,
|
|
136
|
-
host: bind.host,
|
|
137
|
-
ipv6Only: bind.ipv6Only
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/tls/cert-evaluation.ts
|
|
143
|
-
/**
|
|
144
|
-
* The regeneration rule (D227), as a pure function.
|
|
145
|
-
*
|
|
146
|
-
* `ensureTlsCert` reissues **only** when the material on disk cannot do
|
|
147
|
-
* its job. Never because it is old, never because the machine picked up
|
|
148
|
-
* an address the certificate does not need, never because a new build
|
|
149
|
-
* shipped. The decision is a function of (files on disk, machine
|
|
150
|
-
* identity, clock) alone, so the same inputs always produce the same
|
|
151
|
-
* answer — which is what makes a reissue happen once and then stop.
|
|
152
|
-
*/
|
|
153
|
-
/** OID `id-kp-serverAuth`. Apple's trustd requires it on the leaf. */
|
|
154
|
-
var SERVER_AUTH_OID = "1.3.6.1.5.5.7.3.1";
|
|
155
|
-
/**
|
|
156
|
-
* Apple's `SecPolicyCheckOtherTrustValidityPeriod` ceiling is 825 days;
|
|
157
|
-
* the CA/Browser Forum's recommended maximum is 397. We sit at 397.
|
|
158
|
-
*/
|
|
159
|
-
var MAX_LEAF_VALIDITY_DAYS = 397;
|
|
160
|
-
/** Reissue this long before the leaf dies, so nobody serves an expired one. */
|
|
161
|
-
var LEAF_RENEWAL_WINDOW_DAYS = 30;
|
|
162
|
-
/** A local root outlives many leaves — it is the anchor an operator trusts. */
|
|
163
|
-
var CA_VALIDITY_DAYS = 3650;
|
|
164
|
-
var MS_PER_DAY$1 = 864e5;
|
|
165
|
-
/** Reasons that invalidate the root as well as the leaf. */
|
|
166
|
-
var REASONS_REQUIRING_NEW_CA = [
|
|
167
|
-
"missing",
|
|
168
|
-
"unreadable",
|
|
169
|
-
"no-local-ca",
|
|
170
|
-
"ca-expiring"
|
|
171
|
-
];
|
|
172
|
-
function reasonRequiresNewCa(reason) {
|
|
173
|
-
return REASONS_REQUIRING_NEW_CA.includes(reason);
|
|
174
|
-
}
|
|
175
|
-
function parse(pem) {
|
|
176
|
-
try {
|
|
177
|
-
return new X509Certificate(pem);
|
|
178
|
-
} catch {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function daysBetween(from, to) {
|
|
183
|
-
return (to.getTime() - from.getTime()) / MS_PER_DAY$1;
|
|
184
|
-
}
|
|
185
|
-
function hasServerAuthEku(leaf) {
|
|
186
|
-
const eku = leaf.keyUsage;
|
|
187
|
-
return eku !== void 0 && eku.length === 1 && eku[0] === "1.3.6.1.5.5.7.3.1";
|
|
188
|
-
}
|
|
189
|
-
function keyMatches(leaf, keyPem) {
|
|
190
|
-
try {
|
|
191
|
-
return leaf.checkPrivateKey(createPrivateKey(keyPem));
|
|
192
|
-
} catch {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function coversIdentity(leaf, identity) {
|
|
197
|
-
for (const name of identity.requiredDnsNames) if (leaf.checkHost(name) === void 0) return false;
|
|
198
|
-
for (const ip of identity.requiredIpAddresses) if (leaf.checkIP(ip) === void 0) return false;
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* `null` when the material on disk is fit to keep serving.
|
|
203
|
-
*
|
|
204
|
-
* Order matters only for the quality of the reported reason; any
|
|
205
|
-
* non-null answer produces the same action.
|
|
206
|
-
*/
|
|
207
|
-
function evaluateExistingCert(input) {
|
|
208
|
-
const leaf = parse(input.chainPem);
|
|
209
|
-
const ca = parse(input.caPem);
|
|
210
|
-
if (leaf === null || ca === null) return "unreadable";
|
|
211
|
-
if (daysBetween(input.now, new Date(ca.validTo)) < 427) return "ca-expiring";
|
|
212
|
-
if (!keyMatches(leaf, input.keyPem)) return "key-mismatch";
|
|
213
|
-
if (daysBetween(input.now, new Date(leaf.validTo)) < 30) return "expiring";
|
|
214
|
-
if (!hasServerAuthEku(leaf)) return "missing-server-auth-eku";
|
|
215
|
-
if (leaf.ca || !leaf.checkIssued(ca) || !leaf.verify(ca.publicKey)) return "not-issued-by-local-ca";
|
|
216
|
-
if (daysBetween(new Date(leaf.validFrom), new Date(leaf.validTo)) > 398) return "validity-too-long";
|
|
217
|
-
if (!coversIdentity(leaf, input.identity)) return "san-coverage-gap";
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/tls/cert-identity.ts
|
|
222
|
-
/**
|
|
223
|
-
* What names and addresses the hub's certificate has to answer for.
|
|
224
|
-
*
|
|
225
|
-
* Split out of `cert-manager.ts` because it is pure and because the
|
|
226
|
-
* regeneration rule (D227) is decided entirely by the difference between
|
|
227
|
-
* *this* and what the certificate on disk already carries.
|
|
228
|
-
*/
|
|
229
|
-
/** The real machine. The only place in `tls/` that touches `os`. */
|
|
230
|
-
function systemHostFacts() {
|
|
231
|
-
return {
|
|
232
|
-
hostname: os.hostname(),
|
|
233
|
-
networkInterfaces: os.networkInterfaces()
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Interfaces whose addresses are certified but never gate a reissue:
|
|
238
|
-
* container bridges, VPN tunnels and mesh overlays hand out addresses
|
|
239
|
-
* that change without the hub moving.
|
|
240
|
-
*/
|
|
241
|
-
var VOLATILE_INTERFACE_PREFIXES = [
|
|
242
|
-
"docker",
|
|
243
|
-
"br-",
|
|
244
|
-
"veth",
|
|
245
|
-
"virbr",
|
|
246
|
-
"cni",
|
|
247
|
-
"flannel",
|
|
248
|
-
"tun",
|
|
249
|
-
"utun",
|
|
250
|
-
"tap",
|
|
251
|
-
"wg",
|
|
252
|
-
"zt",
|
|
253
|
-
"tailscale",
|
|
254
|
-
"ppp",
|
|
255
|
-
"awdl",
|
|
256
|
-
"llw"
|
|
257
|
-
];
|
|
258
|
-
/** A DNS name we are willing to put in a SAN. */
|
|
259
|
-
var DNS_NAME_PATTERN = /^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
260
|
-
function isIpv4(value) {
|
|
261
|
-
return isIP(value) === 4;
|
|
262
|
-
}
|
|
263
|
-
function isIpv6(value) {
|
|
264
|
-
return isIP(value) === 6;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* `fe80::/10` and `169.254.0.0/16`. An IPv6 link-local address needs a
|
|
268
|
-
* zone index to be usable and a SAN cannot carry one, so such an entry
|
|
269
|
-
* can never match anything — it is noise that makes the certificate look
|
|
270
|
-
* broader than it is.
|
|
271
|
-
*/
|
|
272
|
-
function isLinkLocal(value) {
|
|
273
|
-
if (isIpv4(value)) return value.startsWith("169.254.");
|
|
274
|
-
if (!isIpv6(value)) return false;
|
|
275
|
-
const firstGroup = value.split(":")[0] ?? "";
|
|
276
|
-
if (firstGroup === "") return false;
|
|
277
|
-
const parsed = Number.parseInt(firstGroup, 16);
|
|
278
|
-
return Number.isFinite(parsed) && (parsed & 65472) === 65152;
|
|
279
|
-
}
|
|
280
|
-
function isVolatileInterface(name) {
|
|
281
|
-
const lower = name.toLowerCase();
|
|
282
|
-
return VOLATILE_INTERFACE_PREFIXES.some((prefix) => lower.startsWith(prefix));
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Only IPv4 gates a reissue. Every IPv6 address we see — global **or**
|
|
286
|
-
* ULA — is certified but never required: `os` cannot tell a temporary
|
|
287
|
-
* address from a permanent one, and the live hub's ULA interface-id
|
|
288
|
-
* rotated on every restart (eight leaf reissues in one day under
|
|
289
|
-
* `san-coverage-gap`). Gating on ULA reproduced the churn D227 exists
|
|
290
|
-
* to prevent. Operators who need a fixed IPv6 declare it via `extraSans`.
|
|
291
|
-
*/
|
|
292
|
-
function isStableGateAddress(address) {
|
|
293
|
-
if (isLinkLocal(address)) return false;
|
|
294
|
-
return isIpv4(address);
|
|
295
|
-
}
|
|
296
|
-
function addSan(dns, ips, value) {
|
|
297
|
-
const trimmed = value.trim();
|
|
298
|
-
if (trimmed === "") return;
|
|
299
|
-
if (isIP(trimmed) !== 0) {
|
|
300
|
-
if (!isLinkLocal(trimmed)) ips.add(trimmed);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (DNS_NAME_PATTERN.test(trimmed)) dns.add(trimmed);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Snapshot the machine's identity. Called once per `ensureTlsCert`; the
|
|
307
|
-
* result is both the SAN list for a new leaf and the yardstick the
|
|
308
|
-
* existing leaf is measured against.
|
|
309
|
-
*/
|
|
310
|
-
function collectCertIdentity(options) {
|
|
311
|
-
const host = options.hostFacts ?? systemHostFacts();
|
|
312
|
-
const dnsNames = /* @__PURE__ */ new Set();
|
|
313
|
-
const ipAddresses = new Set(["127.0.0.1", "::1"]);
|
|
314
|
-
const requiredDnsNames = /* @__PURE__ */ new Set();
|
|
315
|
-
const requiredIpAddresses = new Set(["127.0.0.1"]);
|
|
316
|
-
for (const name of [
|
|
317
|
-
"localhost",
|
|
318
|
-
options.commonName,
|
|
319
|
-
host.hostname
|
|
320
|
-
]) {
|
|
321
|
-
addSan(dnsNames, ipAddresses, name);
|
|
322
|
-
addSan(requiredDnsNames, requiredIpAddresses, name);
|
|
323
|
-
}
|
|
324
|
-
for (const [ifaceName, addrs] of Object.entries(host.networkInterfaces)) for (const addr of addrs ?? []) {
|
|
325
|
-
if (addr.internal) continue;
|
|
326
|
-
if (isLinkLocal(addr.address)) continue;
|
|
327
|
-
ipAddresses.add(addr.address);
|
|
328
|
-
if (isVolatileInterface(ifaceName)) continue;
|
|
329
|
-
if (isStableGateAddress(addr.address)) requiredIpAddresses.add(addr.address);
|
|
330
|
-
}
|
|
331
|
-
for (const san of options.extraSans) {
|
|
332
|
-
addSan(dnsNames, ipAddresses, san);
|
|
333
|
-
addSan(requiredDnsNames, requiredIpAddresses, san);
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
dnsNames: [...dnsNames],
|
|
337
|
-
ipAddresses: [...ipAddresses],
|
|
338
|
-
requiredDnsNames: [...requiredDnsNames],
|
|
339
|
-
requiredIpAddresses: [...requiredIpAddresses]
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
2
|
/*! *****************************************************************************
|
|
343
3
|
Copyright (C) Microsoft. All rights reserved.
|
|
344
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -11247,8 +10907,44 @@ var Pkcs10CertificateRequest = class extends PemData {
|
|
|
11247
10907
|
};
|
|
11248
10908
|
_Pkcs10CertificateRequest_tbs = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_subjectName = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_subject = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_signatureAlgorithm = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_signature = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_publicKey = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_attributes = /* @__PURE__ */ new WeakMap(), _Pkcs10CertificateRequest_extensions = /* @__PURE__ */ new WeakMap();
|
|
11249
10909
|
Pkcs10CertificateRequest.NAME = "PKCS#10 Certificate Request";
|
|
10910
|
+
var Pkcs10CertificateRequestGenerator = class {
|
|
10911
|
+
static async create(params, crypto = cryptoProvider.get()) {
|
|
10912
|
+
if (!params.keys.privateKey) throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");
|
|
10913
|
+
if (!params.keys.publicKey) throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");
|
|
10914
|
+
const spki = await crypto.subtle.exportKey("spki", params.keys.publicKey);
|
|
10915
|
+
const asnReq = new CertificationRequest({ certificationRequestInfo: new CertificationRequestInfo({ subjectPKInfo: AsnConvert.parse(spki, SubjectPublicKeyInfo) }) });
|
|
10916
|
+
if (params.name) {
|
|
10917
|
+
const name = params.name instanceof Name ? params.name : new Name(params.name);
|
|
10918
|
+
asnReq.certificationRequestInfo.subject = AsnConvert.parse(name.toArrayBuffer(), Name$1);
|
|
10919
|
+
}
|
|
10920
|
+
if (params.attributes) for (const o of params.attributes) asnReq.certificationRequestInfo.attributes.push(AsnConvert.parse(o.rawData, Attribute$2));
|
|
10921
|
+
if (params.extensions && params.extensions.length) {
|
|
10922
|
+
const attr = new Attribute$2({ type: id_pkcs9_at_extensionRequest });
|
|
10923
|
+
const extensions = new Extensions();
|
|
10924
|
+
for (const o of params.extensions) extensions.push(AsnConvert.parse(o.rawData, Extension$1));
|
|
10925
|
+
attr.values.push(AsnConvert.serialize(extensions));
|
|
10926
|
+
asnReq.certificationRequestInfo.attributes.push(attr);
|
|
10927
|
+
}
|
|
10928
|
+
const signingAlgorithm = {
|
|
10929
|
+
...params.signingAlgorithm,
|
|
10930
|
+
...params.keys.privateKey.algorithm
|
|
10931
|
+
};
|
|
10932
|
+
asnReq.signatureAlgorithm = instance.resolve(diAlgorithmProvider).toAsnAlgorithm(signingAlgorithm);
|
|
10933
|
+
const tbs = AsnConvert.serialize(asnReq.certificationRequestInfo);
|
|
10934
|
+
const signature = await crypto.subtle.sign(signingAlgorithm, params.keys.privateKey, tbs);
|
|
10935
|
+
const signatureFormatters = instance.resolveAll(diAsnSignatureFormatter).reverse();
|
|
10936
|
+
let asnSignature = null;
|
|
10937
|
+
for (const signatureFormatter of signatureFormatters) {
|
|
10938
|
+
asnSignature = signatureFormatter.toAsnSignature(signingAlgorithm, signature);
|
|
10939
|
+
if (asnSignature) break;
|
|
10940
|
+
}
|
|
10941
|
+
if (!asnSignature) throw Error("Cannot convert WebCrypto signature value to ASN.1 format");
|
|
10942
|
+
asnReq.signature = asnSignature;
|
|
10943
|
+
return new Pkcs10CertificateRequest(AsnConvert.serialize(asnReq));
|
|
10944
|
+
}
|
|
10945
|
+
};
|
|
11250
10946
|
var _X509Certificate_tbs, _X509Certificate_serialNumber, _X509Certificate_subjectName, _X509Certificate_subject, _X509Certificate_issuerName, _X509Certificate_issuer, _X509Certificate_notBefore, _X509Certificate_notAfter, _X509Certificate_signatureAlgorithm, _X509Certificate_signature, _X509Certificate_extensions, _X509Certificate_publicKey;
|
|
11251
|
-
var X509Certificate
|
|
10947
|
+
var X509Certificate = class extends PemData {
|
|
11252
10948
|
get publicKey() {
|
|
11253
10949
|
if (!__classPrivateFieldGet(this, _X509Certificate_publicKey, "f")) __classPrivateFieldSet(this, _X509Certificate_publicKey, new PublicKey(this.asn.tbsCertificate.subjectPublicKeyInfo), "f");
|
|
11254
10950
|
return __classPrivateFieldGet(this, _X509Certificate_publicKey, "f");
|
|
@@ -11448,7 +11144,7 @@ var X509Certificate$1 = class extends PemData {
|
|
|
11448
11144
|
}
|
|
11449
11145
|
};
|
|
11450
11146
|
_X509Certificate_tbs = /* @__PURE__ */ new WeakMap(), _X509Certificate_serialNumber = /* @__PURE__ */ new WeakMap(), _X509Certificate_subjectName = /* @__PURE__ */ new WeakMap(), _X509Certificate_subject = /* @__PURE__ */ new WeakMap(), _X509Certificate_issuerName = /* @__PURE__ */ new WeakMap(), _X509Certificate_issuer = /* @__PURE__ */ new WeakMap(), _X509Certificate_notBefore = /* @__PURE__ */ new WeakMap(), _X509Certificate_notAfter = /* @__PURE__ */ new WeakMap(), _X509Certificate_signatureAlgorithm = /* @__PURE__ */ new WeakMap(), _X509Certificate_signature = /* @__PURE__ */ new WeakMap(), _X509Certificate_extensions = /* @__PURE__ */ new WeakMap(), _X509Certificate_publicKey = /* @__PURE__ */ new WeakMap();
|
|
11451
|
-
X509Certificate
|
|
11147
|
+
X509Certificate.NAME = "Certificate";
|
|
11452
11148
|
function generateCertificateSerialNumber(input, crypto = cryptoProvider.get()) {
|
|
11453
11149
|
const inputView = BufferSourceConverter.toUint8Array(Convert.FromHex(input || ""));
|
|
11454
11150
|
let serialNumber = inputView && inputView.length && inputView.some((o) => o > 0) ? new Uint8Array(inputView) : void 0;
|
|
@@ -11529,7 +11225,7 @@ var X509CertificateGenerator = class {
|
|
|
11529
11225
|
}
|
|
11530
11226
|
if (!asnSignature) throw Error("Cannot convert ASN.1 signature value to WebCrypto format");
|
|
11531
11227
|
asnX509.signatureValue = asnSignature;
|
|
11532
|
-
return new X509Certificate
|
|
11228
|
+
return new X509Certificate(AsnConvert.serialize(asnX509));
|
|
11533
11229
|
}
|
|
11534
11230
|
};
|
|
11535
11231
|
var X509CrlReason;
|
|
@@ -11563,610 +11259,4 @@ AsnEcSignatureFormatter.namedCurveSize.set("K-256", 32);
|
|
|
11563
11259
|
AsnEcSignatureFormatter.namedCurveSize.set("P-384", 48);
|
|
11564
11260
|
AsnEcSignatureFormatter.namedCurveSize.set("P-521", 66);
|
|
11565
11261
|
//#endregion
|
|
11566
|
-
|
|
11567
|
-
cryptoProvider.set(webcrypto);
|
|
11568
|
-
/** Subject of the local root. Distinct from the leaf's CN by construction. */
|
|
11569
|
-
var CA_COMMON_NAME = "CamStack Local CA";
|
|
11570
|
-
var MS_PER_DAY = 864e5;
|
|
11571
|
-
/**
|
|
11572
|
-
* RSA-2048 / SHA-256. Unchanged from the openssl invocation this replaces:
|
|
11573
|
-
* every client that trusted the previous material still understands this.
|
|
11574
|
-
*/
|
|
11575
|
-
var SIGNING_ALGORITHM = {
|
|
11576
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
11577
|
-
hash: "SHA-256",
|
|
11578
|
-
publicExponent: new Uint8Array([
|
|
11579
|
-
1,
|
|
11580
|
-
0,
|
|
11581
|
-
1
|
|
11582
|
-
]),
|
|
11583
|
-
modulusLength: 2048
|
|
11584
|
-
};
|
|
11585
|
-
/**
|
|
11586
|
-
* A serial number that is positive and unpredictable. `00` prefix for the
|
|
11587
|
-
* same reason the openssl invocation carried one: a leading bit of 1 would
|
|
11588
|
-
* make the DER INTEGER negative.
|
|
11589
|
-
*/
|
|
11590
|
-
function freshSerial() {
|
|
11591
|
-
return `00${randomBytes(16).toString("hex")}`;
|
|
11592
|
-
}
|
|
11593
|
-
function toPkcs8Pem(pkcs8) {
|
|
11594
|
-
return `${PemConverter.encode(pkcs8, "PRIVATE KEY")}\n`;
|
|
11595
|
-
}
|
|
11596
|
-
function toCertPem(cert) {
|
|
11597
|
-
return `${cert.toString("pem")}\n`;
|
|
11598
|
-
}
|
|
11599
|
-
async function exportKeyPem(key) {
|
|
11600
|
-
return toPkcs8Pem(await webcrypto.subtle.exportKey("pkcs8", key));
|
|
11601
|
-
}
|
|
11602
|
-
/** SAN entries, in the order `cert-identity` produced them. */
|
|
11603
|
-
function subjectAltNames(identity) {
|
|
11604
|
-
const names = [];
|
|
11605
|
-
for (const dns of identity.dnsNames) names.push({
|
|
11606
|
-
type: "dns",
|
|
11607
|
-
value: dns
|
|
11608
|
-
});
|
|
11609
|
-
for (const ip of identity.ipAddresses) if (isIP(ip) !== 0) names.push({
|
|
11610
|
-
type: "ip",
|
|
11611
|
-
value: ip
|
|
11612
|
-
});
|
|
11613
|
-
return names;
|
|
11614
|
-
}
|
|
11615
|
-
/**
|
|
11616
|
-
* A local root: 10 years, `pathlen:0` so it can sign leaves and nothing
|
|
11617
|
-
* else, and **no EKU** — Apple rejects an anchor asserting
|
|
11618
|
-
* `anyExtendedKeyUsage`, and a root with no EKU constrains nothing.
|
|
11619
|
-
*/
|
|
11620
|
-
async function generateCa(now) {
|
|
11621
|
-
const keys = await webcrypto.subtle.generateKey(SIGNING_ALGORITHM, true, ["sign", "verify"]);
|
|
11622
|
-
const extensions = [
|
|
11623
|
-
new BasicConstraintsExtension(true, 0, true),
|
|
11624
|
-
new KeyUsagesExtension(KeyUsageFlags.keyCertSign | KeyUsageFlags.cRLSign, true),
|
|
11625
|
-
await SubjectKeyIdentifierExtension.create(keys.publicKey)
|
|
11626
|
-
];
|
|
11627
|
-
const cert = await X509CertificateGenerator.createSelfSigned({
|
|
11628
|
-
serialNumber: freshSerial(),
|
|
11629
|
-
name: `CN=${CA_COMMON_NAME}`,
|
|
11630
|
-
notBefore: now,
|
|
11631
|
-
notAfter: new Date(now.getTime() + CA_VALIDITY_DAYS * MS_PER_DAY),
|
|
11632
|
-
keys,
|
|
11633
|
-
signingAlgorithm: SIGNING_ALGORITHM,
|
|
11634
|
-
extensions
|
|
11635
|
-
});
|
|
11636
|
-
return {
|
|
11637
|
-
certPem: toCertPem(cert),
|
|
11638
|
-
keyPem: await exportKeyPem(keys.privateKey),
|
|
11639
|
-
cert,
|
|
11640
|
-
privateKey: keys.privateKey
|
|
11641
|
-
};
|
|
11642
|
-
}
|
|
11643
|
-
/** Re-open a root already on disk so a leaf can be issued under it. */
|
|
11644
|
-
async function loadCa(certPem, keyPem) {
|
|
11645
|
-
return {
|
|
11646
|
-
certPem,
|
|
11647
|
-
keyPem,
|
|
11648
|
-
cert: new X509Certificate$1(certPem),
|
|
11649
|
-
privateKey: await webcrypto.subtle.importKey("pkcs8", PemConverter.decodeFirst(keyPem), SIGNING_ALGORITHM, true, ["sign"])
|
|
11650
|
-
};
|
|
11651
|
-
}
|
|
11652
|
-
/**
|
|
11653
|
-
* A server leaf signed by the local root: `CA:FALSE`, and
|
|
11654
|
-
* `extendedKeyUsage=serverAuth` — not `anyExtendedKeyUsage`, which
|
|
11655
|
-
* Apple's `testAppTrustRoot_AnyEKU_AfterJul2019` asserts must fail.
|
|
11656
|
-
*/
|
|
11657
|
-
async function issueLeaf(ca, identity, commonName, validDays, now) {
|
|
11658
|
-
const keys = await webcrypto.subtle.generateKey(SIGNING_ALGORITHM, true, ["sign", "verify"]);
|
|
11659
|
-
const extensions = [
|
|
11660
|
-
new BasicConstraintsExtension(false, void 0, true),
|
|
11661
|
-
new KeyUsagesExtension(KeyUsageFlags.digitalSignature | KeyUsageFlags.keyEncipherment, true),
|
|
11662
|
-
new ExtendedKeyUsageExtension([SERVER_AUTH_OID]),
|
|
11663
|
-
await SubjectKeyIdentifierExtension.create(keys.publicKey),
|
|
11664
|
-
await AuthorityKeyIdentifierExtension.create(ca.cert),
|
|
11665
|
-
new SubjectAlternativeNameExtension(subjectAltNames(identity))
|
|
11666
|
-
];
|
|
11667
|
-
return {
|
|
11668
|
-
certPem: toCertPem(await X509CertificateGenerator.create({
|
|
11669
|
-
serialNumber: freshSerial(),
|
|
11670
|
-
subject: `CN=${commonName}`,
|
|
11671
|
-
issuer: ca.cert.subject,
|
|
11672
|
-
notBefore: now,
|
|
11673
|
-
notAfter: new Date(now.getTime() + validDays * MS_PER_DAY),
|
|
11674
|
-
publicKey: keys.publicKey,
|
|
11675
|
-
signingKey: ca.privateKey,
|
|
11676
|
-
signingAlgorithm: SIGNING_ALGORITHM,
|
|
11677
|
-
extensions
|
|
11678
|
-
})),
|
|
11679
|
-
keyPem: await exportKeyPem(keys.privateKey)
|
|
11680
|
-
};
|
|
11681
|
-
}
|
|
11682
|
-
//#endregion
|
|
11683
|
-
//#region src/tls/cert-manager.ts
|
|
11684
|
-
var DEFAULT_COMMON_NAME = "camstack.local";
|
|
11685
|
-
/**
|
|
11686
|
-
* Ensure the hub has a usable TLS identity under `<dataDir>/tls`, made of
|
|
11687
|
-
* a long-lived local **root** (`camstack-ca.crt`) and a short **leaf**
|
|
11688
|
-
* chained to it (`camstack.crt` = leaf + root, `camstack.key`).
|
|
11689
|
-
*
|
|
11690
|
-
* ## The regeneration rule (D227)
|
|
11691
|
-
*
|
|
11692
|
-
* Reissue happens when, and only when, the material on disk **cannot do
|
|
11693
|
-
* its job**:
|
|
11694
|
-
*
|
|
11695
|
-
* - it is absent, unreadable, or the key does not match the certificate;
|
|
11696
|
-
* - the root is absent (every pre-2026-08 install: one self-signed
|
|
11697
|
-
* `CA:TRUE` leaf and no root) or is inside its renewal window;
|
|
11698
|
-
* - the leaf is inside its 30-day renewal window;
|
|
11699
|
-
* - the leaf lacks `extendedKeyUsage = serverAuth` — Apple's trustd
|
|
11700
|
-
* rejects an app-supplied anchor without it;
|
|
11701
|
-
* - the leaf is not actually issued by the root on disk;
|
|
11702
|
-
* - the leaf's validity span exceeds {@link MAX_LEAF_VALIDITY_DAYS};
|
|
11703
|
-
* - **a name or address the hub must answer for is missing from the SAN
|
|
11704
|
-
* list** — a DHCP move, a new interface or a new hostname.
|
|
11705
|
-
*
|
|
11706
|
-
* And explicitly NOT when: the certificate names an address the machine
|
|
11707
|
-
* no longer has (a superset still works — the check is one-directional),
|
|
11708
|
-
* a volatile interface (docker/VPN/mesh) or **any** IPv6 address changed
|
|
11709
|
-
* (global and ULA both rotate under privacy extensions / interface-id
|
|
11710
|
-
* churn — `os` cannot tell temporary from permanent), or a new build shipped.
|
|
11711
|
-
*
|
|
11712
|
-
* Every trigger is derived from the files plus the machine, so once a
|
|
11713
|
-
* reissue clears them it clears them for good: the next boot returns
|
|
11714
|
-
* `generated: false`. A certificate that moved on every boot would
|
|
11715
|
-
* invalidate every trust an operator granted by hand — worse than the
|
|
11716
|
-
* bugs this rule fixes.
|
|
11717
|
-
*
|
|
11718
|
-
* **The root is rotated only for root-level reasons.** SAN drift rotates
|
|
11719
|
-
* the leaf alone, so trust granted to `camstack-ca.crt` survives every
|
|
11720
|
-
* address change the hub will ever see.
|
|
11721
|
-
*/
|
|
11722
|
-
async function ensureTlsCert(dataDir, options) {
|
|
11723
|
-
const tlsDir = join(dataDir, "tls");
|
|
11724
|
-
const paths = {
|
|
11725
|
-
certPath: join(tlsDir, "camstack.crt"),
|
|
11726
|
-
keyPath: join(tlsDir, "camstack.key"),
|
|
11727
|
-
caCertPath: join(tlsDir, "camstack-ca.crt"),
|
|
11728
|
-
caKeyPath: join(tlsDir, "camstack-ca.key")
|
|
11729
|
-
};
|
|
11730
|
-
const commonName = options?.commonName ?? DEFAULT_COMMON_NAME;
|
|
11731
|
-
const validDays = Math.min(options?.validDays ?? 397, 397);
|
|
11732
|
-
const identity = collectCertIdentity({
|
|
11733
|
-
commonName,
|
|
11734
|
-
extraSans: options?.extraSans ?? [],
|
|
11735
|
-
...options?.hostFacts === void 0 ? {} : { hostFacts: options.hostFacts }
|
|
11736
|
-
});
|
|
11737
|
-
const reason = decideRegeneration(paths, identity);
|
|
11738
|
-
if (reason === null) return describe(paths, false, null, false, null, null);
|
|
11739
|
-
const previousFingerprint = readFingerprint(paths.certPath);
|
|
11740
|
-
const caRotated = reasonRequiresNewCa(reason);
|
|
11741
|
-
mkdirSync(tlsDir, { recursive: true });
|
|
11742
|
-
try {
|
|
11743
|
-
await regenerate(paths, identity, commonName, validDays, caRotated);
|
|
11744
|
-
} catch (err) {
|
|
11745
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
11746
|
-
if (!canKeepServing(paths)) throw err;
|
|
11747
|
-
return describe(paths, false, null, false, null, message);
|
|
11748
|
-
}
|
|
11749
|
-
return describe(paths, true, reason, caRotated, previousFingerprint, null);
|
|
11750
|
-
}
|
|
11751
|
-
/**
|
|
11752
|
-
* Operator "Regenerate": issue a new leaf under the existing local CA.
|
|
11753
|
-
* Never rotates the root — trust granted to `camstack-ca.crt` survives.
|
|
11754
|
-
*/
|
|
11755
|
-
async function reissueTlsLeaf(dataDir, options) {
|
|
11756
|
-
const tlsDir = join(dataDir, "tls");
|
|
11757
|
-
const paths = {
|
|
11758
|
-
certPath: join(tlsDir, "camstack.crt"),
|
|
11759
|
-
keyPath: join(tlsDir, "camstack.key"),
|
|
11760
|
-
caCertPath: join(tlsDir, "camstack-ca.crt"),
|
|
11761
|
-
caKeyPath: join(tlsDir, "camstack-ca.key")
|
|
11762
|
-
};
|
|
11763
|
-
if (!existsSync(paths.caCertPath) || !existsSync(paths.caKeyPath)) return ensureTlsCert(dataDir, options);
|
|
11764
|
-
const commonName = options?.commonName ?? DEFAULT_COMMON_NAME;
|
|
11765
|
-
const validDays = Math.min(options?.validDays ?? 397, 397);
|
|
11766
|
-
const identity = collectCertIdentity({
|
|
11767
|
-
commonName,
|
|
11768
|
-
extraSans: options?.extraSans ?? [],
|
|
11769
|
-
...options?.hostFacts === void 0 ? {} : { hostFacts: options.hostFacts }
|
|
11770
|
-
});
|
|
11771
|
-
const previousFingerprint = readFingerprint(paths.certPath);
|
|
11772
|
-
mkdirSync(tlsDir, { recursive: true });
|
|
11773
|
-
await regenerate(paths, identity, commonName, validDays, false);
|
|
11774
|
-
return describe(paths, true, "san-coverage-gap", false, previousFingerprint, null);
|
|
11775
|
-
}
|
|
11776
|
-
/** True when the material already on disk can still terminate TLS. */
|
|
11777
|
-
function canKeepServing(paths) {
|
|
11778
|
-
if (!existsSync(paths.certPath) || !existsSync(paths.keyPath)) return false;
|
|
11779
|
-
if (!existsSync(paths.caCertPath)) return false;
|
|
11780
|
-
return readFingerprint(paths.certPath) !== null;
|
|
11781
|
-
}
|
|
11782
|
-
/** Fingerprint of whatever is on disk, or `null` if there is nothing readable. */
|
|
11783
|
-
function readFingerprint(certPath) {
|
|
11784
|
-
try {
|
|
11785
|
-
return new X509Certificate(readFileSync(certPath)).fingerprint256;
|
|
11786
|
-
} catch {
|
|
11787
|
-
return null;
|
|
11788
|
-
}
|
|
11789
|
-
}
|
|
11790
|
-
function decideRegeneration(paths, identity) {
|
|
11791
|
-
if (!existsSync(paths.certPath) || !existsSync(paths.keyPath)) return "missing";
|
|
11792
|
-
if (!existsSync(paths.caCertPath) || !existsSync(paths.caKeyPath)) return "no-local-ca";
|
|
11793
|
-
try {
|
|
11794
|
-
return evaluateExistingCert({
|
|
11795
|
-
chainPem: readFileSync(paths.certPath, "utf-8"),
|
|
11796
|
-
keyPem: readFileSync(paths.keyPath, "utf-8"),
|
|
11797
|
-
caPem: readFileSync(paths.caCertPath, "utf-8"),
|
|
11798
|
-
identity,
|
|
11799
|
-
now: /* @__PURE__ */ new Date()
|
|
11800
|
-
});
|
|
11801
|
-
} catch {
|
|
11802
|
-
return "unreadable";
|
|
11803
|
-
}
|
|
11804
|
-
}
|
|
11805
|
-
/**
|
|
11806
|
-
* Build every byte in memory, then move the files into place. A crash
|
|
11807
|
-
* mid-way leaves the previous material untouched; a crash between the
|
|
11808
|
-
* moves leaves a key/certificate mismatch, which the evaluator reports as
|
|
11809
|
-
* `key-mismatch` and heals on the next boot.
|
|
11810
|
-
*/
|
|
11811
|
-
async function regenerate(paths, identity, commonName, validDays, newCa) {
|
|
11812
|
-
const now = /* @__PURE__ */ new Date();
|
|
11813
|
-
const ca = newCa ? await generateCa(now) : await loadCa(readFileSync(paths.caCertPath, "utf-8"), readFileSync(paths.caKeyPath, "utf-8"));
|
|
11814
|
-
const leaf = await issueLeaf(ca, identity, commonName, validDays, now);
|
|
11815
|
-
const chainPem = `${leaf.certPem.trimEnd()}\n${ca.certPem.trimEnd()}\n`;
|
|
11816
|
-
if (newCa) {
|
|
11817
|
-
await writeFile(`${paths.caCertPath}.new`, ca.certPem, "utf-8");
|
|
11818
|
-
await writeFile(`${paths.caKeyPath}.new`, ca.keyPem, {
|
|
11819
|
-
encoding: "utf-8",
|
|
11820
|
-
mode: 384
|
|
11821
|
-
});
|
|
11822
|
-
renameSync(`${paths.caCertPath}.new`, paths.caCertPath);
|
|
11823
|
-
renameSync(`${paths.caKeyPath}.new`, paths.caKeyPath);
|
|
11824
|
-
await chmod(paths.caKeyPath, 384);
|
|
11825
|
-
}
|
|
11826
|
-
await writeFile(`${paths.keyPath}.new`, leaf.keyPem, {
|
|
11827
|
-
encoding: "utf-8",
|
|
11828
|
-
mode: 384
|
|
11829
|
-
});
|
|
11830
|
-
await writeFile(`${paths.certPath}.new`, chainPem, "utf-8");
|
|
11831
|
-
renameSync(`${paths.keyPath}.new`, paths.keyPath);
|
|
11832
|
-
renameSync(`${paths.certPath}.new`, paths.certPath);
|
|
11833
|
-
await chmod(paths.keyPath, 384);
|
|
11834
|
-
}
|
|
11835
|
-
function describe(paths, generated, reason, caRotated, previousFingerprintSha256, reissueError) {
|
|
11836
|
-
const leaf = new X509Certificate(readFileSync(paths.certPath));
|
|
11837
|
-
const ca = new X509Certificate(readFileSync(paths.caCertPath));
|
|
11838
|
-
const san = leaf.subjectAltName ?? "";
|
|
11839
|
-
return {
|
|
11840
|
-
...paths,
|
|
11841
|
-
generated,
|
|
11842
|
-
reason,
|
|
11843
|
-
caRotated,
|
|
11844
|
-
fingerprintSha256: leaf.fingerprint256,
|
|
11845
|
-
previousFingerprintSha256,
|
|
11846
|
-
caFingerprintSha256: ca.fingerprint256,
|
|
11847
|
-
validTo: new Date(leaf.validTo).toISOString(),
|
|
11848
|
-
sans: san === "" ? [] : san.split(", "),
|
|
11849
|
-
reissueError
|
|
11850
|
-
};
|
|
11851
|
-
}
|
|
11852
|
-
/**
|
|
11853
|
-
* Load TLS cert+key from files. Returns Buffers suitable for Node.js TLS
|
|
11854
|
-
* options. `certPath` is a full chain, so the listener presents the local
|
|
11855
|
-
* root alongside the leaf.
|
|
11856
|
-
*/
|
|
11857
|
-
function loadTlsCert(certPath, keyPath) {
|
|
11858
|
-
return {
|
|
11859
|
-
cert: readFileSync(certPath),
|
|
11860
|
-
key: readFileSync(keyPath)
|
|
11861
|
-
};
|
|
11862
|
-
}
|
|
11863
|
-
//#endregion
|
|
11864
|
-
//#region src/tls/tls-status.ts
|
|
11865
|
-
function tlsDir(dataDir) {
|
|
11866
|
-
return join(dataDir, "tls");
|
|
11867
|
-
}
|
|
11868
|
-
function readTlsMode(dataDir) {
|
|
11869
|
-
const marker = join(tlsDir(dataDir), "mode");
|
|
11870
|
-
if (existsSync(marker)) {
|
|
11871
|
-
const raw = readFileSync(marker, "utf-8").trim();
|
|
11872
|
-
if (raw === "uploaded") return "uploaded";
|
|
11873
|
-
if (raw === "disabled") return "disabled";
|
|
11874
|
-
}
|
|
11875
|
-
return existsSync(join(tlsDir(dataDir), "camstack.crt")) ? "generated" : "disabled";
|
|
11876
|
-
}
|
|
11877
|
-
function writeTlsMode(dataDir, mode) {
|
|
11878
|
-
mkdirSync(tlsDir(dataDir), { recursive: true });
|
|
11879
|
-
writeFileSync(join(tlsDir(dataDir), "mode"), `${mode}\n`, "utf-8");
|
|
11880
|
-
}
|
|
11881
|
-
function readExtraSans(dataDir) {
|
|
11882
|
-
const path = join(tlsDir(dataDir), "extra-sans.json");
|
|
11883
|
-
if (!existsSync(path)) return [];
|
|
11884
|
-
try {
|
|
11885
|
-
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
11886
|
-
if (!Array.isArray(parsed)) return [];
|
|
11887
|
-
return parsed.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
11888
|
-
} catch {
|
|
11889
|
-
return [];
|
|
11890
|
-
}
|
|
11891
|
-
}
|
|
11892
|
-
function writeExtraSans(dataDir, sans) {
|
|
11893
|
-
mkdirSync(tlsDir(dataDir), { recursive: true });
|
|
11894
|
-
writeFileSync(join(tlsDir(dataDir), "extra-sans.json"), `${JSON.stringify(sans)}\n`, "utf-8");
|
|
11895
|
-
}
|
|
11896
|
-
/** Where an upload's own CA is kept — never over the local CA's `camstack-ca.crt`. */
|
|
11897
|
-
var UPLOADED_CA_FILE = "uploaded-ca.crt";
|
|
11898
|
-
/** Every certificate in a PEM bundle, in order. */
|
|
11899
|
-
function splitPemCertificates(pem) {
|
|
11900
|
-
const blocks = pem.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g);
|
|
11901
|
-
return blocks === null ? [] : blocks.map((block) => `${block}\n`);
|
|
11902
|
-
}
|
|
11903
|
-
/**
|
|
11904
|
-
* The certificate that signed `leaf`, from the upload itself: the CA the
|
|
11905
|
-
* operator supplied, else the rest of the uploaded chain. `null` when the
|
|
11906
|
-
* upload did not include it — and then nothing may stand in for it: the
|
|
11907
|
-
* local CA did not sign an uploaded leaf, so handing it out as "the CA" would
|
|
11908
|
-
* tell a client to trust a root that verifies nothing it is served.
|
|
11909
|
-
*/
|
|
11910
|
-
function uploadedIssuer(dir, leaf, chainPem) {
|
|
11911
|
-
const caPath = join(dir, UPLOADED_CA_FILE);
|
|
11912
|
-
const candidates = [...existsSync(caPath) ? splitPemCertificates(readFileSync(caPath, "utf-8")) : [], ...splitPemCertificates(chainPem).slice(1)];
|
|
11913
|
-
for (const pem of candidates) try {
|
|
11914
|
-
const cert = new X509Certificate(pem);
|
|
11915
|
-
if (leaf.checkIssued(cert) && leaf.verify(cert.publicKey)) return {
|
|
11916
|
-
pem,
|
|
11917
|
-
cert
|
|
11918
|
-
};
|
|
11919
|
-
} catch {}
|
|
11920
|
-
return null;
|
|
11921
|
-
}
|
|
11922
|
-
function generatedIssuer(dir) {
|
|
11923
|
-
const caPath = join(dir, "camstack-ca.crt");
|
|
11924
|
-
if (!existsSync(caPath)) return null;
|
|
11925
|
-
const pem = readFileSync(caPath, "utf-8");
|
|
11926
|
-
return {
|
|
11927
|
-
pem,
|
|
11928
|
-
cert: new X509Certificate(pem)
|
|
11929
|
-
};
|
|
11930
|
-
}
|
|
11931
|
-
/**
|
|
11932
|
-
* What the node's certificate is, and whether the listener serves it.
|
|
11933
|
-
* `servedLeafFingerprint` is the leaf the HTTPS listener presents right now
|
|
11934
|
-
* (`servedHttpsLeafFingerprint()`), or `null` when unknown; a restart is
|
|
11935
|
-
* required exactly when the listener serves a different leaf than the one
|
|
11936
|
-
* on disk — a measured fact, not a flag a mutation remembered to set.
|
|
11937
|
-
*/
|
|
11938
|
-
function readTlsAccessStatus(dataDir, servedLeafFingerprint) {
|
|
11939
|
-
const dir = tlsDir(dataDir);
|
|
11940
|
-
const certPath = join(dir, "camstack.crt");
|
|
11941
|
-
const mode = readTlsMode(dataDir);
|
|
11942
|
-
if (!existsSync(certPath)) return {
|
|
11943
|
-
mode: "disabled",
|
|
11944
|
-
leafFingerprintSha256: null,
|
|
11945
|
-
caFingerprintSha256: null,
|
|
11946
|
-
validTo: null,
|
|
11947
|
-
sans: [],
|
|
11948
|
-
caCertPem: (mode === "uploaded" ? null : generatedIssuer(dir))?.pem ?? null,
|
|
11949
|
-
reissueError: null,
|
|
11950
|
-
restartRequired: false
|
|
11951
|
-
};
|
|
11952
|
-
try {
|
|
11953
|
-
const chainPem = readFileSync(certPath, "utf-8");
|
|
11954
|
-
const leaf = new X509Certificate(chainPem);
|
|
11955
|
-
const ca = mode === "uploaded" ? uploadedIssuer(dir, leaf, chainPem) : generatedIssuer(dir);
|
|
11956
|
-
const san = leaf.subjectAltName ?? "";
|
|
11957
|
-
return {
|
|
11958
|
-
mode,
|
|
11959
|
-
leafFingerprintSha256: leaf.fingerprint256,
|
|
11960
|
-
caFingerprintSha256: ca?.cert.fingerprint256 ?? null,
|
|
11961
|
-
validTo: new Date(leaf.validTo).toISOString(),
|
|
11962
|
-
sans: san === "" ? [] : san.split(", "),
|
|
11963
|
-
caCertPem: ca?.pem ?? null,
|
|
11964
|
-
reissueError: null,
|
|
11965
|
-
restartRequired: servedLeafFingerprint !== null && servedLeafFingerprint !== leaf.fingerprint256
|
|
11966
|
-
};
|
|
11967
|
-
} catch {
|
|
11968
|
-
return {
|
|
11969
|
-
mode,
|
|
11970
|
-
leafFingerprintSha256: null,
|
|
11971
|
-
caFingerprintSha256: null,
|
|
11972
|
-
validTo: null,
|
|
11973
|
-
sans: [],
|
|
11974
|
-
caCertPem: null,
|
|
11975
|
-
reissueError: "Certificate on disk could not be parsed.",
|
|
11976
|
-
restartRequired: false
|
|
11977
|
-
};
|
|
11978
|
-
}
|
|
11979
|
-
}
|
|
11980
|
-
//#endregion
|
|
11981
|
-
//#region src/tls/boot-tls.ts
|
|
11982
|
-
/**
|
|
11983
|
-
* Decide what the listener serves at boot. The admin UI (Network → Local
|
|
11984
|
-
* access) is the only way to set a certificate (D726): it either leaves the
|
|
11985
|
-
* hub on its generated local-CA leaf (D227) or uploads one, recorded by the
|
|
11986
|
-
* `tls/mode` marker. An uploaded certificate is served verbatim — running it
|
|
11987
|
-
* through `ensureTlsCert` would replace it on the first restart, because a
|
|
11988
|
-
* leaf the local root did not issue is one of that rule's reissue triggers.
|
|
11989
|
-
*/
|
|
11990
|
-
async function prepareBootTls(dataDir, options) {
|
|
11991
|
-
const certPath = join(dataDir, "tls", "camstack.crt");
|
|
11992
|
-
const keyPath = join(dataDir, "tls", "camstack.key");
|
|
11993
|
-
const marked = readTlsMode(dataDir);
|
|
11994
|
-
if (marked === "uploaded" && existsSync(certPath) && existsSync(keyPath)) return {
|
|
11995
|
-
mode: "uploaded",
|
|
11996
|
-
pair: loadTlsCert(certPath, keyPath),
|
|
11997
|
-
ensured: void 0,
|
|
11998
|
-
uploadedMissing: false
|
|
11999
|
-
};
|
|
12000
|
-
const uploadedMissing = marked === "uploaded";
|
|
12001
|
-
if (uploadedMissing) writeTlsMode(dataDir, "generated");
|
|
12002
|
-
const ensured = await ensureTlsCert(dataDir, options);
|
|
12003
|
-
return {
|
|
12004
|
-
mode: "generated",
|
|
12005
|
-
pair: loadTlsCert(ensured.certPath, ensured.keyPath),
|
|
12006
|
-
ensured,
|
|
12007
|
-
uploadedMissing
|
|
12008
|
-
};
|
|
12009
|
-
}
|
|
12010
|
-
//#endregion
|
|
12011
|
-
//#region src/tls/https-listener.ts
|
|
12012
|
-
var SLOT_KEY = Symbol.for("camstack.tls.https-listener");
|
|
12013
|
-
var EMPTY_SLOT = {
|
|
12014
|
-
reload: null,
|
|
12015
|
-
servedLeafFingerprint: null
|
|
12016
|
-
};
|
|
12017
|
-
function isSlot(value) {
|
|
12018
|
-
if (typeof value !== "object" || value === null) return false;
|
|
12019
|
-
if (!("reload" in value) || !("servedLeafFingerprint" in value)) return false;
|
|
12020
|
-
const reload = value.reload;
|
|
12021
|
-
const served = value.servedLeafFingerprint;
|
|
12022
|
-
return (reload === null || typeof reload === "function") && (served === null || typeof served === "string");
|
|
12023
|
-
}
|
|
12024
|
-
function readSlot() {
|
|
12025
|
-
const current = Reflect.get(globalThis, SLOT_KEY);
|
|
12026
|
-
return isSlot(current) ? current : EMPTY_SLOT;
|
|
12027
|
-
}
|
|
12028
|
-
function writeSlot(next) {
|
|
12029
|
-
Reflect.set(globalThis, SLOT_KEY, next);
|
|
12030
|
-
}
|
|
12031
|
-
/** SHA-256 fingerprint of the first certificate (the leaf) in a PEM chain. */
|
|
12032
|
-
function leafFingerprintOf(chain) {
|
|
12033
|
-
return new X509Certificate(chain).fingerprint256;
|
|
12034
|
-
}
|
|
12035
|
-
/**
|
|
12036
|
-
* Called once by the server after its HTTPS listener is up, with the pair it
|
|
12037
|
-
* was started on. From here on a certificate action swaps the served
|
|
12038
|
-
* certificate in place (`setSecureContext`) — new handshakes get the new
|
|
12039
|
-
* leaf, open connections keep theirs, nothing restarts.
|
|
12040
|
-
*/
|
|
12041
|
-
function registerHttpsListener(server, pair) {
|
|
12042
|
-
writeSlot({
|
|
12043
|
-
reload: (next) => server.setSecureContext({
|
|
12044
|
-
cert: next.cert,
|
|
12045
|
-
key: next.key
|
|
12046
|
-
}),
|
|
12047
|
-
servedLeafFingerprint: leafFingerprintOf(pair.cert)
|
|
12048
|
-
});
|
|
12049
|
-
}
|
|
12050
|
-
/** Forget the listener — on shutdown, and between specs. */
|
|
12051
|
-
function clearHttpsListener() {
|
|
12052
|
-
writeSlot(EMPTY_SLOT);
|
|
12053
|
-
}
|
|
12054
|
-
/**
|
|
12055
|
-
* The leaf the HTTPS listener serves now, or `null` when this process has no
|
|
12056
|
-
* registered listener (TLS off, or a process that does not own one) — in
|
|
12057
|
-
* which case nobody can say, and `null` is the honest answer.
|
|
12058
|
-
*/
|
|
12059
|
-
function servedHttpsLeafFingerprint() {
|
|
12060
|
-
return readSlot().servedLeafFingerprint;
|
|
12061
|
-
}
|
|
12062
|
-
/** Serve `pair` from now on. Never throws: the outcome says what happened. */
|
|
12063
|
-
function reloadHttpsListener(pair) {
|
|
12064
|
-
const slot = readSlot();
|
|
12065
|
-
if (slot.reload === null) return { kind: "no-listener" };
|
|
12066
|
-
try {
|
|
12067
|
-
const servedLeafFingerprint = leafFingerprintOf(pair.cert);
|
|
12068
|
-
slot.reload(pair);
|
|
12069
|
-
writeSlot({
|
|
12070
|
-
reload: slot.reload,
|
|
12071
|
-
servedLeafFingerprint
|
|
12072
|
-
});
|
|
12073
|
-
return {
|
|
12074
|
-
kind: "reloaded",
|
|
12075
|
-
servedLeafFingerprint
|
|
12076
|
-
};
|
|
12077
|
-
} catch (err) {
|
|
12078
|
-
return {
|
|
12079
|
-
kind: "failed",
|
|
12080
|
-
error: err instanceof Error ? err.message : String(err)
|
|
12081
|
-
};
|
|
12082
|
-
}
|
|
12083
|
-
}
|
|
12084
|
-
//#endregion
|
|
12085
|
-
//#region src/tls/uploaded-cert.ts
|
|
12086
|
-
/**
|
|
12087
|
-
* Operator-supplied material must parse, match its key, and carry
|
|
12088
|
-
* `extendedKeyUsage = serverAuth` — the same leaf defects D227 refused
|
|
12089
|
-
* to keep generating.
|
|
12090
|
-
*/
|
|
12091
|
-
function validateUploadedTls(certPem, keyPem) {
|
|
12092
|
-
let leaf;
|
|
12093
|
-
try {
|
|
12094
|
-
leaf = new X509Certificate(certPem);
|
|
12095
|
-
} catch {
|
|
12096
|
-
return {
|
|
12097
|
-
ok: false,
|
|
12098
|
-
error: "Certificate PEM could not be parsed."
|
|
12099
|
-
};
|
|
12100
|
-
}
|
|
12101
|
-
try {
|
|
12102
|
-
if (!leaf.checkPrivateKey(createPrivateKey(keyPem))) return {
|
|
12103
|
-
ok: false,
|
|
12104
|
-
error: "Private key does not match the certificate."
|
|
12105
|
-
};
|
|
12106
|
-
} catch {
|
|
12107
|
-
return {
|
|
12108
|
-
ok: false,
|
|
12109
|
-
error: "Private key PEM could not be parsed."
|
|
12110
|
-
};
|
|
12111
|
-
}
|
|
12112
|
-
const eku = leaf.keyUsage;
|
|
12113
|
-
if (eku === void 0 || !eku.includes("1.3.6.1.5.5.7.3.1")) return {
|
|
12114
|
-
ok: false,
|
|
12115
|
-
error: "Certificate is missing extendedKeyUsage = serverAuth."
|
|
12116
|
-
};
|
|
12117
|
-
return {
|
|
12118
|
-
ok: true,
|
|
12119
|
-
fingerprintSha256: leaf.fingerprint256,
|
|
12120
|
-
validTo: new Date(leaf.validTo).toISOString()
|
|
12121
|
-
};
|
|
12122
|
-
}
|
|
12123
|
-
//#endregion
|
|
12124
|
-
//#region src/tls/tls-actions.ts
|
|
12125
|
-
function withNewline(pem) {
|
|
12126
|
-
return pem.endsWith("\n") ? pem : `${pem}\n`;
|
|
12127
|
-
}
|
|
12128
|
-
/**
|
|
12129
|
-
* Store an operator's certificate. The leaf (or chain) and key replace the
|
|
12130
|
-
* served pair; a CA, when given, goes to its own file. The local CA
|
|
12131
|
-
* (`camstack-ca.crt` + key) is never touched — it did not sign the upload,
|
|
12132
|
-
* and it is what "Revert to generated" and every device that trusts it
|
|
12133
|
-
* still need.
|
|
12134
|
-
*/
|
|
12135
|
-
async function storeUploadedCertificate(dataDir, input) {
|
|
12136
|
-
const valid = validateUploadedTls(input.certPem, input.keyPem);
|
|
12137
|
-
if (!valid.ok) throw new Error(valid.error);
|
|
12138
|
-
const dir = join(dataDir, "tls");
|
|
12139
|
-
await mkdir(dir, { recursive: true });
|
|
12140
|
-
await writeFile(join(dir, "camstack.crt"), withNewline(input.certPem));
|
|
12141
|
-
await writeFile(join(dir, "camstack.key"), withNewline(input.keyPem), { mode: 384 });
|
|
12142
|
-
const caPath = join(dir, UPLOADED_CA_FILE);
|
|
12143
|
-
if (input.caPem !== void 0 && input.caPem.trim() !== "") await writeFile(caPath, withNewline(input.caPem));
|
|
12144
|
-
else rmSync(caPath, { force: true });
|
|
12145
|
-
writeTlsMode(dataDir, "uploaded");
|
|
12146
|
-
}
|
|
12147
|
-
/** Issue a new generated leaf under the local CA. Refused while an upload is served. */
|
|
12148
|
-
async function regenerateCertificate(dataDir, options) {
|
|
12149
|
-
if (readTlsMode(dataDir) === "uploaded") throw new Error("Cannot regenerate an uploaded certificate — revert to generated first.");
|
|
12150
|
-
await reissueTlsLeaf(dataDir, options);
|
|
12151
|
-
}
|
|
12152
|
-
/** Drop the upload and serve the generated local-CA leaf again (D227). */
|
|
12153
|
-
async function revertToGeneratedCertificate(dataDir, options) {
|
|
12154
|
-
writeTlsMode(dataDir, "generated");
|
|
12155
|
-
rmSync(join(dataDir, "tls", UPLOADED_CA_FILE), { force: true });
|
|
12156
|
-
await ensureTlsCert(dataDir, options);
|
|
12157
|
-
}
|
|
12158
|
-
/**
|
|
12159
|
-
* Put the pair on disk on the HTTPS listener. Called after every action, so
|
|
12160
|
-
* "the certificate changed" and "clients see it" are the same moment.
|
|
12161
|
-
*/
|
|
12162
|
-
function applyCertificateToListener(dataDir) {
|
|
12163
|
-
const certPath = join(dataDir, "tls", "camstack.crt");
|
|
12164
|
-
const keyPath = join(dataDir, "tls", "camstack.key");
|
|
12165
|
-
if (!existsSync(certPath) || !existsSync(keyPath)) return {
|
|
12166
|
-
kind: "failed",
|
|
12167
|
-
error: `No certificate pair under ${join(dataDir, "tls")}`
|
|
12168
|
-
};
|
|
12169
|
-
return reloadHttpsListener(loadTlsCert(certPath, keyPath));
|
|
12170
|
-
}
|
|
12171
|
-
//#endregion
|
|
12172
|
-
export { allFamiliesListenHost as A, collectCertIdentity as C, SERVER_AUTH_OID as D, MAX_LEAF_VALIDITY_DAYS as E, registerLanHttpHandler as F, bindPendingLanHttp as M, closeLanHttp as N, evaluateExistingCert as O, readLanHttpState as P, CA_COMMON_NAME as S, LEAF_RENEWAL_WINDOW_DAYS as T, writeExtraSans as _, validateUploadedTls as a, loadTlsCert as b, registerHttpsListener as c, prepareBootTls as d, UPLOADED_CA_FILE as f, splitPemCertificates as g, readTlsMode as h, storeUploadedCertificate as i, applyLanHttp as j, DEFAULT_LAN_HTTP_PORT as k, reloadHttpsListener as l, readTlsAccessStatus as m, regenerateCertificate as n, clearHttpsListener as o, readExtraSans as p, revertToGeneratedCertificate as r, leafFingerprintOf as s, applyCertificateToListener as t, servedHttpsLeafFingerprint as u, writeTlsMode as v, CA_VALIDITY_DAYS as w, reissueTlsLeaf as x, ensureTlsCert as y };
|
|
11262
|
+
export { KeyUsagesExtension as a, Pkcs10CertificateRequestGenerator as c, X509Certificate as d, X509CertificateGenerator as f, KeyUsageFlags as i, SubjectAlternativeNameExtension as l, BasicConstraintsExtension as n, PemConverter as o, cryptoProvider as p, ExtendedKeyUsageExtension as r, Pkcs10CertificateRequest as s, AuthorityKeyIdentifierExtension as t, SubjectKeyIdentifierExtension as u };
|