MeshCentral/meshaccelerator.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-01-09 23:13:41 -05:00
/**
* @description MeshCentral accelerator
* @author Ylian Saint-Hilaire
2021-01-09 17:31:09 -05:00
* @copyright Intel Corporation 2018-2021
2018-01-09 23:13:41 -05:00
* @license Apache-2.0
* @version v0.0.1
*/
2018-08-29 20:40:30 -04:00
/*xjslint node: true */
/*xjslint plusplus: true */
/*xjslint maxlen: 256 */
/*jshint node: true */
/*jshint strict: false */
/*jshint esversion: 6 */
"use strict";
2018-08-27 15:24:15 -04:00
2018-01-09 23:13:41 -05:00
const crypto = require('crypto');
var certStore = null;
2019-07-17 18:57:42 -04:00
// When the parent process terminates, we exit also.
process.on('disconnect', function () { process.exit(); });
// Handle parent messages
process.on('message', function (message) { module.exports.processMessage(message); });
// Process an incoming message
module.exports.processMessage = function(message) {
2018-01-09 23:13:41 -05:00
switch (message.action) {
case 'sign': {
if (typeof message.key == 'number') { message.key = certStore[message.key].key; }
try {
const sign = crypto.createSign('SHA384');
sign.end(Buffer.from(message.data, 'binary'));
2018-01-09 23:13:41 -05:00
process.send(sign.sign(message.key).toString('binary'));
} catch (e) { process.send(null); }
break;
}
case 'setState': {
certStore = message.certs;
break;
}
case 'indexMcRec': {
//console.log('indexMcRec', message.data);
2021-06-22 11:29:46 -04:00
// Hold 5 seconds before starting to index
setTimeout(function () { require(require('path').join(__dirname, 'mcrec.js')).indexFile(message.data); }, 5000);
break;
}
2019-01-04 20:59:13 -05:00
default: {
console.log('Unknown accelerator action: ' + message.action + '.');
break;
}
2018-01-09 23:13:41 -05:00
}
}