AMT manager will now clear device credentials if they don't work.
Ylian Saint-Hilaire committed
Oct 7, 2020 at 12:30 UTC
7fc98cc80499578a506b1733d38acfc41077e652
2 files changed
+40
-3
amtmanager.js
+39
-2
@@ -88,8 +88,6 @@ module.exports.CreateAmtManager = function(parent) {
88
if (dev == null) { dev = obj.amtDevices[nodeid]; }
89
if (dev == null) return;
90
91
- //if (dev.host != '192.168.2.136') return;
92
-
91
if ((dev.acctry == null) && ((typeof dev.intelamt.user != 'string') || (typeof dev.intelamt.pass != 'string'))) {
92
if (obj.amtAdminAccounts.length > 0) { dev.acctry = 0; } else { return; }
93
}
@@ -155,6 +153,9 @@ module.exports.CreateAmtManager = function(parent) {
153
// Authentication error, see if we can use alternative credentials
154
if ((dev.acctry == null) && (obj.amtAdminAccounts.length > 0)) { dev.acctry = 0; attemptInitialContact(dev.nodeid, dev); return; }
155
if ((dev.acctry != null) && (obj.amtAdminAccounts.length > (dev.acctry + 1))) { dev.acctry++; attemptInitialContact(dev.nodeid, dev); return; }
156
+
157
+ // We are unable to authenticate to this device, clear Intel AMT credentials.
158
+ ClearDeviceCredentials(dev);
159
}
160
//console.log(dev.nodeid, dev.name, dev.host, status, 'Bad response');
161
removeDevice(dev.nodeid);
@@ -210,6 +211,42 @@ module.exports.CreateAmtManager = function(parent) {
211
});
212
}
213
214
+ // Change the current core information string and event it
215
+ function ClearDeviceCredentials(dev) {
216
+ if (obj.amtDevices[dev.nodeid] == null) return; // Device no longer exists, ignore this request.
217
+
218
+ // Check that the mesh exists
219
+ const mesh = parent.webserver.meshes[dev.meshid];
220
+ if (mesh == null) { removeDevice(dev.nodeid); return; }
221
+
222
+ // Get the node and change it if needed
223
+ parent.db.Get(dev.nodeid, function (err, nodes) {
224
+ if ((nodes == null) || (nodes.length != 1)) return;
225
+ const device = nodes[0];
226
+ var changes = [], change = 0, log = 0;
227
+ var domain = parent.config.domains[device.domain];
228
+ if (domain == null) return;
229
+
230
+ // Check if anything changes
231
+ if (device.intelamt == null) return;
232
+ if (device.intelamt.user != null) { change = 1; log = 1; delete device.intelamt.user; changes.push('AMT user'); }
233
+ if (device.intelamt.pass != null) { change = 1; log = 1; delete device.intelamt.pass; changes.push('AMT pass'); }
234
+
235
+ // If there are changes, event the new device
236
+ if (change == 1) {
237
+ // Save to the database
238
+ parent.db.Set(device);
239
+
240
+ // Event the node change
241
+ var event = { etype: 'node', action: 'changenode', nodeid: device._id, domain: domain.id, node: parent.webserver.CloneSafeNode(device) };
242
+ if (changes.length > 0) { event.msg = 'Changed device ' + device.name + ' from group ' + mesh.name + ': ' + changes.join(', '); }
243
+ if ((log == 0) || ((obj.agentInfo) && (obj.agentInfo.capabilities) && (obj.agentInfo.capabilities & 0x20)) || (changes.length == 0)) { event.nolog = 1; } // If this is a temporary device, don't log changes
244
+ if (parent.db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
245
+ parent.DispatchEvent(parent.webserver.CreateMeshDispatchTargets(device.meshid, [device._id]), obj, event);
246
+ }
247
+ });
248
+ }
249
+
250
function attemptFetchHardwareInventory(dev) {
251
if (obj.amtDevices[dev.nodeid] == null) return false; // Device no longer exists, ignore this request.
252
const mesh = parent.webserver.meshes[dev.meshid];
views/default.handlebars
+1
-1
@@ -2777,7 +2777,7 @@
2777
if (node.intelamt == null) node.intelamt = {};
2778
if (message.event.node.intelamt.state != null) { node.intelamt.state = message.event.node.intelamt.state; }
2779
if (message.event.node.intelamt.host != null) { node.intelamt.user = message.event.node.intelamt.host; }
2780
- if (message.event.node.intelamt.user != null) { node.intelamt.user = message.event.node.intelamt.user; }
2780
+ if (message.event.node.intelamt.user != null) { node.intelamt.user = message.event.node.intelamt.user; } else { delete node.intelamt.user; }
2781
if (message.event.node.intelamt.tls != null) { node.intelamt.tls = message.event.node.intelamt.tls; }
2782
if (message.event.node.intelamt.ver != null) { node.intelamt.ver = message.event.node.intelamt.ver; }
2783
if (message.event.node.intelamt.tag != null) { node.intelamt.tag = message.event.node.intelamt.tag; }