Fixed CR end-of-line certificate loading.
Ylian Saint-Hilaire committed
Jan 11, 2019 at 14:01 UTC
38b24e256ca98068eb3c0e7b8b3c81600a966e31
5 files changed
+33
-20
MeshCentralServer.njsproj
-1
@@ -139,7 +139,6 @@
139
<Content Include="agents\meshagent_arm" />
140
<Content Include="agents\meshagent_arm-linaro" />
141
<Content Include="agents\meshagent_osx-x86-64" />
142
- <Content Include="agents\meshagent_pi" />
142
<Content Include="agents\meshagent_pogo" />
143
<Content Include="agents\meshagent_poky" />
144
<Content Include="agents\meshagent_poky64" />
certoperations.js
+22
-16
@@ -146,6 +146,12 @@ module.exports.CertificateOperations = function () {
146
return { cert: cert, key: keys.privateKey };
147
};
148
149
+ // Make sure a string with Mac style CR endo of line is changed to Linux LF style.
150
+ function fixEndOfLines(str) {
151
+ if ((typeof(str) != 'string') || (str.indexOf('\n') > 0)) return str; // If there is a \n in the file, keep the file as-is.
152
+ return str.split('\r').join('\n'); // If there is no \n, replace all \r with \n.
153
+ }
154
+
155
// Returns the web server TLS certificate and private key, if not present, create demonstration ones.
156
obj.GetMeshServerCertificate = function (parent, args, config, func) {
157
var i = 0;
@@ -166,8 +172,8 @@ module.exports.CertificateOperations = function () {
172
173
// If the root certificate already exist, load it
174
if (obj.fileExists(parent.getConfigFilePath("root-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("root-cert-private.key"))) {
169
- var rootCertificate = obj.fs.readFileSync(parent.getConfigFilePath("root-cert-public.crt"), "utf8");
170
- var rootPrivateKey = obj.fs.readFileSync(parent.getConfigFilePath("root-cert-private.key"), "utf8");
175
+ var rootCertificate = fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("root-cert-public.crt"), "utf8"));
176
+ var rootPrivateKey = fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("root-cert-private.key"), "utf8"));
177
r.root = { cert: rootCertificate, key: rootPrivateKey };
178
rcount++;
179
}
@@ -175,44 +181,44 @@ module.exports.CertificateOperations = function () {
181
if (args.tlsoffload) {
182
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
183
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt"))) {
178
- r.web = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8") };
184
+ r.web = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8")) };
185
rcount++;
186
}
187
} else {
188
// If the web certificate already exist, load it. Load both certificate and private key
189
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-cert-private.key"))) {
184
- r.web = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-private.key"), "utf8") };
190
+ 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")) };
191
rcount++;
192
}
193
}
194
195
// If the mps certificate already exist, load it
196
if (obj.fileExists(parent.getConfigFilePath("mpsserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("mpsserver-cert-private.key"))) {
191
- r.mps = { cert: obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("mpsserver-cert-private.key"), "utf8") };
197
+ 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")) };
198
rcount++;
199
}
200
201
// If the agent certificate already exist, load it
202
if (obj.fileExists(parent.getConfigFilePath("agentserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("agentserver-cert-private.key"))) {
197
- r.agent = { cert: obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("agentserver-cert-private.key"), "utf8") };
203
+ 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")) };
204
rcount++;
205
}
206
207
// If the swarm server certificate exist, load it (This is an optional certificate)
208
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
203
- r.swarmserver = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8") };
209
+ 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")) };
210
}
211
212
// If the swarm server root certificate exist, load it (This is an optional certificate)
213
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
208
- r.swarmserverroot = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8") };
214
+ r.swarmserverroot = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8")) };
215
}
216
217
// If CA certificates are present, load them
218
do {
219
caok = false;
220
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
215
- calist.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8"));
221
+ calist.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8")));
222
caok = true;
223
}
224
caindex++;
@@ -251,7 +257,7 @@ module.exports.CertificateOperations = function () {
257
if (args.tlsoffload) {
258
// If the web certificate already exist, load it. Load just the certificate since we are in TLS offload situation
259
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"))) {
254
- r.dns[i] = { cert: obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8") };
260
+ r.dns[i] = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt"), "utf8")) };
261
config.domains[i].certs = r.dns[i];
262
} else {
263
console.log("WARNING: File \"webserver-" + i + "-cert-public.crt\" missing, domain \"" + i + "\" will not work correctly.");
@@ -259,7 +265,7 @@ module.exports.CertificateOperations = function () {
265
} else {
266
// If the web certificate already exist, load it. Load both certificate and private key
267
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-private.key"))) {
262
- 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") };
268
+ 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")) };
269
config.domains[i].certs = r.dns[i];
270
// If CA certificates are present, load them
271
caindex = 1;
@@ -267,7 +273,7 @@ module.exports.CertificateOperations = function () {
273
do {
274
caok = false;
275
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
270
- r.dns[i].ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8"));
276
+ r.dns[i].ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8")));
277
caok = true;
278
}
279
caindex++;
@@ -413,7 +419,7 @@ module.exports.CertificateOperations = function () {
419
do {
420
caok = false;
421
if (obj.fileExists(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"))) {
416
- r.dns[i].ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8"));
422
+ r.dns[i].ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-" + i + "-cert-chain" + caindex + ".crt"), "utf8")));
423
caok = true;
424
}
425
caindex++;
@@ -425,12 +431,12 @@ module.exports.CertificateOperations = function () {
431
432
// If the swarm server certificate exist, load it (This is an optional certificate)
433
if (obj.fileExists(parent.getConfigFilePath("swarmserver-cert-public.crt")) && obj.fileExists(parent.getConfigFilePath("swarmserver-cert-private.key"))) {
428
- r.swarmserver = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-public.crt"), "utf8"), key: obj.fs.readFileSync(parent.getConfigFilePath("swarmserver-cert-private.key"), "utf8") };
434
+ 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")) };
435
}
436
437
// If the swarm server root certificate exist, load it (This is an optional certificate)
438
if (obj.fileExists(parent.getConfigFilePath("swarmserverroot-cert-public.crt"))) {
433
- r.swarmserverroot = { cert: obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8") };
439
+ r.swarmserverroot = { cert: fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("swarmserverroot-cert-public.crt"), "utf8")) };
440
}
441
442
// If CA certificates are present, load them
@@ -440,7 +446,7 @@ module.exports.CertificateOperations = function () {
446
do {
447
caok = false;
448
if (obj.fileExists(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"))) {
443
- r.web.ca.push(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8"));
449
+ r.web.ca.push(fixEndOfLines(obj.fs.readFileSync(parent.getConfigFilePath("webserver-cert-chain" + caindex + ".crt"), "utf8")));
450
caok = true;
451
}
452
caindex++;
letsEncrypt.js
+9
-1
@@ -16,8 +16,16 @@
16
17
module.exports.CreateLetsEncrypt = function (parent) {
18
try {
19
+ // Try to delete the "./ursa-optional" or "./node_modules/ursa-optional" folder if present.
20
+ // This is an optional module that GreenLock uses that causes issues.
21
+ try {
22
+ const fs = require('fs');
23
+ if (fs.existsSync(obj.path.join(__dirname, 'ursa-optional'))) { fs.unlinkSync(obj.path.join(__dirname, 'ursa-optional')); }
24
+ if (fs.existsSync(obj.path.join(__dirname, 'node_modules', 'ursa-optional'))) { fs.unlinkSync(obj.path.join(__dirname, 'node_modules', 'ursa-optional')); }
25
+ } catch (ex) { }
26
+
27
+ // Get GreenLock setup and running.
28
const greenlock = require('greenlock');
20
-
29
var obj = {};
30
obj.parent = parent;
31
obj.redirWebServerHooked = false;
meshcentral.js
+1
-1
@@ -1297,7 +1297,7 @@ function InstallModule(modulename, func, tag1, tag2) {
1297
} catch (e) {
1298
console.log('Installing ' + modulename + '...');
1299
var child_process = require('child_process');
1300
- child_process.exec('npm install ' + modulename + ' --save', { maxBuffer: 512000 }, function (error, stdout, stderr) {
1300
+ child_process.exec('npm install ' + modulename + ' --no-optional --save', { maxBuffer: 512000 }, function (error, stdout, stderr) {
1301
if (error != null) { console.log('ERROR: Unable to install missing package \'' + modulename + '\', make sure npm is installed.'); process.exit(); return; }
1302
func(tag1, tag2);
1303
return;
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.2.6-d",
3
+ "version": "0.2.6-e",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",