/** * 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' })); }