Added CIRA timeout

Ylian Saint-Hilaire committed May 3, 2018 at 11:09 UTC 202f7c7e6af44eb93919c417c2f8c6c5949b4a3d
11 files changed +49 -34
amtscanner.js
+2 -2
@@ -24,8 +24,8 @@ module.exports.CreateAmtScanner = function (parent) {
24 obj.pendingSendTimer = null;
25 obj.mainTimer = null;
26 obj.nextTag = 0;
27 - var PeriodicScanTime = 30000; // Interval between scan sweeps
28 - var PeriodicScanTimeout = 65000; // After this time, timeout the device.
27 + const PeriodicScanTime = 30000; // Interval between scan sweeps
28 + const PeriodicScanTimeout = 65000; // After this time, timeout the device.
29
30 // Build a RMCP packet with a given tag field
31 obj.buildRmcpPing = function (tag) {
amtscript.js
+3 -3
@@ -10,16 +10,16 @@ module.exports.CreateAmtScriptEngine = function () {
10 var o = {};
11
12 // Core functions
13 - script_functionTable1 = ['nop', 'jump', 'set', 'print', 'dialog', 'getitem', 'substr', 'indexof', 'split', 'join', 'length', 'jsonparse', 'jsonstr', 'add', 'substract', 'parseint', 'wsbatchenum', 'wsput', 'wscreate', 'wsdelete', 'wsexec', 'scriptspeed', 'wssubscribe', 'wsunsubscribe', 'readchar', 'signwithdummyca'];
13 + const script_functionTable1 = ['nop', 'jump', 'set', 'print', 'dialog', 'getitem', 'substr', 'indexof', 'split', 'join', 'length', 'jsonparse', 'jsonstr', 'add', 'substract', 'parseint', 'wsbatchenum', 'wsput', 'wscreate', 'wsdelete', 'wsexec', 'scriptspeed', 'wssubscribe', 'wsunsubscribe', 'readchar', 'signwithdummyca'];
14
15 // functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
16 - script_functionTable2 = ['encodeuri', 'decodeuri', 'passwordcheck', 'atob', 'btoa', 'hex2str', 'str2hex', 'random', 'md5', 'maketoarray', 'readshort', 'readshortx', 'readint', 'readsint', 'readintx', 'shorttostr', 'shorttostrx', 'inttostr', 'inttostrx'];
16 + const script_functionTable2 = ['encodeuri', 'decodeuri', 'passwordcheck', 'atob', 'btoa', 'hex2str', 'str2hex', 'random', 'md5', 'maketoarray', 'readshort', 'readshortx', 'readint', 'readsint', 'readintx', 'shorttostr', 'shorttostrx', 'inttostr', 'inttostrx'];
17
18 // functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
19 //script_functionTableX2 = [encodeURI, decodeURI, passwordcheck, window.atob.bind(window), window.btoa.bind(window), hex2rstr, rstr2hex, random, rstr_md5, MakeToArray, ReadShort, ReadShortX, ReadInt, ReadSInt, ReadIntX, ShortToStr, ShortToStrX, IntToStr, IntToStrX];
20
21 // Optional functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
22 - script_functionTable3 = ['pullsystemstatus', 'pulleventlog', 'pullauditlog', 'pullcertificates', 'pullwatchdog', 'pullsystemdefense', 'pullhardware', 'pulluserinfo', 'pullremoteaccess', 'highlightblock', 'disconnect', 'getsidstring', 'getsidbytearray'];
22 + const script_functionTable3 = ['pullsystemstatus', 'pulleventlog', 'pullauditlog', 'pullcertificates', 'pullwatchdog', 'pullsystemdefense', 'pullhardware', 'pulluserinfo', 'pullremoteaccess', 'highlightblock', 'disconnect', 'getsidstring', 'getsidbytearray'];
23
24 /*
25 // Optional functions of type ARG1 = func(ARG2, ARG3, ARG4, ARG5, ARG6)
common.js
+1 -1
@@ -6,7 +6,7 @@
6 * @version v0.0.1
7 */
8
9 -var crypto = require('crypto');
9 +const crypto = require('crypto');
10
11 // Binary encoding and decoding functions
12 module.exports.ReadShort = function(v, p) { return (v.charCodeAt(p) << 8) + v.charCodeAt(p + 1); }
interceptor.js
+2 -2
@@ -6,8 +6,8 @@
6 * @version v0.0.3
7 */
8
9 -var crypto = require('crypto');
10 -var common = require('./common.js');
9 +const crypto = require('crypto');
10 +const common = require('./common.js');
11
12 var HttpInterceptorAuthentications = {};
13 var RedirInterceptorAuthentications = {};
meshagent.js
+1 -1
@@ -27,7 +27,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
27 obj.agentCoreCheck = 0;
28 obj.agentInfo;
29 obj.agentUpdate = null;
30 - var agentUpdateBlockSize = 65520;
30 + const agentUpdateBlockSize = 65520;
31 obj.remoteaddr = obj.ws._socket.remoteAddress;
32 obj.useSHA386 = false;
33 if (obj.remoteaddr.startsWith('::ffff:')) { obj.remoteaddr = obj.remoteaddr.substring(7); }
meshmail.js
+9 -9
@@ -17,19 +17,19 @@ module.exports.CreateMeshMain = function (parent) {
17 const nodemailer = require('nodemailer');
18
19 // Default account email validation mail
20 - var accountCheckSubject = '[[[SERVERNAME]]] - Email Verification';
21 - var accountCheckMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Verification</b></td></tr></table><p>Hi [[[USERNAME]]], <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting email verification, click on the following link to complete the process.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to verify your e-mail address.</a></p>If you did not initiate this request, please ignore this mail.</div>';
22 - var accountCheckMailText = '[[[SERVERNAME]]] - Verification\r\n\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is performing an e-mail verification. Nagivate to the following link to complete the process: [[[CALLBACKURL]]]\r\nIf you did not initiate this request, please ignore this mail.\r\n';
20 + const accountCheckSubject = '[[[SERVERNAME]]] - Email Verification';
21 + const accountCheckMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Verification</b></td></tr></table><p>Hi [[[USERNAME]]], <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting email verification, click on the following link to complete the process.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to verify your e-mail address.</a></p>If you did not initiate this request, please ignore this mail.</div>';
22 + const accountCheckMailText = '[[[SERVERNAME]]] - Verification\r\n\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is performing an e-mail verification. Nagivate to the following link to complete the process: [[[CALLBACKURL]]]\r\nIf you did not initiate this request, please ignore this mail.\r\n';
23
24 // Default account reset mail
25 - var accountResetSubject = '[[[SERVERNAME]]] - Account Reset';
26 - var accountResetMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Verification</b></td></tr></table><p>Hi [[[USERNAME]]], <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting an account password reset, click on the following link to complete the process.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to reset your account password.</a></p>If you did not initiate this request, please ignore this mail.</div>';
27 - var accountResetMailText = '[[[SERVERNAME]]] - Account Reset\r\n\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting an account password reset. Nagivate to the following link to complete the process: [[[CALLBACKURL]]]\r\nIf you did not initiate this request, please ignore this mail.\r\n';
25 + const accountResetSubject = '[[[SERVERNAME]]] - Account Reset';
26 + const accountResetMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Verification</b></td></tr></table><p>Hi [[[USERNAME]]], <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting an account password reset, click on the following link to complete the process.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to reset your account password.</a></p>If you did not initiate this request, please ignore this mail.</div>';
27 + const accountResetMailText = '[[[SERVERNAME]]] - Account Reset\r\n\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting an account password reset. Nagivate to the following link to complete the process: [[[CALLBACKURL]]]\r\nIf you did not initiate this request, please ignore this mail.\r\n';
28
29 // Default account invite mail
30 - var accountInviteSubject = '[[[SERVERNAME]]] - Agent Installation Invitation';
31 - var accountInviteMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Agent Installation</b></td></tr></table><p>User [[[USERNAME]]] on server <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting that you install a remote management agent. WARNING: this will allow the requester to <u>take control of your computer</u>. If you wish to do this, click on the following link to download the agent.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to download the MeshAgent for Windows.</a></p>If you did not know about this request, please ignore this mail.</div>';
32 - var accountInviteMailText = '[[[SERVERNAME]]] - Agent Installation Invitation\r\n\r\nUser [[[USERNAME]]] on server [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting you install a remote management agent. WARNING: This will allow the requester to take control of your computer. If you wish to do this, click on the following link to download the agent: [[[CALLBACKURL]]]\r\nIf you do not know about this request, please ignore this mail.\r\n';
30 + const accountInviteSubject = '[[[SERVERNAME]]] - Agent Installation Invitation';
31 + const accountInviteMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Agent Installation</b></td></tr></table><p>User [[[USERNAME]]] on server <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting that you install a remote management agent. WARNING: this will allow the requester to <u>take control of your computer</u>. If you wish to do this, click on the following link to download the agent.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to download the MeshAgent for Windows.</a></p>If you did not know about this request, please ignore this mail.</div>';
32 + const accountInviteMailText = '[[[SERVERNAME]]] - Agent Installation Invitation\r\n\r\nUser [[[USERNAME]]] on server [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting you install a remote management agent. WARNING: This will allow the requester to take control of your computer. If you wish to do this, click on the following link to download the agent: [[[CALLBACKURL]]]\r\nIf you do not know about this request, please ignore this mail.\r\n';
33
34 function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
35 function EscapeHtmlBreaks(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;').replace(/\r/g, '<br />').replace(/\n/g, '').replace(/\t/g, '&nbsp;&nbsp;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
meshscanner.js
+3 -3
@@ -16,9 +16,9 @@ module.exports.CreateMeshScanner = function (parent) {
16 obj.servers4 = {};
17 obj.servers6 = {};
18 obj.mainTimer = null;
19 - var periodicScanTime = (60000 * 20); // Interval between scans, 20 minutes.
20 - var membershipIPv4 = '239.255.255.235';
21 - var membershipIPv6 = 'FF02:0:0:0:0:0:0:FE';
19 + const periodicScanTime = (60000 * 20); // Interval between scans, 20 minutes.
20 + const membershipIPv4 = '239.255.255.235';
21 + const membershipIPv6 = 'FF02:0:0:0:0:0:0:FE';
22 obj.agentCertificateHashHex = parent.certificateOperations.forge.pki.getPublicKeyFingerprint(parent.certificateOperations.forge.pki.certificateFromPem(parent.certificates.agent.cert).publicKey, { md: parent.certificateOperations.forge.md.sha384.create(), encoding: 'hex' }).toUpperCase();
23 obj.error = 0;
24
mpsserver.js
+19 -4
@@ -14,9 +14,12 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
14 obj.args = args;
15 obj.certificates = certificates;
16 obj.ciraConnections = {};
17 - var common = require('./common.js');
18 - var net = require('net');
19 - var tls = require('tls');
17 + const common = require('./common.js');
18 + const net = require('net');
19 + const tls = require('tls');
20 +
21 + const MAX_IDLE = 90000; // 90 seconds max idle time, higher than the typical KEEP-ALIVE periode of 60 seconds
22 + const CHECK_INTERVAL = 30000; // 30 seconds check interval
23
24 if (obj.args.tlsoffload) {
25 obj.server = net.createServer(onConnection);
@@ -96,7 +99,15 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
99 }
100 socket.setEncoding('binary');
101 Debug(1, 'MPS:New CIRA connection');
99 -
102 +
103 + // Setup the CIRA keep alive timer
104 + socket.lastping = new Date().getTime(); // Get current time in milliseconds from epoch
105 + socket.timer = setInterval(function () {
106 + const now = new Date().getTime();
107 + Debug(3, "MPS:Check interval:" + (socket.lastping && (socket.lastping + MAX_IDLE) < now));
108 + if (socket.lastping && ((socket.lastping + MAX_IDLE) < now)) { Debug(1, "MPS:CIRA timeout, disconnecting."); try { socket.end(); } catch (e) { } }
109 + }, CHECK_INTERVAL);
110 +
111 socket.addListener("data", function (data) {
112 if (args.mpsdebug) { var buf = new Buffer(data, "binary"); console.log('MPS <-- (' + buf.length + '):' + buf.toString('hex')); } // Print out received bytes
113 socket.tag.accumulator += data;
@@ -167,6 +178,9 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
178 }
179
180 try {
181 + // Set the last time we received data on the CIRA channel
182 + socket.lastping = new Date().getTime();
183 +
184 // Parse all of the APF data we can
185 var l = 0;
186 do { l = ProcessCommand(socket); if (l > 0) { socket.tag.accumulator = socket.tag.accumulator.substring(l); } } while (l > 0);
@@ -530,6 +544,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
544
545 socket.addListener("close", function () {
546 Debug(1, 'MPS:CIRA connection closed');
547 + if (socket.timer) { try { clearInterval(socket.timer); } catch (e) { } socket.timer = null; }
548 try { delete obj.ciraConnections[socket.tag.nodeid]; } catch (e) { }
549 obj.parent.ClearConnectivityState(socket.tag.meshid, socket.tag.nodeid, 2);
550 });
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.1.7-g",
3 + "version": "0.1.7-h",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
pass.js
+3 -3
@@ -1,13 +1,13 @@
1 // check out https://github.com/tj/node-pwd
2
3 // Module dependencies.
4 -var crypto = require('crypto');
4 +const crypto = require('crypto');
5
6 // Bytesize.
7 -var len = 128;
7 +const len = 128;
8
9 // Iterations. ~300ms
10 -var iterations = 12000;
10 +const iterations = 12000;
11
12 /**
13 * Hashes a password with optional `salt`, otherwise
swarmserver.js
+5 -5
@@ -15,12 +15,12 @@ module.exports.CreateSwarmServer = function (parent, db, args, certificates) {
15 obj.certificates = certificates;
16 obj.legacyAgentConnections = {};
17 obj.migrationAgents = {};
18 - var common = require('./common.js');
19 - var net = require('net');
20 - var tls = require('tls');
21 - var forge = require('node-forge');
18 + const common = require('./common.js');
19 + const net = require('net');
20 + const tls = require('tls');
21 + const forge = require('node-forge');
22
23 - var LegacyMeshProtocol = {
23 + const LegacyMeshProtocol = {
24 NODEPUSH: 1, // Used to send a node block to another peer.
25 NODEPULL: 2, // Used to send a pull block to another peer.
26 NODENOTIFY: 3, // Used to indicate the node ID to other peers.