@camstack/server 1.2.143 → 1.2.144

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.
@@ -41,11 +41,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.loadBootstrapConfig = loadBootstrapConfig;
42
42
  exports.autoGenerateJwtSecret = autoGenerateJwtSecret;
43
43
  exports.setupInfra = setupInfra;
44
+ const node_crypto_1 = require("node:crypto");
44
45
  const fs = __importStar(require("node:fs"));
45
46
  const path = __importStar(require("node:path"));
46
- const yaml = __importStar(require("js-yaml"));
47
- const node_crypto_1 = require("node:crypto");
48
47
  const types_1 = require("@camstack/types");
48
+ const yaml = __importStar(require("js-yaml"));
49
49
  const config_schema_1 = require("../core/config/config.schema");
50
50
  const storage_location_manager_1 = require("../core/storage/storage-location-manager");
51
51
  // ---------------------------------------------------------------------------
@@ -207,6 +207,7 @@ async function setupInfra(configPath, bootstrapConfig) {
207
207
  }
208
208
  // --- Phase 2c: TLS certificate setup ---
209
209
  let tlsOptions;
210
+ let tlsCert;
210
211
  if (config.tls.enabled) {
211
212
  // Use require() instead of import() — the ESM build of @camstack/system has
212
213
  // broken chunks with require("fs") when leaked .js files exist in core/src/.
@@ -220,14 +221,10 @@ async function setupInfra(configPath, bootstrapConfig) {
220
221
  tlsOptions = { key: pair.key, cert: pair.cert };
221
222
  }
222
223
  else {
223
- // Auto-generate self-signed
224
+ // Hub-generated local CA → leaf (D227)
224
225
  const tlsResult = await ensureTlsCert(dataPath);
225
- if (tlsResult.generated) {
226
- console.log(`[Phase2c] Generated self-signed TLS cert at ${tlsResult.certPath}`);
227
- }
228
- else {
229
- console.log(`[Phase2c] Using existing TLS cert at ${tlsResult.certPath}`);
230
- }
226
+ tlsCert = tlsResult;
227
+ logTlsCert(tlsResult);
231
228
  const pair = loadTlsCert(tlsResult.certPath, tlsResult.keyPath);
232
229
  tlsOptions = { key: pair.key, cert: pair.cert };
233
230
  }
@@ -237,5 +234,25 @@ async function setupInfra(configPath, bootstrapConfig) {
237
234
  dataPath,
238
235
  locationManager,
239
236
  tlsOptions,
237
+ tlsCert,
240
238
  };
241
239
  }
240
+ /**
241
+ * A certificate change is never silent. Anyone who installed the previous
242
+ * certificate as trusted by hand has to act, and the only chance to tell
243
+ * them before a browser does is right here — the scoped logger does not
244
+ * exist yet at phase 2c, so these go to the boot console like every other
245
+ * line in this file, and post-boot re-reports it as an alert.
246
+ */
247
+ function logTlsCert(result) {
248
+ if (!result.generated) {
249
+ console.log(`[Phase2c] TLS cert unchanged — ${result.certPath} (leaf ${result.fingerprintSha256}, valid to ${result.validTo})`);
250
+ return;
251
+ }
252
+ console.log(`[Phase2c] TLS CERTIFICATE REISSUED — reason=${result.reason}, caRotated=${result.caRotated}`);
253
+ console.log(`[Phase2c] leaf ${result.previousFingerprintSha256 ?? '(none)'} → ${result.fingerprintSha256}`);
254
+ console.log(`[Phase2c] valid to ${result.validTo}, names: ${result.sans.join(', ')}`);
255
+ console.log(result.caRotated
256
+ ? `[Phase2c] ACTION REQUIRED: the local CA changed. Install ${result.caCertPath} (SHA-256 ${result.caFingerprintSha256}) on every device that trusted the previous certificate.`
257
+ : `[Phase2c] Local CA unchanged (${result.caFingerprintSha256}) — devices that trust ${result.caCertPath} keep working.`);
258
+ }
@@ -37,7 +37,7 @@ class PostBootService {
37
37
  return entry.payload;
38
38
  }
39
39
  async run(context) {
40
- const { port, host, dataPath, trpcRegistered } = context;
40
+ const { port, host, dataPath, trpcRegistered, tlsCert } = context;
41
41
  // Device stream wiring moved into `addon-stream-broker` — the addon
42
42
  // does its own initial sync against `ctx.deviceRegistry` plus listens
43
43
  // to `DeviceRegistered` events for future registrations. No kernel
@@ -56,6 +56,9 @@ class PostBootService {
56
56
  // restart, …). `readPendingRestart` clears the marker atomically so
57
57
  // we never re-fire on a crash-loop boot.
58
58
  this.emitRestartCompletedIfPending(dataPath);
59
+ // A certificate that changed underneath the operator is an alert, not
60
+ // a boot line they will never scroll back to (D227).
61
+ this.emitTlsCertChangedIfReissued(tlsCert);
59
62
  // Re-drive every non-terminal lifecycle job (addon task phases) from its
60
63
  // on-disk checkpoint. Framework tasks are no longer applied by the engine
61
64
  // (single-copy collapse — framework updates ship via applyServerUpdate);
@@ -68,6 +71,27 @@ class PostBootService {
68
71
  this.logger.info('Lifecycle jobs reconciled at boot', { meta: { resumed, failed } });
69
72
  }
70
73
  }
74
+ emitTlsCertChangedIfReissued(tlsCert) {
75
+ if (tlsCert === undefined || !tlsCert.generated)
76
+ return;
77
+ const payload = {
78
+ reason: tlsCert.reason ?? 'unknown',
79
+ fingerprintSha256: tlsCert.fingerprintSha256,
80
+ caFingerprintSha256: tlsCert.caFingerprintSha256,
81
+ caRotated: tlsCert.caRotated,
82
+ caCertPath: tlsCert.caCertPath,
83
+ validTo: tlsCert.validTo,
84
+ sans: tlsCert.sans,
85
+ };
86
+ this.logger.warn('TLS certificate reissued', { meta: payload });
87
+ this.eventBus.emit({
88
+ id: (0, node_crypto_1.randomUUID)(),
89
+ timestamp: new Date(),
90
+ source: { type: 'core', id: 'system' },
91
+ category: types_1.EventCategory.SystemTlsCertChanged,
92
+ data: payload,
93
+ });
94
+ }
71
95
  emitRestartCompletedIfPending(dataDir) {
72
96
  const marker = (0, system_1.readPendingRestart)(dataDir);
73
97
  if (marker === null)
package/dist/main.js CHANGED
@@ -249,7 +249,7 @@ async function bootstrap() {
249
249
  path.join(process.env.CAMSTACK_DATA ?? path.join(process.cwd(), 'camstack-data'), 'config.yaml');
250
250
  const bootstrapConfig = (0, boot_config_1.loadBootstrapConfig)(configPath);
251
251
  const infra = await (0, boot_config_1.setupInfra)(configPath, bootstrapConfig);
252
- const { dataPath, tlsOptions } = infra;
252
+ const { dataPath, tlsOptions, tlsCert } = infra;
253
253
  const port = infra.bootstrapConfig.server.port;
254
254
  const host = infra.bootstrapConfig.server.host;
255
255
  // --- Phase 3: Create app + tRPC register + listen ---
@@ -1321,7 +1321,7 @@ async function bootstrap() {
1321
1321
  void Promise.all([resolveAdminUi(), resolveViewerUi()]);
1322
1322
  // Post-boot: fork workers, register device streams, emit system.boot
1323
1323
  const postBoot = app.get(post_boot_service_1.PostBootService);
1324
- await postBoot.run({ port, host, dataPath, trpcRegistered });
1324
+ await postBoot.run({ port, host, dataPath, trpcRegistered, tlsCert });
1325
1325
  // The hub reached ready — when this boot is the PROBATION boot of a freshly
1326
1326
  // staged @camstack/server root, promote it (currentVersion ← pending, N-1
1327
1327
  // retained for rollback) and disarm the starter's crash-loop auto-rollback.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.143",
3
+ "version": "1.2.144",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -33,18 +33,18 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@camstack/addon-admin-ui": "1.2.86",
37
- "@camstack/addon-agent-ui": "1.2.26",
38
- "@camstack/addon-auth": "1.2.28",
39
- "@camstack/addon-decoder-nodeav": "1.2.24",
40
- "@camstack/addon-notifiers": "1.2.29",
41
- "@camstack/addon-pipeline": "1.2.105",
42
- "@camstack/addon-pipeline-orchestrator": "1.2.88",
43
- "@camstack/addon-post-analysis": "1.2.107",
44
- "@camstack/sdk": "1.2.27",
45
- "@camstack/system": "1.2.114",
46
- "@camstack/types": "1.2.95",
47
- "@camstack/ui-library": "1.2.65",
36
+ "@camstack/addon-admin-ui": "1.2.87",
37
+ "@camstack/addon-agent-ui": "1.2.27",
38
+ "@camstack/addon-auth": "1.2.29",
39
+ "@camstack/addon-decoder-nodeav": "1.2.25",
40
+ "@camstack/addon-notifiers": "1.2.30",
41
+ "@camstack/addon-pipeline": "1.2.106",
42
+ "@camstack/addon-pipeline-orchestrator": "1.2.89",
43
+ "@camstack/addon-post-analysis": "1.2.108",
44
+ "@camstack/sdk": "1.2.28",
45
+ "@camstack/system": "1.2.115",
46
+ "@camstack/types": "1.2.96",
47
+ "@camstack/ui-library": "1.2.66",
48
48
  "@fastify/compress": "^9.0.0",
49
49
  "@fastify/cookie": "^11.0.2",
50
50
  "@fastify/cors": "^11.2.0",