Added fetching previous Intel AMT activation passwords into table.
Ylian Saint-Hilaire committed
Apr 3, 2021 at 18:29 UTC
85ef5fca26dd8e15f81e443d612b763ba1765796
4 files changed
+60
-1
certoperations.js
+16
@@ -131,6 +131,22 @@ module.exports.CertificateOperations = function (parent) {
131
// Log the Intel AMT activation operation in the domain log
132
obj.logAmtActivation = function (domain, x) {
133
if (x == null) return true;
134
+
135
+ // Add the password to the Intel AMT list of UUID to passwords
136
+ if ((typeof x.amtUuid == 'string') && (typeof x.password == 'string')) {
137
+ if (parent.amtPasswords == null) { parent.amtPasswords = {}; }
138
+ if (parent.amtPasswords[x.amtUuid] == null) {
139
+ parent.amtPasswords[x.amtUuid] = [x.password]; // Add password to array
140
+ parent.amtPasswords = parent.common.sortObj(parent.amtPasswords);
141
+ } else {
142
+ if (parent.amtPasswords[x.amtUuid].indexOf(x.password) == -1) {
143
+ parent.amtPasswords[x.amtUuid].unshift(x.password); // Add password at the start of the array
144
+ while (parent.amtPasswords[x.amtUuid].length > 3) { parent.amtPasswords[x.amtUuid].pop(); } // Only keep the 3 last passwords for any given device
145
+ }
146
+ }
147
+ }
148
+
149
+ // Append to the log file
150
var logpath = null;
151
if ((domain.amtacmactivation == null) || (domain.amtacmactivation.log == null) || (typeof domain.amtacmactivation.log != 'string')) {
152
if (domain.id == '') { logpath = parent.path.join(obj.parent.datapath, 'amtactivation.log'); } else { logpath = parent.path.join(obj.parent.datapath, 'amtactivation-' + domain.id + '.log'); }
common.js
+2
@@ -294,6 +294,8 @@ module.exports.meshServerRightsArrayToNumber = function (val) {
294
return null;
295
}
296
297
+// Sort an object by key
298
+module.exports.sortObj = function (obj) { return Object.keys(obj).sort().reduce(function (result, key) { result[key] = obj[key]; return result; }, {}); }
299
300
// Validate an object to make sure it can be stored in MongoDB
301
module.exports.validateObjectForMongo = function (obj, maxStrLen) {
meshcentral.js
+33
@@ -1696,6 +1696,11 @@ function CreateMeshCentralServer(config, args) {
1696
if (obj.config.settings.autobackup == null) { obj.config.settings.autobackup = { backupintervalhours: 24, keeplastdaysbackup: 10 }; }
1697
else if (obj.config.settings.autobackup === false) { delete obj.config.settings.autobackup; }
1698
1699
+ // Load Intel AMT passwords from the "amtactivation.log" file
1700
+ obj.loadAmtActivationLogPasswords(function (amtPasswords) {
1701
+ obj.amtPasswords = amtPasswords;
1702
+ });
1703
+
1704
// Setup users that can see all device groups
1705
if (typeof obj.config.settings.managealldevicegroups == 'string') { obj.config.settings.managealldevicegroups = obj.config.settings.managealldevicegroups.split(','); }
1706
else if (Array.isArray(obj.config.settings.managealldevicegroups) == false) { obj.config.settings.managealldevicegroups = []; }
@@ -2680,6 +2685,34 @@ function CreateMeshCentralServer(config, args) {
2685
});
2686
};
2687
2688
+ // Load the list of Intel AMT UUID and passwords from "amtactivation.log"
2689
+ obj.loadAmtActivationLogPasswords = function (func) {
2690
+ var amtlogfilename = obj.path.join(obj.datapath, 'amtactivation.log');
2691
+ obj.fs.readFile(amtlogfilename, 'utf8', function (err, data) {
2692
+ var amtPasswords = {}; // UUID --> [Passwords]
2693
+ if ((err == null) && (data != null)) {
2694
+ const lines = data.split('\r\n');
2695
+ for (var i in lines) {
2696
+ var line = lines[i];
2697
+ if (line.startsWith('{')) {
2698
+ var j = JSON.parse(line);
2699
+ if ((typeof j.amtUuid == 'string') && (typeof j.password == 'string')) {
2700
+ if (amtPasswords[j.amtUuid] == null) {
2701
+ amtPasswords[j.amtUuid] = [j.password]; // Add password to array
2702
+ } else {
2703
+ if (amtPasswords[j.amtUuid].indexOf(j.password) == -1) {
2704
+ amtPasswords[j.amtUuid].unshift(j.password); // Add password at the start of the array
2705
+ while (amtPasswords[j.amtUuid].length > 3) { amtPasswords[j.amtUuid].pop(); } // Only keep the 3 last passwords for any given device
2706
+ }
2707
+ }
2708
+ }
2709
+ }
2710
+ }
2711
+ }
2712
+ func(obj.common.sortObj(amtPasswords)); // Sort by UUID
2713
+ });
2714
+ }
2715
+
2716
// Generate a cryptographic key used to encode and decode cookies
2717
obj.generateCookieKey = function () {
2718
return Buffer.from(obj.crypto.randomBytes(80), 'binary');
meshuser.js
+9
-1
@@ -888,7 +888,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
888
889
switch (cmd) {
890
case 'help': {
891
- var fin = '', f = '', availcommands = 'help,maintenance,info,versions,resetserver,usersessions,closeusersessions,tasklimiter,setmaxtasks,cores,migrationagents,agentstats,agentissues,webstats,mpsstats,swarmstats,acceleratorsstats,updatecheck,serverupdate,nodeconfig,heapdump,relays,autobackup,backupconfig,dupagents,dispatchtable,badlogins,showpaths,le,lecheck,leevents,dbstats,dbcounters,sms,amtacm,certhashes,watchdog,amtmanager';
891
+ var fin = '', f = '', availcommands = 'help,maintenance,info,versions,resetserver,usersessions,closeusersessions,tasklimiter,setmaxtasks,cores,migrationagents,agentstats,agentissues,webstats,mpsstats,swarmstats,acceleratorsstats,updatecheck,serverupdate,nodeconfig,heapdump,relays,autobackup,backupconfig,dupagents,dispatchtable,badlogins,showpaths,le,lecheck,leevents,dbstats,dbcounters,sms,amtacm,certhashes,watchdog,amtmanager,amtpasswords';
892
if (parent.parent.config.settings.heapdump === true) { availcommands += ',heapdump'; }
893
availcommands = availcommands.split(',').sort();
894
while (availcommands.length > 0) { if (f.length > 80) { fin += (f + ',\r\n'); f = ''; } f += (((f != '') ? ', ' : ' ') + availcommands.shift()); }
@@ -1152,6 +1152,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1152
console.log(cmdargs['_'][0]);
1153
break;
1154
}
1155
+ case 'amtpasswords': {
1156
+ if (parent.parent.amtPasswords == null) {
1157
+ r = "No Intel AMT password table."
1158
+ } else {
1159
+ for (var i in parent.parent.amtPasswords) { r += (i + ' - ' + parent.parent.amtPasswords[i].join(', ') + '\r\n'); }
1160
+ }
1161
+ break;
1162
+ }
1163
case 'updatecheck': {
1164
parent.parent.getServerTags(function (tags, error) {
1165
var r2 = '';