Improved AMT ACM activation using MeshAgent.
Ylian Saint-Hilaire committed
Mar 5, 2021 at 17:45 UTC
c9757d904c05e2059b9448f6927e848962415f5e
4 files changed
+23
-40
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/meshcore.js
+21
-38
@@ -1187,29 +1187,7 @@ function handleServerCommand(data) {
1187
};
1188
addAmtEvent('LMS tunnel start.');
1189
apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
1190
- apftunnel.onJsonControl = function (data) {
1191
- if (data.action == 'console') { addAmtEvent(data.msg); } // Add console message to AMT event log
1192
- if (data.action == 'mestate') { amt.getMeiState(15, function (state) { apftunnel.updateMeiState(state); }); } // Update the MEI state
1193
- if (data.action == 'deactivate') { // Request CCM deactivation
1194
- var amtMeiModule, amtMei;
1195
- try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { if (apftunnel) apftunnel.sendMeiDeactivationState(1); return; }
1196
- amtMei.on('error', function (e) { if (apftunnel) apftunnel.sendMeiDeactivationState(1); });
1197
- amtMei.unprovision(1, function (status) { if (apftunnel) apftunnel.sendMeiDeactivationState(status); }); // 0 = Success
1198
- }
1199
- if (data.action == 'close') { try { apftunnel.disconnect(); } catch (e) { } apftunnel = null; } // Close the CIRA-LMS connection
1200
- if (data.action == 'startTlsHostConfig') { // Request start of host based TLS ACM activation
1201
- var amtMeiModule, amtMei;
1202
- try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { if (apftunnel) apftunnel.sendMeiDeactivationState(1); return; }
1203
- amtMei.on('error', function (e) { if (apftunnel) apftunnel.sendStartTlsHostConfigResponse({ state: -104 }); });
1204
- amtMei.startConfigurationHBased(Buffer.from(data.hash, 'hex'), data.hostVpn, data.dnsSuffixList, function (response) { apftunnel.sendStartTlsHostConfigResponse(response); });
1205
- }
1206
- if (data.action == 'stopConfiguration') { // Request Intel AMT stop configuration.
1207
- var amtMeiModule, amtMei;
1208
- try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { if (apftunnel) apftunnel.sendMeiDeactivationState(1); return; }
1209
- amtMei.on('error', function (e) { if (apftunnel) apftunnel.sendStopConfigurationResponse({ state: -104 }); });
1210
- amtMei.stopConfiguration(function (status) { apftunnel.sendStopConfigurationResponse(status); });
1211
- }
1212
- }
1190
+ apftunnel.onJsonControl = handleApfJsonControl;
1191
apftunnel.onChannelClosed = function () { addAmtEvent('LMS tunnel closed.'); apftunnel = null; }
1192
try { apftunnel.connect(); } catch (ex) { }
1193
});
@@ -1279,6 +1257,24 @@ function handleServerCommand(data) {
1257
}
1258
}
1259
1260
+// Handle APF JSON control commands
1261
+function handleApfJsonControl(data) {
1262
+ if (data.action == 'console') { addAmtEvent(data.msg); } // Add console message to AMT event log
1263
+ if (data.action == 'mestate') { amt.getMeiState(15, function (state) { apftunnel.updateMeiState(state); }); } // Update the MEI state
1264
+ if (data.action == 'close') { try { apftunnel.disconnect(); } catch (e) { } apftunnel = null; } // Close the CIRA-LMS connection
1265
+ if (amt.amtMei != null) {
1266
+ if (data.action == 'deactivate') { // Request CCM deactivation
1267
+ amt.amtMei.unprovision(1, function (status) { if (apftunnel) apftunnel.sendMeiDeactivationState(status); }); // 0 = Success
1268
+ }
1269
+ if (data.action == 'startTlsHostConfig') { // Request start of host based TLS ACM activation
1270
+ amt.amtMei.startConfigurationHBased(Buffer.from(data.hash, 'hex'), data.hostVpn, data.dnsSuffixList, function (response) { apftunnel.sendStartTlsHostConfigResponse(response); });
1271
+ }
1272
+ if (data.action == 'stopConfiguration') { // Request Intel AMT stop configuration.
1273
+ amt.amtMei.stopConfiguration(function (status) { apftunnel.sendStopConfigurationResponse(status); });
1274
+ }
1275
+ }
1276
+}
1277
+
1278
// Agent just get a file from the server and save it locally.
1279
function serverFetchFile() {
1280
if ((Object.keys(agentFileHttpRequests).length > 4) || (agentFileHttpPendingRequests.length == 0)) return; // No more than 4 active HTTPS requests to the server.
@@ -3769,17 +3765,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3765
} else {
3766
addAmtEvent('User LMS tunnel start.');
3767
apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
3772
- apftunnel.onJsonControl = function (data) {
3773
- if (data.action == 'console') { addAmtEvent(data.msg); require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: data.msg }); } // Display a console message
3774
- if (data.action == 'mestate') { amt.getMeiState(15, function (state) { apftunnel.updateMeiState(state); }); } // Update the MEI state
3775
- if (data.action == 'deactivate') { // Request CCM deactivation
3776
- var amtMeiModule, amtMei;
3777
- try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { apftunnel.sendMeiDeactivationState(1); return; }
3778
- amtMei.on('error', function (e) { apftunnel.sendMeiDeactivationState(1); });
3779
- amtMei.unprovision(1, function (status) { apftunnel.sendMeiDeactivationState(status); }); // 0 = Success
3780
- }
3781
- if (data.action == 'close') { try { apftunnel.disconnect(); } catch (e) { } apftunnel = null; } // Close the CIRA-LMS connection
3782
- }
3768
+ apftunnel.onJsonControl = handleApfJsonControl;
3769
apftunnel.onChannelClosed = function () { addAmtEvent('User LMS tunnel closed.'); apftunnel = null; }
3770
try {
3771
apftunnel.connect();
@@ -3816,10 +3802,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3802
response = "Unable to get Intel AMT UUID: " + apfarg.clientuuid;
3803
} else {
3804
apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
3819
- apftunnel.onJsonControl = function (data) {
3820
- if (data.action == 'console') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: data.msg }); }
3821
- if (data.action == 'close') { try { apftunnel.disconnect(); } catch (e) { } apftunnel = null; }
3822
- }
3805
+ apftunnel.onJsonControl = handleApfJsonControl;
3806
apftunnel.onChannelClosed = function () { apftunnel = null; }
3807
try {
3808
apftunnel.connect();
agents/modules_meshcore/amt-manage.js
+2
-2
@@ -58,11 +58,11 @@ function AmtManager(agent, db, isdebug) {
58
var rebindToMeiRetrys = 0;
59
obj.reset = function () {
60
++rebindToMeiRetrys;
61
- amtMei = null, amtMeiState = 0, amtLms = null, amtLmsState = 0, obj.state = 0, obj.lmsstate = 0;
61
+ obj.amtMei = null, amtMei = null, amtMeiState = 0, amtLms = null, amtLmsState = 0, obj.state = 0, obj.lmsstate = 0;
62
//debug('Binding to MEI');
63
try {
64
var amtMeiLib = require('amt-mei');
65
- amtMei = new amtMeiLib();
65
+ obj.amtMei = amtMei = new amtMeiLib();
66
amtMei.on('error', function (e) { debug('MEI error'); amtMei = null; amtMeiState = -1; obj.state = -1; if (obj.onStateChange != null) { obj.onStateChange(amtMeiState); } });
67
amtMei.getVersion(function (result) {
68
if (result == null) {