forked from Ylianst/MeshCentral
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeshaccelerator.js
44 lines (40 loc) · 1.2 KB
/
meshaccelerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @description MeshCentral accelerator
* @author Ylian Saint-Hilaire
* @copyright Intel Corporation 2018-2019
* @license Apache-2.0
* @version v0.0.1
*/
/*xjslint node: true */
/*xjslint plusplus: true */
/*xjslint maxlen: 256 */
/*jshint node: true */
/*jshint strict: false */
/*jshint esversion: 6 */
"use strict";
const crypto = require('crypto');
var certStore = null;
// When the parent process terminates, we exit also.
process.on('disconnect', function () { process.exit(); });
// Handle parent messages
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');
sign.end(Buffer.from(message.data, 'binary'));
process.send(sign.sign(message.key).toString('binary'));
} catch (e) { process.send(null); }
break;
}
case 'setState': {
certStore = message.certs;
break;
}
default: {
console.log('Unknown accelerator action: ' + message.action + '.');
break;
}
}
});