Fixed AMT DNS suffix on non-Win32 agents.

This commit is contained in:
Ylian Saint-Hilaire 2021-07-24 10:56:53 -07:00
parent 7766e1ca07
commit e9e24e13dc

View File

@ -1236,22 +1236,24 @@ function handleServerCommand(data) {
if ((apftunnel != null) || (amt == null)) return; if ((apftunnel != null) || (amt == null)) return;
if ((state == null) || (state.ProvisioningState == null)) return; if ((state == null) || (state.ProvisioningState == null)) return;
if ((state.UUID == null) || (state.UUID.length != 36)) return; // Bad UUID if ((state.UUID == null) || (state.UUID.length != 36)) return; // Bad UUID
var apfarg = { getAmtOsDnsSuffix(state, function () {
mpsurl: mesh.ServerUrl.replace('/agent.ashx', '/apf.ashx'), var apfarg = {
mpsuser: data.user, // Agent user name mpsurl: mesh.ServerUrl.replace('/agent.ashx', '/apf.ashx'),
mpspass: data.pass, // Encrypted login cookie mpsuser: data.user, // Agent user name
mpskeepalive: 60000, mpspass: data.pass, // Encrypted login cookie
clientname: state.OsHostname, mpskeepalive: 60000,
clientaddress: '127.0.0.1', clientname: state.OsHostname,
clientuuid: state.UUID, clientaddress: '127.0.0.1',
conntype: 2, // 0 = CIRA, 1 = Relay, 2 = LMS. The correct value is 2 since we are performing an LMS relay, other values for testing. clientuuid: state.UUID,
meiState: state // MEI state will be passed to MPS server conntype: 2, // 0 = CIRA, 1 = Relay, 2 = LMS. The correct value is 2 since we are performing an LMS relay, other values for testing.
}; meiState: state // MEI state will be passed to MPS server
addAmtEvent('LMS tunnel start.'); };
apftunnel = require('amt-apfclient')({ debug: false }, apfarg); addAmtEvent('LMS tunnel start.');
apftunnel.onJsonControl = handleApfJsonControl; apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
apftunnel.onChannelClosed = function () { addAmtEvent('LMS tunnel closed.'); apftunnel = null; } apftunnel.onJsonControl = handleApfJsonControl;
try { apftunnel.connect(); } catch (ex) { } apftunnel.onChannelClosed = function () { addAmtEvent('LMS tunnel closed.'); apftunnel = null; }
try { apftunnel.connect(); } catch (ex) { }
});
}); });
break; break;
} }
@ -1337,6 +1339,19 @@ function handleServerCommand(data) {
} }
} }
// On non-Windows platforms, we need to query the DHCP server for the DNS suffix
function getAmtOsDnsSuffix(mestate, func) {
if ((process.platform == 'win32') || (mestate.net0 == null) || (mestate.net0.mac == null)) { func(mestate); return; }
try { require('linux-dhcp') } catch (ex) { func(mestate); return; }
require('linux-dhcp').client.info(mestate.net0.mac).then(function (d) {
if ((typeof d.options == 'object') && (typeof d.options.domainname == 'string')) { mestate.OsDnsSuffix = d.options.domainname; }
func(mestate);
}, function (e) {
console.log('DHCP error', e);
func(mestate);
});
}
// Download a file from the server and check the hash. // Download a file from the server and check the hash.
// This download is similar to the one used for meshcore self-update. // This download is similar to the one used for meshcore self-update.
var trustedDownloads = {}; var trustedDownloads = {};
@ -3956,35 +3971,37 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
if (amt == null) { response = "Intel AMT not detected."; break; } if (amt == null) { response = "Intel AMT not detected."; break; }
if (apftunnel != null) { response = "Intel AMT server tunnel already active"; break; } if (apftunnel != null) { response = "Intel AMT server tunnel already active"; break; }
amt.getMeiState(15, function (state) { amt.getMeiState(15, function (state) {
var rx = ''; if ((state == null) || (state.ProvisioningState == null)) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "Intel AMT not ready for configuration." }); } else {
if ((state == null) || (state.ProvisioningState == null)) { rx = "Intel AMT not ready for configuration."; } else { getAmtOsDnsSuffix(state, function () {
var apfarg = { var rx = '';
mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'), var apfarg = {
mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16), mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16), mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
mpskeepalive: 60000, mpspass: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
clientname: state.OsHostname, mpskeepalive: 60000,
clientaddress: '127.0.0.1', clientname: state.OsHostname,
clientuuid: state.UUID, clientaddress: '127.0.0.1',
conntype: 2, // 0 = CIRA, 1 = Relay, 2 = LMS. The correct value is 2 since we are performing an LMS relay, other values for testing. clientuuid: state.UUID,
meiState: state // MEI state will be passed to MPS server conntype: 2, // 0 = CIRA, 1 = Relay, 2 = LMS. The correct value is 2 since we are performing an LMS relay, other values for testing.
}; meiState: state // MEI state will be passed to MPS server
if ((state.UUID == null) || (state.UUID.length != 36)) { };
rx = "Unable to get Intel AMT UUID"; if ((state.UUID == null) || (state.UUID.length != 36)) {
} else { rx = "Unable to get Intel AMT UUID";
addAmtEvent('User LMS tunnel start.'); } else {
apftunnel = require('amt-apfclient')({ debug: false }, apfarg); addAmtEvent('User LMS tunnel start.');
apftunnel.onJsonControl = handleApfJsonControl; apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
apftunnel.onChannelClosed = function () { addAmtEvent('User LMS tunnel closed.'); apftunnel = null; } apftunnel.onJsonControl = handleApfJsonControl;
try { apftunnel.onChannelClosed = function () { addAmtEvent('User LMS tunnel closed.'); apftunnel = null; }
apftunnel.connect(); try {
rx = "Started Intel AMT configuration"; apftunnel.connect();
} catch (ex) { rx = "Started Intel AMT configuration";
rx = JSON.stringify(ex); } catch (ex) {
rx = JSON.stringify(ex);
}
} }
} if (rx != '') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: rx }); }
});
} }
if (rx != '') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: rx }); }
}); });
break; break;
} }