Move generation of auth secret to master startup

Move the code generating the master authentication secret from the
inital value function of the master.auth_secret config entry to the
master startup.  Having the authentication secret generated in the
config library poses issues with using the config library in browser.
This commit is contained in:
Hornwitser committed 2020-10-21 17:58:30 +02:00
1 parent 34a0ce4dc3
commit 2a7bc75929
2 files changed
+10 -11

No files matched your search

+1 -9
View File
@@ -1,9 +1,6 @@
// Core definitions for the configuration system
"use strict";
const util = require("util");
const crypto = require("crypto");
const path = require("path");
const fs = require("fs-extra");
const classes = require("./classes");
@@ -76,12 +73,7 @@ MasterGroup.define({
+" Should be a long string of random letters and numbers."
+" Do not share this.",
type: "string",
initial_value: async function() {
console.log("Generating new master authentication secret");
let asyncRandomBytes = util.promisify(crypto.randomBytes);
let bytes = await asyncRandomBytes(256);
return bytes.toString("base64");
},
optional: true,
});
MasterGroup.define({
name: "heartbeat_interval",
+9 -2
View File
@@ -29,6 +29,7 @@ const yargs = require("yargs");
const WebSocket = require("ws");
const JSZip = require("jszip");
const version = require("./package").version;
const util = require("util");
// ugly globals
let masterConfig;
@@ -1595,6 +1596,14 @@ async function startServer() {
}
}
if (!masterConfig.get("master.auth_secret")) {
console.log("Generating new master authentication secret");
let asyncRandomBytes = util.promisify(crypto.randomBytes);
let bytes = await asyncRandomBytes(256);
masterConfig.set("master.auth_secret", bytes.toString("base64"));
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
}
let command = args._[0];
if (command === "config") {
await config.handleConfigCommand(args, masterConfig, masterConfigPath);
@@ -1642,8 +1651,6 @@ async function startServer() {
}
}
// Save config in case the auth_secret was generated during this invocation.
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
return;
}