Improved AmtConfig command in agent console.

Ylian Saint-Hilaire committed Apr 11, 2022 at 15:05 UTC 79c97af78bad180fd03bf54195c87d41c578a643
2 files changed +8 -29
agents/meshcore.js
+2 -29
@@ -4368,36 +4368,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4368 }
4369 case 'amtconfig': {
4370 if (amt == null) { response = 'Intel AMT not detected.'; break; }
4371 - if (apftunnel != null) { response = 'Intel AMT server tunnel already active'; break; }
4371 if (!obj.showamtevent) { obj.showamtevent = true; require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Enabled live view of Intel AMT configuration events, \"amtevents off\" to disable.' }); }
4373 - amt.getMeiState(15, function (state) {
4374 - if ((state == null) || (state.ProvisioningState == null)) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Intel AMT not ready for configuration.' }); } else {
4375 - getAmtOsDnsSuffix(state, function () {
4376 - var rx = '';
4377 - var apfarg = {
4378 - mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
4379 - mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
4380 - mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16).replace(/\+/g, '@').replace(/\//g, '$'),
4381 - mpskeepalive: 60000,
4382 - clientname: state.OsHostname,
4383 - clientaddress: '127.0.0.1',
4384 - clientuuid: state.UUID,
4385 - conntype: 2, // 0 = CIRA, 1 = Relay, 2 = LMS. The correct value is 2 since we are performing an LMS relay, other values for testing.
4386 - meiState: state // MEI state will be passed to MPS server
4387 - };
4388 - if ((state.UUID == null) || (state.UUID.length != 36)) {
4389 - rx = "Unable to get Intel AMT UUID";
4390 - } else {
4391 - addAmtEvent('User LMS tunnel start.');
4392 - apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
4393 - apftunnel.onJsonControl = handleApfJsonControl;
4394 - apftunnel.onChannelClosed = function () { addAmtEvent('User LMS tunnel closed.'); apftunnel = null; }
4395 - try { apftunnel.connect(); } catch (ex) { rx = JSON.stringify(ex); }
4396 - }
4397 - if (rx != '') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: rx }); }
4398 - });
4399 - }
4400 - });
4372 + if (apftunnel != null) { response = 'Intel AMT server tunnel already active'; break; }
4373 + require('MeshAgent').SendCommand({ action: 'amtconfig' }); // Request that the server give us a server authentication cookie to start the APF session.
4374 break;
4375 }
4376 case 'apf': {
meshagent.js
+6
@@ -1732,6 +1732,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1732 }
1733 break;
1734 }
1735 + case 'amtconfig': {
1736 + // Sent by the agent when the agent needs a Intel AMT APF connection to the server
1737 + const cookie = parent.parent.encodeCookie({ a: 'apf', n: obj.dbNodeKey, m: obj.dbMeshKey }, parent.parent.loginCookieEncryptionKey);
1738 + try { obj.send(JSON.stringify({ action: 'amtconfig', user: '**MeshAgentApfTunnel**', pass: cookie })); } catch (ex) { }
1739 + break;
1740 + }
1741 case 'scriptTask': {
1742 // TODO
1743 break;