Fixed CR end-of-line certificate loading.
This commit is contained in:
parent
8d21e843a6
commit
38b24e256c
|
@ -139,7 +139,6 @@
|
||||||
<Content Include="agents\meshagent_arm" />
|
<Content Include="agents\meshagent_arm" />
|
||||||
<Content Include="agents\meshagent_arm-linaro" />
|
<Content Include="agents\meshagent_arm-linaro" />
|
||||||
<Content Include="agents\meshagent_osx-x86-64" />
|
<Content Include="agents\meshagent_osx-x86-64" />
|
||||||
<Content Include="agents\meshagent_pi" />
|
|
||||||
<Content Include="agents\meshagent_pogo" />
|
<Content Include="agents\meshagent_pogo" />
|
||||||
<Content Include="agents\meshagent_poky" />
|
<Content Include="agents\meshagent_poky" />
|
||||||
<Content Include="agents\meshagent_poky64" />
|
<Content Include="agents\meshagent_poky64" />
|
||||||
|
|
|
@ -146,6 +146,12 @@ module.exports.CertificateOperations = function () {
|
||||||
return { cert: cert, key: keys.privateKey };
|
return { cert: cert, key: keys.privateKey };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Make sure a string with Mac style CR endo of line is changed to Linux LF style.
|
||||||
|
function fixEndOfLines(str) {
|
||||||
|
if ((typeof(str) != 'string') || (str.indexOf('\n') > 0)) return str; // If there is a \n in the file, keep the file as-is.
|
||||||
|
return str.split('\r').join('\n'); // If there is no \n, replace all \r with \n.
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the web server TLS certificate and private key, if not present, create demonstration ones.
|
// Returns the web server TLS certificate and private key, if not present, create demonstration ones.
|
||||||
obj.GetMeshServerCertificate = function (parent, args, config, func) {
|
obj.GetMeshServerCertificate = function (parent, args, config, func) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
@ -166,8 +172,8 @@ module.exports.CertificateOperations = function () {
|
||||||
|
|
||||||
// If the root certificate already exist, load it
|
// If the root certificate already exist, load it
|
||||||
if (obj.fileExists(parent.getConfigFilePath("root-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("root-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("root-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("root-cert-private.key"))) {
|
||||||
var rootCertificate = obj.fs.readFileSync(parent.getConfigFilePath("root-cert-public.crt"), "utf8");
|
var rootCertificate = fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("root-cert-public.crt"), "utf8"));
|
||||||
var rootPrivateKey = obj.fs.readFileSync(parent.getConfigFilePath("root-cert-private.key"), "utf8");
|
var rootPrivateKey = fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("root-cert-private.key"), "utf8"));
|
||||||
r.root = { cert: rootCertificate, key: rootPrivateKey };
|
r.root = { cert: rootCertificate, key: rootPrivateKey };
|
||||||
rcount++;
|
rcount++;
|
||||||
}
|
}
|
||||||
|
@ -175,44 +181,44 @@ module.exports.CertificateOperations = function () {
|
||||||
if (args.tlsoffload) {
|
if (args.tlsoffload) {
|
||||||
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
|
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt"))) {
|
||||||
r.web = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8") };
|
r.web = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8")) };
|
||||||
rcount++;
|
rcount++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the web certificate already exist, load it. Load both certificate and private key
|
// If the web certificate already exist, load it. Load both certificate and private key
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-cert-private.key"))) {
|
||||||
r.web = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-private.key"), "utf8") };
|
r.web = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8")), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-private.key"), "utf8")) };
|
||||||
rcount++;
|
rcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mps certificate already exist, load it
|
// If the mps certificate already exist, load it
|
||||||
if (obj.fileExists(parent.getConfigFilePath("mpsserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("mpsserver-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("mpsserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("mpsserver-cert-private.key"))) {
|
||||||
r.mps = { cert: obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-private.key"), "utf8") };
|
r.mps = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-public.crt")), "utf8"), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-private.key"), "utf8")) };
|
||||||
rcount++;
|
rcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the agent certificate already exist, load it
|
// If the agent certificate already exist, load it
|
||||||
if (obj.fileExists(parent.getConfigFilePath("agentserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("agentserver-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("agentserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("agentserver-cert-private.key"))) {
|
||||||
r.agent = { cert: obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-private.key"), "utf8") };
|
r.agent = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-public.crt")), "utf8"), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-private.key"), "utf8")) };
|
||||||
rcount++;
|
rcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the swarm server certificate exist, load it (This is an optional certificate)
|
// If the swarm server certificate exist, load it (This is an optional certificate)
|
||||||
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
|
||||||
r.swarmserver = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8") };
|
r.swarmserver = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8")), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8")) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the swarm server root certificate exist, load it (This is an optional certificate)
|
// If the swarm server root certificate exist, load it (This is an optional certificate)
|
||||||
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
|
||||||
r.swarmserverroot = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8") };
|
r.swarmserverroot = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8")) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If CA certificates are present, load them
|
// If CA certificates are present, load them
|
||||||
do {
|
do {
|
||||||
caok = false;
|
caok = false;
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
|
||||||
calist.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8"));
|
calist.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8")));
|
||||||
caok = true;
|
caok = true;
|
||||||
}
|
}
|
||||||
caindex++;
|
caindex++;
|
||||||
|
@ -251,7 +257,7 @@ module.exports.CertificateOperations = function () {
|
||||||
if (args.tlsoffload) {
|
if (args.tlsoffload) {
|
||||||
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
|
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"))) {
|
||||||
r.dns[i] = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8") };
|
r.dns[i] = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8")) };
|
||||||
config.domains[i].certs = r.dns[i];
|
config.domains[i].certs = r.dns[i];
|
||||||
} else {
|
} else {
|
||||||
console.log("WARNING: File \"webserver-" + i + "-cert-public.crt\" missing, domain \"" + i + "\" will not work correctly.");
|
console.log("WARNING: File \"webserver-" + i + "-cert-public.crt\" missing, domain \"" + i + "\" will not work correctly.");
|
||||||
|
@ -259,7 +265,7 @@ module.exports.CertificateOperations = function () {
|
||||||
} else {
|
} else {
|
||||||
// If the web certificate already exist, load it. Load both certificate and private key
|
// If the web certificate already exist, load it. Load both certificate and private key
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-private.key"))) {
|
||||||
r.dns[i] = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-private.key"), "utf8") };
|
r.dns[i] = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8")), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-private.key"), "utf8")) };
|
||||||
config.domains[i].certs = r.dns[i];
|
config.domains[i].certs = r.dns[i];
|
||||||
// If CA certificates are present, load them
|
// If CA certificates are present, load them
|
||||||
caindex = 1;
|
caindex = 1;
|
||||||
|
@ -267,7 +273,7 @@ module.exports.CertificateOperations = function () {
|
||||||
do {
|
do {
|
||||||
caok = false;
|
caok = false;
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
|
||||||
r.dns[i].ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8"));
|
r.dns[i].ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8")));
|
||||||
caok = true;
|
caok = true;
|
||||||
}
|
}
|
||||||
caindex++;
|
caindex++;
|
||||||
|
@ -413,7 +419,7 @@ module.exports.CertificateOperations = function () {
|
||||||
do {
|
do {
|
||||||
caok = false;
|
caok = false;
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
|
||||||
r.dns[i].ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8"));
|
r.dns[i].ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8")));
|
||||||
caok = true;
|
caok = true;
|
||||||
}
|
}
|
||||||
caindex++;
|
caindex++;
|
||||||
|
@ -425,12 +431,12 @@ module.exports.CertificateOperations = function () {
|
||||||
|
|
||||||
// If the swarm server certificate exist, load it (This is an optional certificate)
|
// If the swarm server certificate exist, load it (This is an optional certificate)
|
||||||
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
|
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
|
||||||
r.swarmserver = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8") };
|
r.swarmserver = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8")), key: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8")) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the swarm server root certificate exist, load it (This is an optional certificate)
|
// If the swarm server root certificate exist, load it (This is an optional certificate)
|
||||||
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
|
||||||
r.swarmserverroot = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8") };
|
r.swarmserverroot = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8")) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If CA certificates are present, load them
|
// If CA certificates are present, load them
|
||||||
|
@ -440,7 +446,7 @@ module.exports.CertificateOperations = function () {
|
||||||
do {
|
do {
|
||||||
caok = false;
|
caok = false;
|
||||||
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
|
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
|
||||||
r.web.ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8"));
|
r.web.ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8")));
|
||||||
caok = true;
|
caok = true;
|
||||||
}
|
}
|
||||||
caindex++;
|
caindex++;
|
||||||
|
|
|
@ -16,8 +16,16 @@
|
||||||
|
|
||||||
module.exports.CreateLetsEncrypt = function (parent) {
|
module.exports.CreateLetsEncrypt = function (parent) {
|
||||||
try {
|
try {
|
||||||
const greenlock = require('greenlock');
|
// Try to delete the "./ursa-optional" or "./node_modules/ursa-optional" folder if present.
|
||||||
|
// This is an optional module that GreenLock uses that causes issues.
|
||||||
|
try {
|
||||||
|
const fs = require('fs');
|
||||||
|
if (fs.existsSync(obj.path.join(__dirname, 'ursa-optional'))) { fs.unlinkSync(obj.path.join(__dirname, 'ursa-optional')); }
|
||||||
|
if (fs.existsSync(obj.path.join(__dirname, 'node_modules', 'ursa-optional'))) { fs.unlinkSync(obj.path.join(__dirname, 'node_modules', 'ursa-optional')); }
|
||||||
|
} catch (ex) { }
|
||||||
|
|
||||||
|
// Get GreenLock setup and running.
|
||||||
|
const greenlock = require('greenlock');
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj.parent = parent;
|
obj.parent = parent;
|
||||||
obj.redirWebServerHooked = false;
|
obj.redirWebServerHooked = false;
|
||||||
|
|
|
@ -1297,7 +1297,7 @@ function InstallModule(modulename, func, tag1, tag2) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Installing ' + modulename + '...');
|
console.log('Installing ' + modulename + '...');
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
child_process.exec('npm install ' + modulename + ' --save', { maxBuffer: 512000 }, function (error, stdout, stderr) {
|
child_process.exec('npm install ' + modulename + ' --no-optional --save', { maxBuffer: 512000 }, function (error, stdout, stderr) {
|
||||||
if (error != null) { console.log('ERROR: Unable to install missing package \'' + modulename + '\', make sure npm is installed.'); process.exit(); return; }
|
if (error != null) { console.log('ERROR: Unable to install missing package \'' + modulename + '\', make sure npm is installed.'); process.exit(); return; }
|
||||||
func(tag1, tag2);
|
func(tag1, tag2);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.2.6-d",
|
"version": "0.2.6-e",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
|
Loading…
Reference in New Issue