From 50684bb44754e0a5e5d7da3704f9d13dfa2b320a Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 26 Feb 2019 15:49:44 -0800 Subject: [PATCH] Fix for Node 11.10 deprecation of require('constants'). --- amtscanner.js | 4 ++-- mpsserver.js | 2 +- webserver.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/amtscanner.js b/amtscanner.js index e2eb52a1..3af0ea53 100644 --- a/amtscanner.js +++ b/amtscanner.js @@ -21,7 +21,6 @@ module.exports.CreateAmtScanner = function (parent) { obj.net = require('net'); obj.tls = require('tls'); obj.dns = require('dns'); - obj.constants = require('constants'); obj.dgram = require('dgram'); obj.common = require('./common.js'); obj.servers = {}; @@ -36,6 +35,7 @@ module.exports.CreateAmtScanner = function (parent) { obj.nextTag = 0; const PeriodicScanTime = 30000; // Interval between scan sweeps const PeriodicScanTimeout = 65000; // After this time, timeout the device. + const constants = (require('crypto').constants ? require('crypto').constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead. // Build a RMCP packet with a given tag field obj.buildRmcpPing = function (tag) { @@ -371,7 +371,7 @@ module.exports.CreateAmtScanner = function (parent) { } else { // Connect using TLS, we will switch from default TLS to TLS1-only and back if we get a connection error to support older Intel AMT. if (scaninfo.tlsoption == null) { scaninfo.tlsoption = 0; } - client = obj.tls.connect(port, host, scaninfo.tlsoption == 1 ? { secureProtocol: 'TLSv1_method', rejectUnauthorized: false, ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: obj.constants.SSL_OP_NO_SSLv2 | obj.constants.SSL_OP_NO_SSLv3 | obj.constants.SSL_OP_NO_COMPRESSION | obj.constants.SSL_OP_CIPHER_SERVER_PREFERENCE } : { rejectUnauthorized: false, ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: obj.constants.SSL_OP_NO_SSLv2 | obj.constants.SSL_OP_NO_SSLv3 | obj.constants.SSL_OP_NO_COMPRESSION | obj.constants.SSL_OP_CIPHER_SERVER_PREFERENCE }, function () { this.write('GET / HTTP/1.1\r\nhost: ' + host + '\r\n\r\n'); }); + client = obj.tls.connect(port, host, scaninfo.tlsoption == 1 ? { secureProtocol: 'TLSv1_method', rejectUnauthorized: false, ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE } : { rejectUnauthorized: false, ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE }, function () { this.write('GET / HTTP/1.1\r\nhost: ' + host + '\r\n\r\n'); }); } client.scaninfo = scaninfo; client.func = func; diff --git a/mpsserver.js b/mpsserver.js index a56f785f..cd2b721c 100644 --- a/mpsserver.js +++ b/mpsserver.js @@ -23,7 +23,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) { obj.ciraConnections = {}; var tlsSessionStore = {}; // Store TLS session information for quick resume. var tlsSessionStoreCount = 0; // Number of cached TLS session information in store. - const constants = require('constants'); + const constants = (require('crypto').constants ? require('crypto').constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead. const common = require("./common.js"); const net = require("net"); const tls = require("tls"); diff --git a/webserver.js b/webserver.js index 85dfd4c1..72b5f2a0 100644 --- a/webserver.js +++ b/webserver.js @@ -59,7 +59,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { obj.meshRelayHandler = require('./meshrelay.js'); obj.meshUserHandler = require('./meshuser.js'); obj.interceptor = require('./interceptor'); - const constants = require('constants'); + const constants = (obj.crypto.constants ? obj.crypto.constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead. // Variables obj.parent = parent;