Fixed certificate creation when using with authenticode.

Ylian Saint-Hilaire committed May 29, 2022 at 11:16 UTC 25c805d7eabb9bbe223f527a46669edeae72b7ff
2 files changed +13 -10
certoperations.js
+1 -1
@@ -1089,7 +1089,7 @@ module.exports.CertificateOperations = function (parent) {
1089 mpsPrivateKey = r.mps.key;
1090 }
1091
1092 - r = { root: { cert: rootCertificate, key: rootPrivateKey }, web: { cert: webCertificate, key: webPrivateKey, ca: [] }, webdefault: { cert: webCertificate, key: webPrivateKey, ca: [] }, mps: { cert: mpsCertificate, key: mpsPrivateKey }, agent: { cert: agentCertificate, key: agentPrivateKey }, ca: calist, CommonName: commonName, RootName: rootName, AmtMpsName: mpsCommonName, dns: {}, WebIssuer: webIssuer };
1092 + r = { root: { cert: rootCertificate, key: rootPrivateKey }, web: { cert: webCertificate, key: webPrivateKey, ca: [] }, webdefault: { cert: webCertificate, key: webPrivateKey, ca: [] }, mps: { cert: mpsCertificate, key: mpsPrivateKey }, agent: { cert: agentCertificate, key: agentPrivateKey }, codesign: { cert: codesignCertificate, key: codesignPrivateKey }, ca: calist, CommonName: commonName, RootName: rootName, AmtMpsName: mpsCommonName, dns: {}, WebIssuer: webIssuer };
1093
1094 // Fetch the certificates names for the main certificate
1095 var webCertificate = obj.pki.certificateFromPem(r.web.cert);
meshcentral.js
+12 -9
@@ -2860,14 +2860,17 @@ function CreateMeshCentralServer(config, args) {
2860 }
2861
2862 // Generate the agent signature description and URL
2863 - const serverSignedAgentsPath = obj.path.join(obj.datapath, 'signedagents' + suffix);
2864 - var signDesc = (domain.title ? domain.title : agentSignCertInfo.cert.subject.hash);
2865 - var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
2866 - var signUrl = 'https://' + ((domain.dns != null) ? domain.dns : obj.certificates.CommonName);
2867 - if (httpsPort != 443) { signUrl += ':' + httpsPort; }
2868 - var xdomain = (domain.dns == null) ? domain.id : '';
2869 - if (xdomain != '') xdomain += '/';
2870 - signUrl += '/' + xdomain;
2863 + var serverSignedAgentsPath, signDesc, signUrl;
2864 + if (agentSignCertInfo != null) {
2865 + serverSignedAgentsPath = obj.path.join(obj.datapath, 'signedagents' + suffix);
2866 + signDesc = (domain.title ? domain.title : agentSignCertInfo.cert.subject.hash);
2867 + var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
2868 + signUrl = 'https://' + ((domain.dns != null) ? domain.dns : obj.certificates.CommonName);
2869 + if (httpsPort != 443) { signUrl += ':' + httpsPort; }
2870 + var xdomain = (domain.dns == null) ? domain.id : '';
2871 + if (xdomain != '') xdomain += '/';
2872 + signUrl += '/' + xdomain;
2873 + }
2874
2875 // Load agent information file. This includes the data & time of the agent.
2876 const agentInfo = [];
@@ -2893,7 +2896,7 @@ function CreateMeshCentralServer(config, args) {
2896 if ((stats == null)) continue; // If this agent does not exist, skip it.
2897
2898 // Check if we need to sign this agent, if so, check if it's already been signed
2896 - if (obj.meshAgentsArchitectureNumbers[archid].codesign === true) {
2899 + if ((obj.meshAgentsArchitectureNumbers[archid].codesign === true) && (agentSignCertInfo != null)) {{
2900 // Open the original agent with authenticode
2901 var signeedagentpath = obj.path.join(serverSignedAgentsPath, obj.meshAgentsArchitectureNumbers[archid].localname);
2902 const originalAgent = require('./authenticode.js').createAuthenticodeHandler(agentpath);