mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 23:24:52 +09:00
Split up codebase into the packages @clsterio/lib, @clusterio/master, @clusterio/slave, and @clusterio/ctl using lerna to manage them. This will allow deployment to use only the parts needed reducing install size, and better separate the code into shared library, master, slave and control.
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
"use strict";
|
|
const forge = require("node-forge");
|
|
const fs = require("fs-extra");
|
|
const util = require("util");
|
|
|
|
const hrtime = process.hrtime.bigint;
|
|
|
|
|
|
module.exports = async function({
|
|
bits = 2048,
|
|
sslCertPath,
|
|
sslPrivKeyPath,
|
|
doLogging = false,
|
|
} = {}){
|
|
function log(t) {
|
|
if(doLogging) console.log("src/generate_ssl_cert.js | "+t);
|
|
}
|
|
log("Generating SSL certificate with "+bits+" bits at "+sslCertPath);
|
|
|
|
let startNs = hrtime();
|
|
let keypair = await util.promisify(forge.pki.rsa.generateKeyPair)({ bits: bits, e: 0x10001 });
|
|
log("Generated 2048bit keypair in: "+(Number(hrtime()-startNs) / 1e6)+" ms");
|
|
|
|
startNs = hrtime();
|
|
let cert = forge.pki.createCertificate();
|
|
cert.publicKey = keypair.publicKey;
|
|
cert.serialNumber = "01";
|
|
|
|
cert.validity.notBefore = new Date();
|
|
cert.validity.notAfter = new Date(Date.now()+(1000*60*60*24*365)); // valid for one year
|
|
|
|
// XXX This should probably be limited to the actual hostname
|
|
let attrs = [{ name: "commonName", value: "*" }];
|
|
cert.setSubject(attrs);
|
|
cert.setIssuer(attrs);
|
|
|
|
// self-sign certificate
|
|
cert.sign(keypair.privateKey);
|
|
|
|
// Write certificate and private key to pem files
|
|
await fs.outputFile(sslPrivKeyPath, forge.pki.privateKeyToPem(keypair.privateKey));
|
|
await fs.outputFile(sslCertPath, forge.pki.certificateToPem(cert));
|
|
|
|
log("Generated certificate in: "+(Number(hrtime()-startNs) / 1e6)+" ms");
|
|
};
|