Files
events-hub/backend/scripts/generate-keys.js
T
joshuaandClaude Opus 5.5 041461f2b5 Servers and the agent, backend (2.1.0): join, jobs, schedules, port list, stats, alerts
- Agent API /api/agent/v1: join with a one-time token, then poll, stats,
  report and export upload, all signed with the server's Ed25519 key.
- Jobs signed with a separate job key (HUB_JOB_SIGNING_KEY_FILE) when
  delivered, config sealed to the server; one at a time per server;
  missed when not picked up in their window.
- New install (licence, ports, preflight against the release's env
  template), Proxy done with public URL checks, scheduled / emergency
  (2FA, reason) / batch updates with email and banner, uninstall with
  an encrypted export first (the key is never stored), adopt and
  linking existing installs, purge after 30 days.
- Port list, install defaults, server configuration (encrypted), stats
  per minute / hour with roll-up, server alerts. contracts 1.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 13:12:28 +02:00

38 lines
1.7 KiB
JavaScript

/**
* Create the Hub's signing key pairs (Ed25519).
*
* npm run generate-keys → keys/hub-signing-key.pem: licences (refuses to overwrite)
* npm run generate-keys -- --job → keys/hub-job-key.pem: jobs for server agents (2.1.0)
* add --force to replace one: every install then needs the new licence key, or every server
* must join again for a new job key (agents pin it when they join).
*
* The private keys stay on the Hub server only — back them up somewhere safe. The two are
* separate, so a leaked job key can't sign licences and the other way round.
*/
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const job = process.argv.includes('--job');
const dir = path.join(__dirname, '..', 'keys');
const file = path.join(dir, job ? 'hub-job-key.pem' : 'hub-signing-key.pem');
if (fs.existsSync(file) && !process.argv.includes('--force')) {
console.error(`${file} already exists. Use --force to replace it (${job ? 'every server would have to join again' : 'installs would need the new public key'}).`);
process.exit(1);
}
const { privateKey, publicKey } = crypto.generateKeyPairSync('ed25519');
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(file, privateKey.export({ type: 'pkcs8', format: 'pem' }), { mode: 0o600 });
console.log(`Private key written to ${file} — keep it secret and back it up.`);
if (job) {
console.log('Set HUB_JOB_SIGNING_KEY_FILE to that path in .env. Agents receive the public key when they join.');
} else {
console.log('Set HUB_SIGNING_KEY_FILE to that path in .env.\n');
console.log('Public key (for Cross Events, backend/src/hub/publicKey.js):\n');
console.log(publicKey.export({ type: 'spki', format: 'pem' }));
}