2018-01-10 07:13:41 +03:00
|
|
|
/**
|
|
|
|
* @description MeshCentral accelerator
|
|
|
|
* @author Ylian Saint-Hilaire
|
2019-01-04 03:22:15 +03:00
|
|
|
* @copyright Intel Corporation 2018-2019
|
2018-01-10 07:13:41 +03:00
|
|
|
* @license Apache-2.0
|
|
|
|
* @version v0.0.1
|
|
|
|
*/
|
|
|
|
|
2018-08-30 03:40:30 +03:00
|
|
|
/*xjslint node: true */
|
|
|
|
/*xjslint plusplus: true */
|
|
|
|
/*xjslint maxlen: 256 */
|
|
|
|
/*jshint node: true */
|
|
|
|
/*jshint strict: false */
|
|
|
|
/*jshint esversion: 6 */
|
|
|
|
"use strict";
|
2018-08-27 22:24:15 +03:00
|
|
|
|
2018-01-10 07:13:41 +03:00
|
|
|
const crypto = require('crypto');
|
|
|
|
var certStore = null;
|
|
|
|
|
2019-07-18 01:57:42 +03:00
|
|
|
// When the parent process terminates, we exit also.
|
|
|
|
process.on('disconnect', function () { process.exit(); });
|
|
|
|
|
|
|
|
// Handle parent messages
|
2018-01-10 07:13:41 +03:00
|
|
|
process.on('message', function (message) {
|
|
|
|
switch (message.action) {
|
|
|
|
case 'sign': {
|
|
|
|
if (typeof message.key == 'number') { message.key = certStore[message.key].key; }
|
|
|
|
try {
|
|
|
|
const sign = crypto.createSign('SHA384');
|
2019-01-03 05:03:34 +03:00
|
|
|
sign.end(Buffer.from(message.data, 'binary'));
|
2018-01-10 07:13:41 +03:00
|
|
|
process.send(sign.sign(message.key).toString('binary'));
|
|
|
|
} catch (e) { process.send(null); }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'setState': {
|
|
|
|
certStore = message.certs;
|
|
|
|
break;
|
|
|
|
}
|
2019-01-05 04:59:13 +03:00
|
|
|
default: {
|
|
|
|
console.log('Unknown accelerator action: ' + message.action + '.');
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 07:13:41 +03:00
|
|
|
}
|
|
|
|
});
|