Updated Windows MeshAgents + UTF8 string encoding fixes.
Ylian Saint-Hilaire committed
Aug 9, 2019 at 15:13 UTC
bb4bc55c480b7163973c710eb2daed14b3354edb
9 files changed
+38
-38
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/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshcore.min.js
+4
-5
@@ -709,16 +709,14 @@ function createMeshCore(agent)
709
} catch (e) { }
710
break;
711
}
712
- /*
712
case 'serviceRestart': {
714
- // Start a service
713
+ // Restart a service
714
try {
715
var service = require('service-manager').manager.getService(data.serviceName);
717
- if (service != null) { service.stop(); service.start(); }
716
+ if (service != null) { service.restart(); }
717
} catch (e) { }
718
break;
719
}
721
- */
720
case 'openUrl': {
721
// Open a local web browser and return success/fail
722
MeshServerLog('Opening: ' + data.url, data);
@@ -1826,8 +1824,9 @@ function createMeshCore(agent)
1824
break;
1825
}
1826
case 'sysinfo': { // Return system information
1829
- var results = { hardware: require('identifiers').get(), pendingReboot: require('win-info').pendingReboot() }; // Hardware && pending reboot
1827
+ var results = { hardware: require('identifiers').get() }; // Hardware && pending reboot
1828
if (process.platform == 'win32') {
1829
+ results.pendingReboot = require('win-info').pendingReboot();
1830
var defragResult = function (r) {
1831
if (typeof r == 'object') { results[this.callname] = r; }
1832
if (this.callname == 'defrag') {
meshagent.js
+33
-32
@@ -39,7 +39,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
39
//obj.agentInfo = null;
40
41
// Send a message to the mesh agent
42
- obj.send = function (data, func) { try { if (typeof data == 'string') { ws.send(Buffer.from(data, 'binary'), func); } else { ws.send(data, func); } } catch (e) { } };
42
+ obj.send = function (data, func) { try { if (typeof data == 'string') { ws.send(Buffer.from(data), func); } else { ws.send(data, func); } } catch (e) { } };
43
+ obj.sendBinary = function (data, func) { try { if (typeof data == 'string') { ws.send(Buffer.from(data, 'binary'), func); } else { ws.send(data, func); } } catch (e) { } };
44
45
// Disconnect this agent
46
obj.close = function (arg) {
@@ -125,7 +126,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
126
127
// If we are using a custom core, don't try to update it.
128
if (obj.agentCoreCheck == 1000) {
128
- obj.send(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
129
+ obj.sendBinary(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
130
agentCoreIsStable();
131
return;
132
}
@@ -136,7 +137,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
137
// If the agent indicates this is a custom core, we are done.
138
if ((agentMeshCoreHash != null) && (agentMeshCoreHash == '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0')) {
139
obj.agentCoreCheck = 0;
139
- obj.send(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
140
+ obj.sendBinary(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
141
agentCoreIsStable();
142
return;
143
}
@@ -163,12 +164,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
164
if ((obj.agentCoreCheck < 5) || (obj.agentCoreCheck == 1001)) {
165
if (meshcorehash == null) {
166
// Clear the core
166
- obj.send(common.ShortToStr(10) + common.ShortToStr(0)); // MeshCommand_CoreModule, ask mesh agent to clear the core
167
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0)); // MeshCommand_CoreModule, ask mesh agent to clear the core
168
parent.agentStats.clearingCoreCount++;
169
parent.parent.debug(1, 'Clearing core');
170
} else {
171
// Update new core
171
- //obj.send(common.ShortToStr(10) + common.ShortToStr(0) + meshcorehash + parent.parent.defaultMeshCores[corename]); // MeshCommand_CoreModule, start core update
172
+ //obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + meshcorehash + parent.parent.defaultMeshCores[corename]); // MeshCommand_CoreModule, start core update
173
//parent.parent.debug(1, 'Updating code ' + corename);
174
175
// Update new core with task limiting so not to flood the server. This is a high priority task.
@@ -177,7 +178,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
178
if (obj.authenticated == 2) {
179
// Send the updated code.
180
delete obj.agentCoreUpdatePending;
180
- obj.send(common.ShortToStr(10) + common.ShortToStr(0) + argument.hash + argument.core, function () { parent.parent.taskLimiter.completed(taskid); }); // MeshCommand_CoreModule, start core update
181
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + argument.hash + argument.core, function () { parent.parent.taskLimiter.completed(taskid); }); // MeshCommand_CoreModule, start core update
182
parent.agentStats.updatingCoreCount++;
183
parent.parent.debug(1, 'Updating core ' + argument.name);
184
agentCoreIsStable();
@@ -191,7 +192,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
192
}
193
} else {
194
obj.agentCoreCheck = 0;
194
- obj.send(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
195
+ obj.sendBinary(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
196
agentCoreIsStable(); // No updates needed, agent is ready to go.
197
}
198
}
@@ -204,13 +205,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
205
if (obj.agentCoreCheck < 5) { // This check is in place to avoid a looping core update.
206
if (parent.parent.defaultMeshCoreHash == null) {
207
// Update no core
207
- obj.send(common.ShortToStr(10) + common.ShortToStr(0)); // Command 10, ask mesh agent to clear the core
208
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0)); // Command 10, ask mesh agent to clear the core
209
} else {
210
// Update new core
211
if (parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].amt == true) {
211
- obj.send(common.ShortToStr(10) + common.ShortToStr(0) + parent.parent.defaultMeshCoreHash + parent.parent.defaultMeshCore); // Command 10, ask mesh agent to set the core (with MEI support)
212
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + parent.parent.defaultMeshCoreHash + parent.parent.defaultMeshCore); // Command 10, ask mesh agent to set the core (with MEI support)
213
} else {
213
- obj.send(common.ShortToStr(10) + common.ShortToStr(0) + parent.parent.defaultMeshCoreNoMeiHash + parent.parent.defaultMeshCoreNoMei); // Command 10, ask mesh agent to set the core (No MEI)
214
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + parent.parent.defaultMeshCoreNoMeiHash + parent.parent.defaultMeshCoreNoMei); // Command 10, ask mesh agent to set the core (No MEI)
215
}
216
}
217
obj.agentCoreCheck++;
@@ -238,11 +239,11 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
239
240
// MeshCommand_CoreModule, ask mesh agent to clear the core.
241
// The new core will only be sent after the agent updates.
241
- obj.send(common.ShortToStr(10) + common.ShortToStr(0));
242
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
243
244
// We got the agent file open on the server side, tell the agent we are sending an update starting with the SHA384 hash of the result
245
//console.log("Agent update file open.");
245
- obj.send(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
246
+ obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
247
248
// Send the first mesh agent update data block
249
obj.agentUpdate.buf[0] = 0;
@@ -260,7 +261,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
261
// Send the first block to the agent
262
obj.agentUpdate.ptr += bytesRead;
263
//console.log("Agent update send first block: " + bytesRead);
263
- obj.send(obj.agentUpdate.buf); // Command 14, mesh agent first data block
264
+ obj.sendBinary(obj.agentUpdate.buf); // Command 14, mesh agent first data block
265
}
266
});
267
});
@@ -270,10 +271,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
271
272
// MeshCommand_CoreModule, ask mesh agent to clear the core.
273
// The new core will only be sent after the agent updates.
273
- obj.send(common.ShortToStr(10) + common.ShortToStr(0));
274
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
275
276
// We got the agent file open on the server side, tell the agent we are sending an update starting with the SHA384 hash of the result
276
- obj.send(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
277
+ obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
278
279
// Send the first mesh agent update data block
280
obj.agentUpdate.buf[0] = 0;
@@ -286,7 +287,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
287
// Send the first block
288
obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
289
obj.agentUpdate.ptr += len;
289
- obj.send(obj.agentUpdate.buf); // Command 14, mesh agent first data block
290
+ obj.sendBinary(obj.agentUpdate.buf); // Command 14, mesh agent first data block
291
} else {
292
// Error
293
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
@@ -299,7 +300,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
300
} else {
301
// Check the mesh core, if the agent is capable of running one
302
if (((obj.agentInfo.capabilities & 16) != 0) && (parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core != null)) {
302
- obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash.
303
+ obj.sendBinary(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash.
304
}
305
}
306
}
@@ -322,10 +323,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
323
// Send the next block to the agent
324
obj.agentUpdate.ptr += bytesRead;
325
//console.log("Agent update send next block", obj.agentUpdate.ptr, bytesRead);
325
- if (bytesRead == agentUpdateBlockSize) { obj.send(obj.agentUpdate.buf); } else { obj.send(obj.agentUpdate.buf.slice(0, bytesRead + 4)); } // Command 14, mesh agent next data block
326
+ if (bytesRead == agentUpdateBlockSize) { obj.sendBinary(obj.agentUpdate.buf); } else { obj.sendBinary(obj.agentUpdate.buf.slice(0, bytesRead + 4)); } // Command 14, mesh agent next data block
327
if (bytesRead < agentUpdateBlockSize) {
328
//console.log("Agent update sent from disk.");
328
- obj.send(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
329
+ obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
330
try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { }
331
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
332
delete obj.agentUpdate.buf;
@@ -338,13 +339,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
339
const len = Math.min(agentUpdateBlockSize, obj.agentExeInfo.data.length - obj.agentUpdate.ptr);
340
if (len > 0) {
341
obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
341
- if (len == agentUpdateBlockSize) { obj.send(obj.agentUpdate.buf); } else { obj.send(obj.agentUpdate.buf.slice(0, len + 4)); } // Command 14, mesh agent next data block
342
+ if (len == agentUpdateBlockSize) { obj.sendBinary(obj.agentUpdate.buf); } else { obj.sendBinary(obj.agentUpdate.buf.slice(0, len + 4)); } // Command 14, mesh agent next data block
343
obj.agentUpdate.ptr += len;
344
}
345
346
if (obj.agentUpdate.ptr == obj.agentExeInfo.data.length) {
347
//console.log("Agent update sent from RAM.");
347
- obj.send(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
348
+ obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
349
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
350
delete obj.agentUpdate.buf;
351
delete obj.agentUpdate;
@@ -367,7 +368,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
368
369
if (args.ignoreagenthashcheck === true) {
370
// Send the agent web hash back to the agent
370
- obj.send(common.ShortToStr(1) + msg.substring(2, 50) + obj.nonce); // Command 1, hash + nonce. Use the web hash given by the agent.
371
+ obj.sendBinary(common.ShortToStr(1) + msg.substring(2, 50) + obj.nonce); // Command 1, hash + nonce. Use the web hash given by the agent.
372
} else {
373
// Check that the server hash matches our own web certificate hash (SHA384)
374
if ((getWebCertHash(domain) != msg.substring(2, 50)) && (getWebCertFullHash(domain) != msg.substring(2, 50))) {
@@ -388,13 +389,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
389
// Perform the hash signature using older swarm server certificate
390
parent.parent.certificateOperations.acceleratorPerformSignature(1, msg.substring(2) + obj.nonce, obj, function (obj2, signature) {
391
// Send back our certificate + signature
391
- obj2.send(common.ShortToStr(2) + common.ShortToStr(parent.swarmCertificateAsn1.length) + parent.swarmCertificateAsn1 + signature); // Command 2, certificate + signature
392
+ obj2.sendBinary(common.ShortToStr(2) + common.ShortToStr(parent.swarmCertificateAsn1.length) + parent.swarmCertificateAsn1 + signature); // Command 2, certificate + signature
393
});
394
} else {
395
// Perform the hash signature using the server agent certificate
396
parent.parent.certificateOperations.acceleratorPerformSignature(0, msg.substring(2) + obj.nonce, obj, function (obj2, signature) {
397
// Send back our certificate + signature
397
- obj2.send(common.ShortToStr(2) + common.ShortToStr(parent.agentCertificateAsn1.length) + parent.agentCertificateAsn1 + signature); // Command 2, certificate + signature
398
+ obj2.sendBinary(common.ShortToStr(2) + common.ShortToStr(parent.agentCertificateAsn1.length) + parent.agentCertificateAsn1 + signature); // Command 2, certificate + signature
399
});
400
}
401
}
@@ -485,7 +486,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
486
// Start authenticate the mesh agent by sending a auth nonce & server TLS cert hash.
487
// Send 384 bits SHA384 hash of TLS cert public key + 384 bits nonce
488
if (args.ignoreagenthashcheck !== true) {
488
- obj.send(common.ShortToStr(1) + getWebCertHash(domain) + obj.nonce); // Command 1, hash + nonce
489
+ obj.sendBinary(common.ShortToStr(1) + getWebCertHash(domain) + obj.nonce); // Command 1, hash + nonce
490
}
491
492
// Return the mesh for this device, in some cases, we may auto-create the mesh.
@@ -556,10 +557,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
557
// Inform mesh agent that it's authenticated.
558
delete obj.pendingCompleteAgentConnection;
559
obj.authenticated = 2;
559
- obj.send(common.ShortToStr(4));
560
+ obj.sendBinary(common.ShortToStr(4));
561
562
// Ask for mesh core hash.
562
- obj.send(common.ShortToStr(11) + common.ShortToStr(0));
563
+ obj.sendBinary(common.ShortToStr(11) + common.ShortToStr(0));
564
return;
565
}
566
@@ -784,11 +785,11 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
785
}
786
787
// Command 4, inform mesh agent that it's authenticated.
787
- obj.send(common.ShortToStr(4));
788
+ obj.sendBinary(common.ShortToStr(4));
789
790
if (disconnectCount > 4) {
791
// Too many disconnections, this agent has issues. Just clear the core.
791
- obj.send(common.ShortToStr(10) + common.ShortToStr(0));
792
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
793
//console.log('Agent in trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
794
// TODO: Log or do something to recover?
795
return;
@@ -804,16 +805,16 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
805
corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
806
} else {
807
// MeshCommand_CoreModule, ask mesh agent to clear the core
807
- obj.send(common.ShortToStr(10) + common.ShortToStr(0));
808
+ obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
809
}
810
811
if ((obj.agentExeInfo != null) && (obj.agentExeInfo.update == true)) {
812
// Ask the agent for it's executable binary hash
812
- obj.send(common.ShortToStr(12) + common.ShortToStr(0));
813
+ obj.sendBinary(common.ShortToStr(12) + common.ShortToStr(0));
814
} else {
815
// Check the mesh core, if the agent is capable of running one
816
if (((obj.agentInfo.capabilities & 16) != 0) && (corename != null)) {
816
- obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash.
817
+ obj.sendBinary(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash.
818
} else {
819
agentCoreIsStable(); // No updates needed, agent is ready to go.
820
}
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.3.9-n",
3
+ "version": "0.3.9-o",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",