Added workaround if MeshCentral can't sign the agents, #4069

Ylian Saint-Hilaire committed Jun 1, 2022 at 16:29 UTC 43bbabc00c08279e2ce66011f8b632c6a0312d84
2 files changed +14 -6
authenticode.js
+4 -1
@@ -505,7 +505,9 @@ function createAuthenticodeHandler(path) {
505 //console.log('Signature', Buffer.from(p7signature, 'binary').toString('base64'));
506
507 // Open the output file
508 - var output = fs.openSync(args.out, 'w');
508 + var output = null;
509 + try { output = fs.openSync(args.out, 'w'); } catch (ex) { }
510 + if (output == null) return false;
511 var tmp, written = 0;
512 var executableSize = obj.header.sigpos ? obj.header.sigpos : this.filesize;
513
@@ -544,6 +546,7 @@ function createAuthenticodeHandler(path) {
546
547 // Close the file
548 fs.closeSync(output);
549 + return true;
550 }
551
552 // Save an executable without the signature
meshcentral.js
+10 -5
@@ -2918,13 +2918,18 @@ function CreateMeshCentralServer(config, args) {
2918 if (destinationAgentOk == false) {
2919 // If not signed correctly, sign it. First, create the server signed agent folder if needed
2920 try { obj.fs.mkdirSync(serverSignedAgentsPath); } catch (ex) { }
2921 - console.log(obj.common.format('Code signing agent {0}...', obj.meshAgentsArchitectureNumbers[archid].localname));
2922 - originalAgent.sign(agentSignCertInfo, { out: signeedagentpath, desc: signDesc, url: signUrl });
2921 + if (originalAgent.sign(agentSignCertInfo, { out: signeedagentpath, desc: signDesc, url: signUrl }) == true) {
2922 + // Agent was signed succesfuly
2923 + agentpath = signeedagentpath;
2924 + console.log(obj.common.format('Code signed agent {0}.', obj.meshAgentsArchitectureNumbers[archid].localname));
2925 + } else {
2926 + console.log(obj.common.format('Failed to sign agent {0}.', obj.meshAgentsArchitectureNumbers[archid].localname));
2927 + }
2928 + } else {
2929 + // Signed agent is already ok, use it.
2930 + agentpath = signeedagentpath;
2931 }
2932 originalAgent.close();
2925 -
2926 - // Update agent path to signed agent
2927 - agentpath = signeedagentpath;
2933 }
2934 }
2935