@camstack/system 1.2.114 → 1.2.115
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 +1 -1
- package/dist/addon-runner.mjs +1 -1
- 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.d.ts +1 -1
- package/dist/builtins/alerts/alerts.addon.js +6 -1
- package/dist/builtins/alerts/alerts.addon.mjs +6 -1
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- 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 +1 -1
- package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
- 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/doorbell/virtual-doorbell.addon.js +1 -1
- package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
- package/dist/builtins/hub-forwarder/index.js +1 -1
- package/dist/builtins/hub-forwarder/index.mjs +1 -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.js +1 -1
- package/dist/builtins/local-auth/local-auth.addon.mjs +3 -3
- package/dist/builtins/local-network/local-network.addon.js +1 -1
- package/dist/builtins/local-network/local-network.addon.mjs +1 -1
- 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/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 +2 -2
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/dist/builtins/system-config/system-config.addon.js +1 -1
- package/dist/builtins/system-config/system-config.addon.mjs +1 -1
- package/dist/builtins/winston-logging/index.js +1 -1
- package/dist/builtins/winston-logging/index.mjs +1 -1
- package/dist/{dist-CJ8RRSvQ.mjs → dist-Drb54SZD.mjs} +10 -1
- package/dist/{dist-C1Aea3c6.js → dist-iAwSA2_f.js} +10 -1
- package/dist/index.js +438 -47
- package/dist/index.mjs +435 -50
- package/dist/{retired-settings-keys-C1efPfyW.mjs → retired-settings-keys-Dz5-7gjt.mjs} +1 -1
- package/dist/{retired-settings-keys-B52KsNz8.js → retired-settings-keys-OfhqQio4.js} +1 -1
- package/dist/tls/cert-evaluation.d.ts +41 -0
- package/dist/tls/cert-identity.d.ts +37 -0
- package/dist/tls/cert-manager.d.ts +60 -6
- package/dist/tls/cert-openssl.d.ts +23 -0
- package/dist/tls/index.d.ts +3 -1
- package/package.json +1 -1
- package/dist/{manifest-python-deps-MA_BZGBz.js → manifest-python-deps-CwBbX4Ut.js} +1 -1
- package/dist/{manifest-python-deps-Cb1ANt3i.mjs → manifest-python-deps-SGdbr9D5.mjs} +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("./chunk-Cek0wNdY.js");
|
|
3
|
-
const require_dist = require("./dist-
|
|
3
|
+
const require_dist = require("./dist-iAwSA2_f.js");
|
|
4
4
|
const require_builtins_alerts_alerts_addon = require("./builtins/alerts/alerts.addon.js");
|
|
5
5
|
require("./builtins/alerts/index.js");
|
|
6
6
|
const require_formatter = require("./formatter-DqAKDlvN.js");
|
|
@@ -25,7 +25,7 @@ const require_builtins_system_config_system_config_addon = require("./builtins/s
|
|
|
25
25
|
require("./builtins/system-config/index.js");
|
|
26
26
|
const require_builtins_winston_logging_index = require("./builtins/winston-logging/index.js");
|
|
27
27
|
const require_file_data_plane = require("./file-data-plane-DUHPHa-Y.js");
|
|
28
|
-
const require_manifest_python_deps = require("./manifest-python-deps-
|
|
28
|
+
const require_manifest_python_deps = require("./manifest-python-deps-CwBbX4Ut.js");
|
|
29
29
|
const require_resource_monitor = require("./resource-monitor-CdnzxBLP.js");
|
|
30
30
|
const require_custom_action_registry = require("./custom-action-registry-jY0NOZK8.js");
|
|
31
31
|
let zod = require("zod");
|
|
@@ -46,6 +46,7 @@ let node_http = require("node:http");
|
|
|
46
46
|
let node_vm = require("node:vm");
|
|
47
47
|
node_vm = require_chunk.__toESM(node_vm);
|
|
48
48
|
let _camstack_types_addon = require("@camstack/types/addon");
|
|
49
|
+
let node_net = require("node:net");
|
|
49
50
|
let node_url = require("node:url");
|
|
50
51
|
let node_events = require("node:events");
|
|
51
52
|
let node_stream = require("node:stream");
|
|
@@ -2017,71 +2018,454 @@ var StorageManager = class {
|
|
|
2017
2018
|
}
|
|
2018
2019
|
};
|
|
2019
2020
|
//#endregion
|
|
2020
|
-
//#region src/tls/cert-
|
|
2021
|
-
var execFileAsync$3 = (0, node_util.promisify)(node_child_process.execFile);
|
|
2021
|
+
//#region src/tls/cert-evaluation.ts
|
|
2022
2022
|
/**
|
|
2023
|
-
*
|
|
2024
|
-
*
|
|
2023
|
+
* The regeneration rule (D227), as a pure function.
|
|
2024
|
+
*
|
|
2025
|
+
* `ensureTlsCert` reissues **only** when the material on disk cannot do
|
|
2026
|
+
* its job. Never because it is old, never because the machine picked up
|
|
2027
|
+
* an address the certificate does not need, never because a new build
|
|
2028
|
+
* shipped. The decision is a function of (files on disk, machine
|
|
2029
|
+
* identity, clock) alone, so the same inputs always produce the same
|
|
2030
|
+
* answer — which is what makes a reissue happen once and then stop.
|
|
2025
2031
|
*/
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2032
|
+
/** OID `id-kp-serverAuth`. Apple's trustd requires it on the leaf. */
|
|
2033
|
+
var SERVER_AUTH_OID = "1.3.6.1.5.5.7.3.1";
|
|
2034
|
+
/**
|
|
2035
|
+
* Apple's `SecPolicyCheckOtherTrustValidityPeriod` ceiling is 825 days;
|
|
2036
|
+
* the CA/Browser Forum's recommended maximum is 397. We sit at 397.
|
|
2037
|
+
*/
|
|
2038
|
+
var MAX_LEAF_VALIDITY_DAYS = 397;
|
|
2039
|
+
/** Reissue this long before the leaf dies, so nobody serves an expired one. */
|
|
2040
|
+
var LEAF_RENEWAL_WINDOW_DAYS = 30;
|
|
2041
|
+
/** A local root outlives many leaves — it is the anchor an operator trusts. */
|
|
2042
|
+
var CA_VALIDITY_DAYS = 3650;
|
|
2043
|
+
var MS_PER_DAY = 864e5;
|
|
2044
|
+
/** Reasons that invalidate the root as well as the leaf. */
|
|
2045
|
+
var REASONS_REQUIRING_NEW_CA = [
|
|
2046
|
+
"missing",
|
|
2047
|
+
"unreadable",
|
|
2048
|
+
"no-local-ca",
|
|
2049
|
+
"ca-expiring"
|
|
2050
|
+
];
|
|
2051
|
+
function reasonRequiresNewCa(reason) {
|
|
2052
|
+
return REASONS_REQUIRING_NEW_CA.includes(reason);
|
|
2053
|
+
}
|
|
2054
|
+
function parse$1(pem) {
|
|
2055
|
+
try {
|
|
2056
|
+
return new node_crypto.X509Certificate(pem);
|
|
2057
|
+
} catch {
|
|
2058
|
+
return null;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
function daysBetween(from, to) {
|
|
2062
|
+
return (to.getTime() - from.getTime()) / MS_PER_DAY;
|
|
2063
|
+
}
|
|
2064
|
+
function hasServerAuthEku(leaf) {
|
|
2065
|
+
const eku = leaf.keyUsage;
|
|
2066
|
+
return eku !== void 0 && eku.length === 1 && eku[0] === "1.3.6.1.5.5.7.3.1";
|
|
2067
|
+
}
|
|
2068
|
+
function keyMatches(leaf, keyPem) {
|
|
2069
|
+
try {
|
|
2070
|
+
return leaf.checkPrivateKey((0, node_crypto.createPrivateKey)(keyPem));
|
|
2071
|
+
} catch {
|
|
2072
|
+
return false;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function coversIdentity(leaf, identity) {
|
|
2076
|
+
for (const name of identity.requiredDnsNames) if (leaf.checkHost(name) === void 0) return false;
|
|
2077
|
+
for (const ip of identity.requiredIpAddresses) if (leaf.checkIP(ip) === void 0) return false;
|
|
2078
|
+
return true;
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* `null` when the material on disk is fit to keep serving.
|
|
2082
|
+
*
|
|
2083
|
+
* Order matters only for the quality of the reported reason; any
|
|
2084
|
+
* non-null answer produces the same action.
|
|
2085
|
+
*/
|
|
2086
|
+
function evaluateExistingCert(input) {
|
|
2087
|
+
const leaf = parse$1(input.chainPem);
|
|
2088
|
+
const ca = parse$1(input.caPem);
|
|
2089
|
+
if (leaf === null || ca === null) return "unreadable";
|
|
2090
|
+
if (daysBetween(input.now, new Date(ca.validTo)) < 427) return "ca-expiring";
|
|
2091
|
+
if (!keyMatches(leaf, input.keyPem)) return "key-mismatch";
|
|
2092
|
+
if (daysBetween(input.now, new Date(leaf.validTo)) < 30) return "expiring";
|
|
2093
|
+
if (!hasServerAuthEku(leaf)) return "missing-server-auth-eku";
|
|
2094
|
+
if (leaf.ca || !leaf.checkIssued(ca) || !leaf.verify(ca.publicKey)) return "not-issued-by-local-ca";
|
|
2095
|
+
if (daysBetween(new Date(leaf.validFrom), new Date(leaf.validTo)) > 398) return "validity-too-long";
|
|
2096
|
+
if (!coversIdentity(leaf, input.identity)) return "san-coverage-gap";
|
|
2097
|
+
return null;
|
|
2098
|
+
}
|
|
2099
|
+
//#endregion
|
|
2100
|
+
//#region src/tls/cert-identity.ts
|
|
2101
|
+
/**
|
|
2102
|
+
* What names and addresses the hub's certificate has to answer for.
|
|
2103
|
+
*
|
|
2104
|
+
* Split out of `cert-manager.ts` because it is pure and because the
|
|
2105
|
+
* regeneration rule (D227) is decided entirely by the difference between
|
|
2106
|
+
* *this* and what the certificate on disk already carries.
|
|
2107
|
+
*/
|
|
2108
|
+
/**
|
|
2109
|
+
* Interfaces whose addresses are certified but never gate a reissue:
|
|
2110
|
+
* container bridges, VPN tunnels and mesh overlays hand out addresses
|
|
2111
|
+
* that change without the hub moving.
|
|
2112
|
+
*/
|
|
2113
|
+
var VOLATILE_INTERFACE_PREFIXES = [
|
|
2114
|
+
"docker",
|
|
2115
|
+
"br-",
|
|
2116
|
+
"veth",
|
|
2117
|
+
"virbr",
|
|
2118
|
+
"cni",
|
|
2119
|
+
"flannel",
|
|
2120
|
+
"tun",
|
|
2121
|
+
"utun",
|
|
2122
|
+
"tap",
|
|
2123
|
+
"wg",
|
|
2124
|
+
"zt",
|
|
2125
|
+
"tailscale",
|
|
2126
|
+
"ppp",
|
|
2127
|
+
"awdl",
|
|
2128
|
+
"llw"
|
|
2129
|
+
];
|
|
2130
|
+
/** A DNS name we are willing to hand to openssl. */
|
|
2131
|
+
var DNS_NAME_PATTERN = /^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
2132
|
+
function isIpv4(value) {
|
|
2133
|
+
return (0, node_net.isIP)(value) === 4;
|
|
2134
|
+
}
|
|
2135
|
+
function isIpv6(value) {
|
|
2136
|
+
return (0, node_net.isIP)(value) === 6;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* `fe80::/10` and `169.254.0.0/16`. An IPv6 link-local address needs a
|
|
2140
|
+
* zone index to be usable and a SAN cannot carry one, so such an entry
|
|
2141
|
+
* can never match anything — it is noise that makes the certificate look
|
|
2142
|
+
* broader than it is.
|
|
2143
|
+
*/
|
|
2144
|
+
function isLinkLocal(value) {
|
|
2145
|
+
if (isIpv4(value)) return value.startsWith("169.254.");
|
|
2146
|
+
if (!isIpv6(value)) return false;
|
|
2147
|
+
const firstGroup = value.split(":")[0] ?? "";
|
|
2148
|
+
if (firstGroup === "") return false;
|
|
2149
|
+
const parsed = Number.parseInt(firstGroup, 16);
|
|
2150
|
+
return Number.isFinite(parsed) && (parsed & 65472) === 65152;
|
|
2151
|
+
}
|
|
2152
|
+
/** `fc00::/7` — the IPv6 range that behaves like RFC 1918 does for v4. */
|
|
2153
|
+
function isUniqueLocalIpv6(value) {
|
|
2154
|
+
if (!isIpv6(value)) return false;
|
|
2155
|
+
const firstGroup = value.split(":")[0] ?? "";
|
|
2156
|
+
const parsed = Number.parseInt(firstGroup, 16);
|
|
2157
|
+
return Number.isFinite(parsed) && (parsed & 65024) === 64512;
|
|
2158
|
+
}
|
|
2159
|
+
function isVolatileInterface(name) {
|
|
2160
|
+
const lower = name.toLowerCase();
|
|
2161
|
+
return VOLATILE_INTERFACE_PREFIXES.some((prefix) => lower.startsWith(prefix));
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* A global-scope IPv6 address is NOT a stable identity: SLAAC privacy
|
|
2165
|
+
* extensions rotate temporary addresses roughly daily, and `os` gives us
|
|
2166
|
+
* no way to tell a temporary address from a permanent one. Gating on
|
|
2167
|
+
* one would reissue the certificate every day.
|
|
2168
|
+
*/
|
|
2169
|
+
function isStableGateAddress(address) {
|
|
2170
|
+
if (isLinkLocal(address)) return false;
|
|
2171
|
+
if (isIpv4(address)) return true;
|
|
2172
|
+
return isUniqueLocalIpv6(address);
|
|
2173
|
+
}
|
|
2174
|
+
function addSan(dns, ips, value) {
|
|
2175
|
+
const trimmed = value.trim();
|
|
2176
|
+
if (trimmed === "") return;
|
|
2177
|
+
if ((0, node_net.isIP)(trimmed) !== 0) {
|
|
2178
|
+
if (!isLinkLocal(trimmed)) ips.add(trimmed);
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
if (DNS_NAME_PATTERN.test(trimmed)) dns.add(trimmed);
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Snapshot the machine's identity. Called once per `ensureTlsCert`; the
|
|
2185
|
+
* result is both the SAN list for a new leaf and the yardstick the
|
|
2186
|
+
* existing leaf is measured against.
|
|
2187
|
+
*/
|
|
2188
|
+
function collectCertIdentity(options) {
|
|
2189
|
+
const dnsNames = /* @__PURE__ */ new Set();
|
|
2190
|
+
const ipAddresses = new Set(["127.0.0.1", "::1"]);
|
|
2191
|
+
const requiredDnsNames = /* @__PURE__ */ new Set();
|
|
2192
|
+
const requiredIpAddresses = new Set(["127.0.0.1"]);
|
|
2193
|
+
for (const name of [
|
|
2042
2194
|
"localhost",
|
|
2043
|
-
|
|
2195
|
+
options.commonName,
|
|
2044
2196
|
node_os.hostname()
|
|
2045
|
-
])
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
for (const
|
|
2057
|
-
|
|
2197
|
+
]) {
|
|
2198
|
+
addSan(dnsNames, ipAddresses, name);
|
|
2199
|
+
addSan(requiredDnsNames, requiredIpAddresses, name);
|
|
2200
|
+
}
|
|
2201
|
+
for (const [ifaceName, addrs] of Object.entries(node_os.networkInterfaces())) for (const addr of addrs ?? []) {
|
|
2202
|
+
if (addr.internal) continue;
|
|
2203
|
+
if (isLinkLocal(addr.address)) continue;
|
|
2204
|
+
ipAddresses.add(addr.address);
|
|
2205
|
+
if (isVolatileInterface(ifaceName)) continue;
|
|
2206
|
+
if (isStableGateAddress(addr.address)) requiredIpAddresses.add(addr.address);
|
|
2207
|
+
}
|
|
2208
|
+
for (const san of options.extraSans) {
|
|
2209
|
+
addSan(dnsNames, ipAddresses, san);
|
|
2210
|
+
addSan(requiredDnsNames, requiredIpAddresses, san);
|
|
2211
|
+
}
|
|
2212
|
+
return {
|
|
2213
|
+
dnsNames: [...dnsNames],
|
|
2214
|
+
ipAddresses: [...ipAddresses],
|
|
2215
|
+
requiredDnsNames: [...requiredDnsNames],
|
|
2216
|
+
requiredIpAddresses: [...requiredIpAddresses]
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
//#endregion
|
|
2220
|
+
//#region src/tls/cert-openssl.ts
|
|
2221
|
+
/**
|
|
2222
|
+
* The openssl invocations. Isolated so `cert-manager.ts` reads as policy
|
|
2223
|
+
* and this file reads as mechanics.
|
|
2224
|
+
*/
|
|
2225
|
+
var execFileAsync$3 = (0, node_util.promisify)(node_child_process.execFile);
|
|
2226
|
+
/** Subject of the local root. Distinct from the leaf's CN by construction. */
|
|
2227
|
+
var CA_COMMON_NAME = "CamStack Local CA";
|
|
2228
|
+
function sanValue(identity) {
|
|
2229
|
+
const parts = [];
|
|
2230
|
+
for (const dns of identity.dnsNames) parts.push(`DNS:${dns}`);
|
|
2231
|
+
for (const ip of identity.ipAddresses) if ((0, node_net.isIP)(ip) !== 0) parts.push(`IP:${ip}`);
|
|
2232
|
+
return parts.join(",");
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
* A local root: 10 years, `pathlen:0` so it can sign leaves and nothing
|
|
2236
|
+
* else, and **no EKU** — Apple rejects an anchor asserting
|
|
2237
|
+
* `anyExtendedKeyUsage`, and a root with no EKU constrains nothing.
|
|
2238
|
+
*/
|
|
2239
|
+
async function generateCa(tmpDir) {
|
|
2240
|
+
const caCertPath = (0, node_path.join)(tmpDir, "ca.crt");
|
|
2241
|
+
const caKeyPath = (0, node_path.join)(tmpDir, "ca.key");
|
|
2058
2242
|
await execFileAsync$3("openssl", [
|
|
2059
2243
|
"req",
|
|
2060
2244
|
"-x509",
|
|
2061
2245
|
"-newkey",
|
|
2062
2246
|
"rsa:2048",
|
|
2247
|
+
"-nodes",
|
|
2248
|
+
"-sha256",
|
|
2249
|
+
"-days",
|
|
2250
|
+
String(CA_VALIDITY_DAYS),
|
|
2251
|
+
"-keyout",
|
|
2252
|
+
caKeyPath,
|
|
2253
|
+
"-out",
|
|
2254
|
+
caCertPath,
|
|
2255
|
+
"-subj",
|
|
2256
|
+
`/CN=${CA_COMMON_NAME}`,
|
|
2257
|
+
"-addext",
|
|
2258
|
+
"basicConstraints=critical,CA:TRUE,pathlen:0",
|
|
2259
|
+
"-addext",
|
|
2260
|
+
"keyUsage=critical,keyCertSign,cRLSign",
|
|
2261
|
+
"-addext",
|
|
2262
|
+
"subjectKeyIdentifier=hash"
|
|
2263
|
+
]);
|
|
2264
|
+
await (0, node_fs_promises.chmod)(caKeyPath, 384);
|
|
2265
|
+
return {
|
|
2266
|
+
caCertPath,
|
|
2267
|
+
caKeyPath
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* A server leaf signed by the local root: `CA:FALSE`, and
|
|
2272
|
+
* `extendedKeyUsage=serverAuth` — not `anyExtendedKeyUsage`, which
|
|
2273
|
+
* Apple's `testAppTrustRoot_AnyEKU_AfterJul2019` asserts must fail.
|
|
2274
|
+
*/
|
|
2275
|
+
async function issueLeaf(tmpDir, ca, identity, commonName, validDays) {
|
|
2276
|
+
const keyPath = (0, node_path.join)(tmpDir, "leaf.key");
|
|
2277
|
+
const csrPath = (0, node_path.join)(tmpDir, "leaf.csr");
|
|
2278
|
+
const certPath = (0, node_path.join)(tmpDir, "leaf.crt");
|
|
2279
|
+
const extPath = (0, node_path.join)(tmpDir, "leaf.ext");
|
|
2280
|
+
await (0, node_fs_promises.writeFile)(extPath, [
|
|
2281
|
+
"basicConstraints=critical,CA:FALSE",
|
|
2282
|
+
"keyUsage=critical,digitalSignature,keyEncipherment",
|
|
2283
|
+
"extendedKeyUsage=serverAuth",
|
|
2284
|
+
"subjectKeyIdentifier=hash",
|
|
2285
|
+
"authorityKeyIdentifier=keyid,issuer",
|
|
2286
|
+
`subjectAltName=${sanValue(identity)}`,
|
|
2287
|
+
""
|
|
2288
|
+
].join("\n"), "utf-8");
|
|
2289
|
+
await execFileAsync$3("openssl", [
|
|
2290
|
+
"req",
|
|
2291
|
+
"-new",
|
|
2292
|
+
"-newkey",
|
|
2293
|
+
"rsa:2048",
|
|
2294
|
+
"-nodes",
|
|
2295
|
+
"-sha256",
|
|
2063
2296
|
"-keyout",
|
|
2064
2297
|
keyPath,
|
|
2065
2298
|
"-out",
|
|
2066
|
-
|
|
2299
|
+
csrPath,
|
|
2300
|
+
"-subj",
|
|
2301
|
+
`/CN=${commonName}`
|
|
2302
|
+
]);
|
|
2303
|
+
await execFileAsync$3("openssl", [
|
|
2304
|
+
"x509",
|
|
2305
|
+
"-req",
|
|
2306
|
+
"-in",
|
|
2307
|
+
csrPath,
|
|
2308
|
+
"-CA",
|
|
2309
|
+
ca.caCertPath,
|
|
2310
|
+
"-CAkey",
|
|
2311
|
+
ca.caKeyPath,
|
|
2312
|
+
"-set_serial",
|
|
2313
|
+
`0x00${(0, node_crypto.randomBytes)(16).toString("hex")}`,
|
|
2067
2314
|
"-days",
|
|
2068
2315
|
String(validDays),
|
|
2069
|
-
"-
|
|
2070
|
-
"-
|
|
2071
|
-
|
|
2072
|
-
"-
|
|
2073
|
-
|
|
2316
|
+
"-sha256",
|
|
2317
|
+
"-extfile",
|
|
2318
|
+
extPath,
|
|
2319
|
+
"-out",
|
|
2320
|
+
certPath
|
|
2074
2321
|
]);
|
|
2075
|
-
|
|
2076
|
-
await
|
|
2322
|
+
await (0, node_fs_promises.chmod)(keyPath, 384);
|
|
2323
|
+
await (0, node_fs_promises.rm)(csrPath, { force: true });
|
|
2324
|
+
await (0, node_fs_promises.rm)(extPath, { force: true });
|
|
2077
2325
|
return {
|
|
2078
2326
|
certPath,
|
|
2079
|
-
keyPath
|
|
2080
|
-
|
|
2327
|
+
keyPath
|
|
2328
|
+
};
|
|
2329
|
+
}
|
|
2330
|
+
//#endregion
|
|
2331
|
+
//#region src/tls/cert-manager.ts
|
|
2332
|
+
var DEFAULT_COMMON_NAME = "camstack.local";
|
|
2333
|
+
/**
|
|
2334
|
+
* Ensure the hub has a usable TLS identity under `<dataDir>/tls`, made of
|
|
2335
|
+
* a long-lived local **root** (`camstack-ca.crt`) and a short **leaf**
|
|
2336
|
+
* chained to it (`camstack.crt` = leaf + root, `camstack.key`).
|
|
2337
|
+
*
|
|
2338
|
+
* ## The regeneration rule (D227)
|
|
2339
|
+
*
|
|
2340
|
+
* Reissue happens when, and only when, the material on disk **cannot do
|
|
2341
|
+
* its job**:
|
|
2342
|
+
*
|
|
2343
|
+
* - it is absent, unreadable, or the key does not match the certificate;
|
|
2344
|
+
* - the root is absent (every pre-2026-08 install: one self-signed
|
|
2345
|
+
* `CA:TRUE` leaf and no root) or is inside its renewal window;
|
|
2346
|
+
* - the leaf is inside its 30-day renewal window;
|
|
2347
|
+
* - the leaf lacks `extendedKeyUsage = serverAuth` — Apple's trustd
|
|
2348
|
+
* rejects an app-supplied anchor without it;
|
|
2349
|
+
* - the leaf is not actually issued by the root on disk;
|
|
2350
|
+
* - the leaf's validity span exceeds {@link MAX_LEAF_VALIDITY_DAYS};
|
|
2351
|
+
* - **a name or address the hub must answer for is missing from the SAN
|
|
2352
|
+
* list** — a DHCP move, a new interface or a new hostname.
|
|
2353
|
+
*
|
|
2354
|
+
* And explicitly NOT when: the certificate names an address the machine
|
|
2355
|
+
* no longer has (a superset still works — the check is one-directional),
|
|
2356
|
+
* a volatile interface (docker/VPN/mesh) or a global-scope IPv6 address
|
|
2357
|
+
* changed (SLAAC privacy addresses rotate daily), or a new build shipped.
|
|
2358
|
+
*
|
|
2359
|
+
* Every trigger is derived from the files plus the machine, so once a
|
|
2360
|
+
* reissue clears them it clears them for good: the next boot returns
|
|
2361
|
+
* `generated: false`. A certificate that moved on every boot would
|
|
2362
|
+
* invalidate every trust an operator granted by hand — worse than the
|
|
2363
|
+
* bugs this rule fixes.
|
|
2364
|
+
*
|
|
2365
|
+
* **The root is rotated only for root-level reasons.** SAN drift rotates
|
|
2366
|
+
* the leaf alone, so trust granted to `camstack-ca.crt` survives every
|
|
2367
|
+
* address change the hub will ever see.
|
|
2368
|
+
*/
|
|
2369
|
+
async function ensureTlsCert(dataDir, options) {
|
|
2370
|
+
const tlsDir = (0, node_path.join)(dataDir, "tls");
|
|
2371
|
+
const paths = {
|
|
2372
|
+
certPath: (0, node_path.join)(tlsDir, "camstack.crt"),
|
|
2373
|
+
keyPath: (0, node_path.join)(tlsDir, "camstack.key"),
|
|
2374
|
+
caCertPath: (0, node_path.join)(tlsDir, "camstack-ca.crt"),
|
|
2375
|
+
caKeyPath: (0, node_path.join)(tlsDir, "camstack-ca.key")
|
|
2376
|
+
};
|
|
2377
|
+
const commonName = options?.commonName ?? DEFAULT_COMMON_NAME;
|
|
2378
|
+
const validDays = Math.min(options?.validDays ?? 397, 397);
|
|
2379
|
+
const identity = collectCertIdentity({
|
|
2380
|
+
commonName,
|
|
2381
|
+
extraSans: options?.extraSans ?? []
|
|
2382
|
+
});
|
|
2383
|
+
const reason = decideRegeneration(paths, identity);
|
|
2384
|
+
if (reason === null) return describe(paths, false, null, false, null);
|
|
2385
|
+
const previousFingerprint = readFingerprint(paths.certPath);
|
|
2386
|
+
const caRotated = reasonRequiresNewCa(reason);
|
|
2387
|
+
(0, node_fs.mkdirSync)(tlsDir, { recursive: true });
|
|
2388
|
+
await regenerate(paths, identity, commonName, validDays, caRotated);
|
|
2389
|
+
return describe(paths, true, reason, caRotated, previousFingerprint);
|
|
2390
|
+
}
|
|
2391
|
+
/** Fingerprint of whatever is on disk, or `null` if there is nothing readable. */
|
|
2392
|
+
function readFingerprint(certPath) {
|
|
2393
|
+
try {
|
|
2394
|
+
return new node_crypto.X509Certificate((0, node_fs.readFileSync)(certPath)).fingerprint256;
|
|
2395
|
+
} catch {
|
|
2396
|
+
return null;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
function decideRegeneration(paths, identity) {
|
|
2400
|
+
if (!(0, node_fs.existsSync)(paths.certPath) || !(0, node_fs.existsSync)(paths.keyPath)) return "missing";
|
|
2401
|
+
if (!(0, node_fs.existsSync)(paths.caCertPath) || !(0, node_fs.existsSync)(paths.caKeyPath)) return "no-local-ca";
|
|
2402
|
+
try {
|
|
2403
|
+
return evaluateExistingCert({
|
|
2404
|
+
chainPem: (0, node_fs.readFileSync)(paths.certPath, "utf-8"),
|
|
2405
|
+
keyPem: (0, node_fs.readFileSync)(paths.keyPath, "utf-8"),
|
|
2406
|
+
caPem: (0, node_fs.readFileSync)(paths.caCertPath, "utf-8"),
|
|
2407
|
+
identity,
|
|
2408
|
+
now: /* @__PURE__ */ new Date()
|
|
2409
|
+
});
|
|
2410
|
+
} catch {
|
|
2411
|
+
return "unreadable";
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Build every file in a scratch directory, then move them into place.
|
|
2416
|
+
* A crash mid-way leaves the previous material untouched; a crash
|
|
2417
|
+
* between the moves leaves a key/certificate mismatch, which the
|
|
2418
|
+
* evaluator reports as `key-mismatch` and heals on the next boot.
|
|
2419
|
+
*/
|
|
2420
|
+
async function regenerate(paths, identity, commonName, validDays, newCa) {
|
|
2421
|
+
const scratch = await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "camstack-tls-"));
|
|
2422
|
+
try {
|
|
2423
|
+
const ca = newCa ? await generateCa(scratch) : {
|
|
2424
|
+
caCertPath: paths.caCertPath,
|
|
2425
|
+
caKeyPath: paths.caKeyPath
|
|
2426
|
+
};
|
|
2427
|
+
const leaf = await issueLeaf(scratch, ca, identity, commonName, validDays);
|
|
2428
|
+
const chainPath = (0, node_path.join)(scratch, "chain.crt");
|
|
2429
|
+
await (0, node_fs_promises.writeFile)(chainPath, `${(0, node_fs.readFileSync)(leaf.certPath, "utf-8").trimEnd()}\n${(0, node_fs.readFileSync)(ca.caCertPath, "utf-8").trimEnd()}\n`, "utf-8");
|
|
2430
|
+
if (newCa) {
|
|
2431
|
+
await (0, node_fs_promises.copyFile)(ca.caCertPath, `${paths.caCertPath}.new`);
|
|
2432
|
+
await (0, node_fs_promises.copyFile)(ca.caKeyPath, `${paths.caKeyPath}.new`);
|
|
2433
|
+
(0, node_fs.renameSync)(`${paths.caCertPath}.new`, paths.caCertPath);
|
|
2434
|
+
(0, node_fs.renameSync)(`${paths.caKeyPath}.new`, paths.caKeyPath);
|
|
2435
|
+
await (0, node_fs_promises.chmod)(paths.caKeyPath, 384);
|
|
2436
|
+
}
|
|
2437
|
+
await (0, node_fs_promises.copyFile)(leaf.keyPath, `${paths.keyPath}.new`);
|
|
2438
|
+
await (0, node_fs_promises.copyFile)(chainPath, `${paths.certPath}.new`);
|
|
2439
|
+
(0, node_fs.renameSync)(`${paths.keyPath}.new`, paths.keyPath);
|
|
2440
|
+
(0, node_fs.renameSync)(`${paths.certPath}.new`, paths.certPath);
|
|
2441
|
+
await (0, node_fs_promises.chmod)(paths.keyPath, 384);
|
|
2442
|
+
} finally {
|
|
2443
|
+
await (0, node_fs_promises.rm)(scratch, {
|
|
2444
|
+
recursive: true,
|
|
2445
|
+
force: true
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
function describe(paths, generated, reason, caRotated, previousFingerprintSha256) {
|
|
2450
|
+
const leaf = new node_crypto.X509Certificate((0, node_fs.readFileSync)(paths.certPath));
|
|
2451
|
+
const ca = new node_crypto.X509Certificate((0, node_fs.readFileSync)(paths.caCertPath));
|
|
2452
|
+
const san = leaf.subjectAltName ?? "";
|
|
2453
|
+
return {
|
|
2454
|
+
...paths,
|
|
2455
|
+
generated,
|
|
2456
|
+
reason,
|
|
2457
|
+
caRotated,
|
|
2458
|
+
fingerprintSha256: leaf.fingerprint256,
|
|
2459
|
+
previousFingerprintSha256,
|
|
2460
|
+
caFingerprintSha256: ca.fingerprint256,
|
|
2461
|
+
validTo: new Date(leaf.validTo).toISOString(),
|
|
2462
|
+
sans: san === "" ? [] : san.split(", ")
|
|
2081
2463
|
};
|
|
2082
2464
|
}
|
|
2083
2465
|
/**
|
|
2084
|
-
* Load TLS cert+key from files. Returns Buffers suitable for Node.js TLS
|
|
2466
|
+
* Load TLS cert+key from files. Returns Buffers suitable for Node.js TLS
|
|
2467
|
+
* options. `certPath` is a full chain, so the listener presents the local
|
|
2468
|
+
* root alongside the leaf.
|
|
2085
2469
|
*/
|
|
2086
2470
|
function loadTlsCert(certPath, keyPath) {
|
|
2087
2471
|
return {
|
|
@@ -94910,6 +95294,8 @@ exports.AddonRouteRegistry = AddonRouteRegistry;
|
|
|
94910
95294
|
exports.AlertCenterAddon = require_builtins_alerts_alerts_addon.AlertCenterAddon;
|
|
94911
95295
|
exports.ApiKeyManager = require_builtins_local_auth_local_auth_addon.ApiKeyManager;
|
|
94912
95296
|
exports.AuthManager = require_builtins_local_auth_local_auth_addon.AuthManager;
|
|
95297
|
+
exports.CA_COMMON_NAME = CA_COMMON_NAME;
|
|
95298
|
+
exports.CA_VALIDITY_DAYS = CA_VALIDITY_DAYS;
|
|
94913
95299
|
exports.CLUSTER_SECRET_MISMATCH_TYPE = CLUSTER_SECRET_MISMATCH_TYPE;
|
|
94914
95300
|
exports.CLUSTER_SECRET_REJECTED_EXIT_CODE = CLUSTER_SECRET_REJECTED_EXIT_CODE;
|
|
94915
95301
|
exports.CORE_CAP_SERVICE_NAME = CORE_CAP_SERVICE_NAME;
|
|
@@ -94956,6 +95342,7 @@ exports.HubNodeRegistry = HubNodeRegistry;
|
|
|
94956
95342
|
exports.INFRA_CAPABILITIES = INFRA_CAPABILITIES;
|
|
94957
95343
|
exports.IntegrationRegistry = IntegrationRegistry;
|
|
94958
95344
|
exports.JobJournal = JobJournal;
|
|
95345
|
+
exports.LEAF_RENEWAL_WINDOW_DAYS = LEAF_RENEWAL_WINDOW_DAYS;
|
|
94959
95346
|
exports.LifecycleJobEngine = LifecycleJobEngine;
|
|
94960
95347
|
exports.LifecycleStateMachine = LifecycleStateMachine;
|
|
94961
95348
|
exports.LivenessMonitorAddon = require_builtins_liveness_monitor_liveness_monitor_addon.LivenessMonitorAddon;
|
|
@@ -94966,6 +95353,7 @@ exports.LogManager = LogManager;
|
|
|
94966
95353
|
exports.LogRingBuffer = LogRingBuffer;
|
|
94967
95354
|
exports.LokiDestination = require_builtins_loki_logging_index.LokiDestination$1;
|
|
94968
95355
|
exports.LokiLoggingAddon = require_builtins_loki_logging_index.LokiLoggingAddon$1;
|
|
95356
|
+
exports.MAX_LEAF_VALIDITY_DAYS = MAX_LEAF_VALIDITY_DAYS;
|
|
94969
95357
|
exports.METHOD_ACCESS_MAP = require_dist.METHOD_ACCESS_MAP;
|
|
94970
95358
|
exports.ModelDownloadService = require_file_data_plane.ModelDownloadService;
|
|
94971
95359
|
exports.NATIVE_PROVIDER_SERVICE_INFIX = require_manifest_python_deps.NATIVE_PROVIDER_SERVICE_INFIX;
|
|
@@ -94991,6 +95379,7 @@ exports.ReadinessRegistry = require_dist.ReadinessRegistry;
|
|
|
94991
95379
|
exports.ReadinessTimeoutError = require_dist.ReadinessTimeoutError;
|
|
94992
95380
|
exports.ReplEngine = ReplEngine;
|
|
94993
95381
|
exports.RingBuffer = RingBuffer;
|
|
95382
|
+
exports.SERVER_AUTH_OID = SERVER_AUTH_OID;
|
|
94994
95383
|
exports.ScopedLogger = ScopedLogger;
|
|
94995
95384
|
exports.ScopedTokenManager = require_builtins_local_auth_local_auth_addon.ScopedTokenManager;
|
|
94996
95385
|
exports.SocketChannel = require_manifest_python_deps.SocketChannel;
|
|
@@ -95042,6 +95431,7 @@ exports.classifyCapRoute = require_manifest_python_deps.classifyCapRoute;
|
|
|
95042
95431
|
exports.clearPendingRestart = clearPendingRestart;
|
|
95043
95432
|
exports.clusterEventTopic = require_manifest_python_deps.clusterEventTopic;
|
|
95044
95433
|
exports.clusterSecretMatches = clusterSecretMatches;
|
|
95434
|
+
exports.collectCertIdentity = collectCertIdentity;
|
|
95045
95435
|
exports.collectModelFiles = require_file_data_plane.collectModelFiles;
|
|
95046
95436
|
exports.contentTypeFor = require_file_data_plane.contentTypeFor;
|
|
95047
95437
|
exports.copyDirRecursive = copyDirRecursive;
|
|
@@ -95108,6 +95498,7 @@ Object.defineProperty(exports, "ensurePython", {
|
|
|
95108
95498
|
}
|
|
95109
95499
|
});
|
|
95110
95500
|
exports.ensureTlsCert = ensureTlsCert;
|
|
95501
|
+
exports.evaluateExistingCert = evaluateExistingCert;
|
|
95111
95502
|
exports.expandCapMethods = require_dist.expandCapMethods;
|
|
95112
95503
|
exports.fetchJson = require_file_data_plane.fetchJson;
|
|
95113
95504
|
Object.defineProperty(exports, "findInPath", {
|