Fixed utf8 in meshcore.
This commit is contained in:
parent
924d62c940
commit
cd85c66a1d
|
@ -224,7 +224,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||||
if (obj.authenticated == 2) {
|
if (obj.authenticated == 2) {
|
||||||
// Send the updated core.
|
// Send the updated core.
|
||||||
delete obj.agentCoreUpdatePending;
|
delete obj.agentCoreUpdatePending;
|
||||||
obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + argument.hash + argument.core, function () { parent.parent.taskLimiter.completed(taskid); }); // MeshCommand_CoreModule, start core update
|
obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + argument.hash + argument.core.toString('binary'), function () { parent.parent.taskLimiter.completed(taskid); }); // MeshCommand_CoreModule, start core update
|
||||||
parent.agentStats.updatingCoreCount++;
|
parent.agentStats.updatingCoreCount++;
|
||||||
parent.parent.debug('agent', "Updating core " + argument.name);
|
parent.parent.debug('agent', "Updating core " + argument.name);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2479,7 +2479,8 @@ function CreateMeshCentralServer(config, args) {
|
||||||
if (modulesDir[i].toLowerCase().endsWith('.json')) {
|
if (modulesDir[i].toLowerCase().endsWith('.json')) {
|
||||||
var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 5);
|
var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 5);
|
||||||
if (moduleName.endsWith('.min')) { moduleName = moduleName.substring(0, moduleName.length - 6); } // Remove the ".min" for ".min.json" files.
|
if (moduleName.endsWith('.min')) { moduleName = moduleName.substring(0, moduleName.length - 6); } // Remove the ".min" for ".min.json" files.
|
||||||
var moduleData = ['var ', moduleName, ' = JSON.parse("', obj.escapeCodeString(obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('utf8')), '");\r\n'];
|
var d = obj.fs.readFileSync(obj.path.join(moduleDirPath, modulesDir[i])).toString('utf8').split('\'').join('\\\'');
|
||||||
|
var moduleData = ['var ', moduleName, ' = JSON.parse(\'', d, '\');\r\n'];
|
||||||
|
|
||||||
// Add to all cores
|
// Add to all cores
|
||||||
modulesAdd['windows-amt'].push(...moduleData);
|
modulesAdd['windows-amt'].push(...moduleData);
|
||||||
|
@ -2546,15 +2547,17 @@ function CreateMeshCentralServer(config, args) {
|
||||||
} else {
|
} else {
|
||||||
obj.defaultMeshCores[i] = [obj.common.IntToStr(0), ...modulesAdd[i], meshCore].join('');
|
obj.defaultMeshCores[i] = [obj.common.IntToStr(0), ...modulesAdd[i], meshCore].join('');
|
||||||
}
|
}
|
||||||
|
obj.defaultMeshCores[i] = Buffer.from(obj.defaultMeshCores[i], 'utf8');
|
||||||
obj.defaultMeshCoresHash[i] = obj.crypto.createHash('sha384').update(obj.defaultMeshCores[i]).digest('binary');
|
obj.defaultMeshCoresHash[i] = obj.crypto.createHash('sha384').update(obj.defaultMeshCores[i]).digest('binary');
|
||||||
obj.debug('main', 'Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.');
|
obj.debug('main', 'Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.');
|
||||||
|
|
||||||
//console.log('Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.'); // DEBUG, Print the core size
|
//console.log('Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.'); // DEBUG, Print the core size
|
||||||
//obj.fs.writeFile("C:\\temp\\" + i + ".js", obj.defaultMeshCores[i].substring(4), function () { }); // DEBUG, Write the core to file
|
//obj.fs.writeFile("C:\\temp\\" + i + ".js", obj.defaultMeshCores[i].slice(4), function () { }); // DEBUG, Write the core to file
|
||||||
|
|
||||||
// Compress the mesh cores with DEFLATE
|
// Compress the mesh cores with DEFLATE
|
||||||
var callback = function MeshCoreDeflateCb(err, buffer) { if (err == null) { obj.defaultMeshCoresDeflate[MeshCoreDeflateCb.i] = buffer; } }
|
var callback = function MeshCoreDeflateCb(err, buffer) { if (err == null) { obj.defaultMeshCoresDeflate[MeshCoreDeflateCb.i] = buffer; } }
|
||||||
callback.i = i;
|
callback.i = i;
|
||||||
require('zlib').deflate(obj.defaultMeshCores[i], { level: require('zlib').Z_BEST_COMPRESSION }, callback);
|
require('zlib').deflate(obj.defaultMeshCores[i], { level: require('zlib').Z_BEST_COMPRESSION }, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6902,8 +6902,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
|
||||||
agent.send(obj.common.ShortToStr(11) + obj.common.ShortToStr(0)); // Command 11, ask for mesh core hash.
|
agent.send(obj.common.ShortToStr(11) + obj.common.ShortToStr(0)); // Command 11, ask for mesh core hash.
|
||||||
} else if (coretype == 'custom') {
|
} else if (coretype == 'custom') {
|
||||||
agent.agentCoreCheck = 1000; // Tell the agent object we are using a custom core.
|
agent.agentCoreCheck = 1000; // Tell the agent object we are using a custom core.
|
||||||
const hash = obj.crypto.createHash('sha384').update(Buffer.from(coredata, 'binary')).digest().toString('binary'); // Perform a SHA384 hash on the core module
|
var buf = Buffer.from(coredata, 'utf8');
|
||||||
agent.sendBinary(obj.common.ShortToStr(10) + obj.common.ShortToStr(0) + hash + coredata); // Send the code module to the agent
|
const hash = obj.crypto.createHash('sha384').update(buf).digest().toString('binary'); // Perform a SHA384 hash on the core module
|
||||||
|
agent.sendBinary(obj.common.ShortToStr(10) + obj.common.ShortToStr(0) + hash + buf.toString('binary')); // Send the code module to the agent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue