From f93e71dadae80c32ac3cdebb91d2836ca771c4b3 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 23 Sep 2020 00:18:17 -0700 Subject: [PATCH] Replaced unsupported randomint() --- certoperations.js | 4 ++-- common.js | 2 +- multiserver.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/certoperations.js b/certoperations.js index 6a0e920e..5c490b00 100644 --- a/certoperations.js +++ b/certoperations.js @@ -307,7 +307,7 @@ module.exports.CertificateOperations = function (parent) { var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 }); var cert = obj.pki.createCertificate(); cert.publicKey = keys.publicKey; - cert.serialNumber = require('crypto').randomInt(1, 100000); + cert.serialNumber = require('crypto').randomBytes(4).readUInt32BE(0); cert.validity.notBefore = new Date(2018, 0, 1); cert.validity.notAfter = new Date(2049, 11, 31); if (addThumbPrintToName === true) { commonName += '-' + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); } @@ -329,7 +329,7 @@ module.exports.CertificateOperations = function (parent) { var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 }); var cert = obj.pki.createCertificate(); cert.publicKey = keys.publicKey; - cert.serialNumber = require('crypto').randomInt(1, 100000); + cert.serialNumber = require('crypto').randomBytes(4).readUInt32BE(0); cert.validity.notBefore = new Date(2018, 0, 1); cert.validity.notAfter = new Date(2049, 11, 31); if (addThumbPrintToName === true) { commonName += "-" + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); } diff --git a/common.js b/common.js index 376be61a..13e08826 100644 --- a/common.js +++ b/common.js @@ -96,7 +96,7 @@ module.exports.data2blob = function (data) { }; // Generate random numbers -module.exports.random = function (max) { require('crypto').randomInt(0, max); }; +module.exports.random = function (max) { (require('crypto').randomBytes(4).readUInt32BE(0) % max); }; // Split a comma seperated string, ignoring commas in quotes. module.exports.quoteSplit = function (str) { diff --git a/multiserver.js b/multiserver.js index 1857ece6..9aa653ed 100644 --- a/multiserver.js +++ b/multiserver.js @@ -172,7 +172,7 @@ module.exports.CreateMultiServer = function (parent, args) { // Get the next retry time in milliseconds function getConnectRetryTime() { - if (obj.retryBackoff < 30000) { obj.retryBackoff += require('crypto').randomInt(1000, 4000); } + if (obj.retryBackoff < 30000) { obj.retryBackoff += ((require('crypto').randomBytes(4).readUInt32BE(0) % 3000) + 1000); } return obj.retryBackoff; }