Fixed device group not found bug, #2948

Ylian Saint-Hilaire committed Jul 29, 2021 at 15:51 UTC 58039c4c1a0e85c3b20e8a2e0b082739510be0df
2 files changed +10 -15
agents/meshcore.js
+4 -4
@@ -3978,8 +3978,8 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3978 var rx = '';
3979 var apfarg = {
3980 mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
3981 - mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
3982 - mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
3981 + mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
3982 + mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
3983 mpskeepalive: 60000,
3984 clientname: state.OsHostname,
3985 clientaddress: '127.0.0.1',
@@ -4018,8 +4018,8 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4018 if (connType >= 0) { // Connect
4019 var apfarg = {
4020 mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
4021 - mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
4022 - mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
4021 + mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
4022 + mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
4023 mpskeepalive: 60000,
4024 clientname: require('os').hostname(),
4025 clientaddress: '127.0.0.1',
amtmanager.js
+6 -11
@@ -1897,7 +1897,7 @@ module.exports.CreateAmtManager = function (parent) {
1897 if (amtPolicy == 2) { activateIntelAmtCcm(dev, mesh.amt.password); } // Activate to CCM policy
1898 if ((amtPolicy == 3) || (amtPolicy == 4)) { // Activate to ACM policy
1899 var acminfo = checkAcmActivation(dev);
1900 - if (acminfo == null) {
1900 + if ((acminfo == null) || (acminfo.err != null)) {
1901 // No opportunity to activate to ACM, check if we are in CCM
1902 if ((dev.mpsConnection.tag.meiState.Flags & 2) != 0) {
1903 if ((amtPolicy == 3) && (ccmPolicy == 1)) { deactivateIntelAmtCCM(dev); } // If we are in ACM policy and CCM is not allowed, deactivate it now.
@@ -1907,11 +1907,7 @@ module.exports.CreateAmtManager = function (parent) {
1907 if ((amtPolicy == 4) || ((amtPolicy == 3) && (ccmPolicy == 2))) { activateIntelAmtCcm(dev, mesh.amt.password); } // If we are in full automatic or ACM with CCM allowed, setup CCM.
1908 else {
1909 // Unable to find an activation match.
1910 - var trustedFqdn = null;
1911 - if (dev.mpsConnection.tag.meiState.OsDnsSuffix != null) { trustedFqdn = dev.mpsConnection.tag.meiState.OsDnsSuffix; }
1912 - if (dev.mpsConnection.tag.meiState.DnsSuffix != null) { trustedFqdn = dev.mpsConnection.tag.meiState.DnsSuffix; }
1913 - //dev.consoleMsg("No opportunity for ACM activation, trusted FQDN: " + ((trustedFqdn == null) ? "(Not Set)" : trustedFqdn));
1914 - dev.consoleMsg("No opportunity for ACM activation, trusted FQDN: " + ((trustedFqdn == null) ? "(Not Set)" : (trustedFqdn + ", HEX: " + Buffer.from(trustedFqdn).toString('hex'))));
1910 + if (acminfo == null) { dev.consoleMsg("No opportunity for ACM activation."); } else { dev.consoleMsg("No opportunity for ACM activation: " + acminfo.err); }
1911 removeAmtDevice(dev, 38);
1912 return false; // We are not in CCM and policy restricts use of CCM, so exit now.
1913 }
@@ -2014,17 +2010,16 @@ module.exports.CreateAmtManager = function (parent) {
2010 // Check if this device has any way to be activated in ACM using our server certificates.
2011 function checkAcmActivation(dev) {
2012 var domain = parent.config.domains[dev.domainid];
2017 - if ((domain == null) || (domain.amtacmactivation == null) || (domain.amtacmactivation.certs == null) || (domain.amtacmactivation.certs.length == 0)) return null;
2013 + if ((domain == null) || (domain.amtacmactivation == null) || (domain.amtacmactivation.certs == null) || (domain.amtacmactivation.certs.length == 0)) return { err: "Server does not have any ACM activation certificates." };
2014 const activationCerts = domain.amtacmactivation.certs;
2019 - if ((dev.mpsConnection.tag.meiState == null) || (dev.mpsConnection.tag.meiState.Hashes == null) || (dev.mpsConnection.tag.meiState.Hashes.length == 0)) return null;
2015 + if ((dev.mpsConnection.tag.meiState == null) || (dev.mpsConnection.tag.meiState.Hashes == null) || (dev.mpsConnection.tag.meiState.Hashes.length == 0)) return { err: "Intel AMT did not report any trusted hashes." };
2016 const deviceHashes = dev.mpsConnection.tag.meiState.Hashes;
2021 - if (deviceHashes == null) return null;
2017
2018 // Get the trusted FQDN of the device
2019 var trustedFqdn = null;
2020 if (dev.mpsConnection.tag.meiState.OsDnsSuffix != null) { trustedFqdn = dev.mpsConnection.tag.meiState.OsDnsSuffix; }
2021 if (dev.mpsConnection.tag.meiState.DnsSuffix != null) { trustedFqdn = dev.mpsConnection.tag.meiState.DnsSuffix; }
2027 - if (trustedFqdn == null) return null;
2022 + if (trustedFqdn == null) return { err: "No trusted DNS suffix reported" };
2023
2024 // Find a matching certificate
2025 for (var i in activationCerts) {
@@ -2039,7 +2034,7 @@ module.exports.CreateAmtManager = function (parent) {
2034 }
2035 }
2036 }
2042 - return null; // Did not find a match
2037 + return { err: "No matching ACM activation certificate for \"" + trustedFqdn + "\"." }; // Did not find a match
2038 }
2039
2040 // Return true if the trusted FQDN matched the certificate common name