mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Refactor SSL certificate creation
Rewrite the generateSSLcert lib to be async, use the sslCert and
sslPrivKey config entries and invoke it only if needed during master
server startup instead of in the post install script. Also add note to
the changelog covering both this and the fix in c645fac.
This commit is contained in:
1 parent
cc87654742
commit
44b7d0aa19
5 files changed
+58
-52
No files matched your search
@@ -41,6 +41,7 @@ mkdirp.sync(config.databaseDirectory);
|
||||
mkdirp.sync(masterModFolder);
|
||||
|
||||
// homebrew modules
|
||||
const generateSSLcert = require("lib/generateSSLcert");
|
||||
const getFactorioLocale = require("lib/getFactorioLocale");
|
||||
|
||||
// homemade express middleware for token auth
|
||||
@@ -1005,6 +1006,15 @@ async function startServer() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create a self signed certificate if the certificate files doesn't exist
|
||||
if (httpsPort && !await fs.exists(config.sslCert) && !await fs.exists(config.sslPrivKey)) {
|
||||
await generateSSLcert({
|
||||
sslCertPath: config.sslCert,
|
||||
sslPrivKeyPath: config.sslPrivKey,
|
||||
doLogging: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Load plugins
|
||||
await pluginManagement();
|
||||
|
||||
@@ -1016,8 +1026,15 @@ async function startServer() {
|
||||
}
|
||||
|
||||
if (httpsPort) {
|
||||
var certificate = fs.readFileSync(config.sslCert);
|
||||
var privateKey = fs.readFileSync(config.sslPrivKey);
|
||||
let certificate, privateKey;
|
||||
try {
|
||||
certificate = await fs.readFile(config.sslCert);
|
||||
privateKey = await fs.readFile(config.sslPrivKey);
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error loading ssl certificate: ${err.message}`);
|
||||
await shutdown()
|
||||
}
|
||||
|
||||
let httpsServer = require("https").createServer({
|
||||
key: privateKey,
|
||||
|
||||
Reference in new issue
Block a user