Added websocket per-message deflate support.
Ylian Saint-Hilaire committed
Jul 9, 2020 at 16:40 UTC
fa3ae55074e9d2c0fe7362bed692bf8a6a4ef740
4 files changed
+7
-5
meshcentral-config-schema.json
+1
@@ -55,6 +55,7 @@
55
"agentPong": { "type": "integer", "minimum": 1, "description": "When specified, sends data to the agent at x seconds interval." },
56
"agentIdleTimeout": { "type": "integer", "minimum": 1 },
57
"compression": { "type": "boolean", "default": true, "description": "Enables GZIP compression for web requests." },
58
+ "wscompression": { "type": "boolean", "default": false, "description": "Enables websocket per-message deflate compression." },
59
"meshErrorLogPath": { "type": "string" },
60
"npmPath": { "type": "string" },
61
"npmProxy": { "type": "string", "format": "uri" },
meshcentral.js
+1
-1
@@ -2595,7 +2595,7 @@ function mainStart() {
2595
if (config.domains[i].mstsc === true) { mstsc = true; }
2596
if ((typeof config.domains[i].authstrategies == 'object')) {
2597
if (passport == null) { passport = ['passport']; }
2598
- if ((typeof config.domains[i].authstrategies.twitter == 'object') && (typeof config.domains[i].authstrategies.twitter.apikey == 'string') && (typeof config.domains[i].authstrategies.twitter.apisecret == 'string') && (passport.indexOf('passport-twitter') == -1)) { passport.push('passport-twitter'); }
2598
+ if ((typeof config.domains[i].authstrategies.twitter == 'object') && (typeof config.domains[i].authstrategies.twitter.clientid == 'string') && (typeof config.domains[i].authstrategies.twitter.clientsecret == 'string') && (passport.indexOf('passport-twitter') == -1)) { passport.push('passport-twitter'); }
2599
if ((typeof config.domains[i].authstrategies.google == 'object') && (typeof config.domains[i].authstrategies.google.clientid == 'string') && (typeof config.domains[i].authstrategies.google.clientsecret == 'string') && (passport.indexOf('passport-google-oauth20') == -1)) { passport.push('passport-google-oauth20'); }
2600
if ((typeof config.domains[i].authstrategies.github == 'object') && (typeof config.domains[i].authstrategies.github.clientid == 'string') && (typeof config.domains[i].authstrategies.github.clientsecret == 'string') && (passport.indexOf('passport-github2') == -1)) { passport.push('passport-github2'); }
2601
if ((typeof config.domains[i].authstrategies.reddit == 'object') && (typeof config.domains[i].authstrategies.reddit.clientid == 'string') && (typeof config.domains[i].authstrategies.reddit.clientsecret == 'string') && (passport.indexOf('passport-reddit') == -1)) { passport.push('passport-reddit'); }
package.json
+1
@@ -43,6 +43,7 @@
43
"multiparty": "^4.2.1",
44
"nedb": "^1.8.0",
45
"node-forge": "^0.8.4",
46
+ "permessage-deflate": "^0.1.7",
47
"ws": "^6.2.1",
48
"xmldom": "^0.1.27",
49
"yauzl": "^2.10.0"
webserver.js
+4
-4
@@ -4303,7 +4303,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4303
// Start the server, only after users and meshes are loaded from the database.
4304
if (obj.args.notls || obj.args.tlsoffload) {
4305
// Setup the HTTP server without TLS
4306
- obj.expressWs = require('express-ws')(obj.app);
4306
+ obj.expressWs = require('express-ws')(obj.app, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4307
} else {
4308
// Setup the HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4309
//const tlsOptions = { cert: obj.certificates.web.cert, key: obj.certificates.web.key, ca: obj.certificates.web.ca, rejectUnauthorized: true, ciphers: "HIGH:!aNULL:!eNULL:!EXPORT:!RSA:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA", secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE | constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1 }; // This does not work with TLS 1.3
@@ -4315,7 +4315,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4315
//obj.tlsServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4316
obj.tlsServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4317
obj.tlsServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4318
- obj.expressWs = require('express-ws')(obj.app, obj.tlsServer);
4318
+ obj.expressWs = require('express-ws')(obj.app, obj.tlsServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4319
}
4320
4321
// Start a second agent-only server if needed
@@ -4328,7 +4328,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4328
4329
if (agentPortTls == false) {
4330
// Setup the HTTP server without TLS
4331
- obj.expressWsAlt = require('express-ws')(obj.agentapp);
4331
+ obj.expressWsAlt = require('express-ws')(obj.agentapp, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4332
} else {
4333
// Setup the agent HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4334
// If TLS is used on the agent port, we always use the default TLS certificate.
@@ -4339,7 +4339,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4339
//obj.tlsAltServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4340
obj.tlsAltServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4341
obj.tlsAltServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4342
- obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer);
4342
+ obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4343
}
4344
}
4345