EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
meshaccelerator.js
Go to the documentation of this file.
1/**
2* @description MeshCentral accelerator
3* @author Ylian Saint-Hilaire
4* @copyright Intel Corporation 2018-2022
5* @license Apache-2.0
6* @version v0.0.1
7*/
8
9/*xjslint node: true */
10/*xjslint plusplus: true */
11/*xjslint maxlen: 256 */
12/*jshint node: true */
13/*jshint strict: false */
14/*jshint esversion: 6 */
15"use strict";
16
17const crypto = require('crypto');
18var certStore = null;
19
20// When the parent process terminates, we exit also.
21process.on('disconnect', function () { process.exit(); });
22
23// Handle parent messages
24process.on('message', function (message) { module.exports.processMessage(message); });
25
26// Process an incoming message
27module.exports.processMessage = function(message) {
28 switch (message.action) {
29 case 'sign': {
30 if (typeof message.key == 'number') { message.key = certStore[message.key].key; }
31 try {
32 const sign = crypto.createSign('SHA384');
33 sign.end(Buffer.from(message.data, 'binary'));
34 process.send(sign.sign(message.key).toString('binary'));
35 } catch (ex) {
36 // If this exception happens, try again.
37 if (ex.code == 'ERR_OSSL_DSO_COULD_NOT_LOAD_THE_SHARED_LIBRARY') {
38 try {
39 const sign = crypto.createSign('SHA384');
40 sign.end(Buffer.from(message.data, 'binary'));
41 process.send(sign.sign(message.key).toString('binary'));
42 } catch (ex) {
43 process.send(null);
44 }
45 } else {
46 process.send(null);
47 }
48 }
49 break;
50 }
51 case 'setState': {
52 certStore = message.certs;
53 break;
54 }
55 case 'indexMcRec': {
56 //console.log('indexMcRec', message.data);
57 // Hold 5 seconds before starting to index
58 setTimeout(function () { require(require('path').join(__dirname, 'mcrec.js')).indexFile(message.data); }, 5000);
59 break;
60 }
61 default: {
62 console.log('Unknown accelerator action: ' + message.action + '.');
63 break;
64 }
65 }
66}