-
Notifications
You must be signed in to change notification settings - Fork 586
/
meshaccelerator.js
66 lines (61 loc) · 2.16 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @description MeshCentral accelerator
* @author Ylian Saint-Hilaire
* @copyright Intel Corporation 2018-2022
* @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) { module.exports.processMessage(message); });
// Process an incoming message
module.exports.processMessage = 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 (ex) {
// If this exception happens, try again.
if (ex.code == 'ERR_OSSL_DSO_COULD_NOT_LOAD_THE_SHARED_LIBRARY') {
try {
const sign = crypto.createSign('SHA384');
sign.end(Buffer.from(message.data, 'binary'));
process.send(sign.sign(message.key).toString('binary'));
} catch (ex) {
process.send(null);
}
} else {
process.send(null);
}
}
break;
}
case 'setState': {
certStore = message.certs;
break;
}
case 'indexMcRec': {
//console.log('indexMcRec', message.data);
// Hold 5 seconds before starting to index
setTimeout(function () { require(require('path').join(__dirname, 'mcrec.js')).indexFile(message.data); }, 5000);
break;
}
default: {
console.log('Unknown accelerator action: ' + message.action + '.');
break;
}
}
}