Replaced unsupported randomint()

Ylian Saint-Hilaire committed Sep 23, 2020 at 00:18 UTC 08e075b4b3b9185cbc33479d471819339c574cf4
3 files changed +4 -4
certoperations.js
+2 -2
@@ -307,7 +307,7 @@ module.exports.CertificateOperations = function (parent) {
307 var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 });
308 var cert = obj.pki.createCertificate();
309 cert.publicKey = keys.publicKey;
310 - cert.serialNumber = require('crypto').randomInt(1, 100000);
310 + cert.serialNumber = require('crypto').randomBytes(4).readUInt32BE(0);
311 cert.validity.notBefore = new Date(2018, 0, 1);
312 cert.validity.notAfter = new Date(2049, 11, 31);
313 if (addThumbPrintToName === true) { commonName += '-' + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); }
@@ -329,7 +329,7 @@ module.exports.CertificateOperations = function (parent) {
329 var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 });
330 var cert = obj.pki.createCertificate();
331 cert.publicKey = keys.publicKey;
332 - cert.serialNumber = require('crypto').randomInt(1, 100000);
332 + cert.serialNumber = require('crypto').randomBytes(4).readUInt32BE(0);
333 cert.validity.notBefore = new Date(2018, 0, 1);
334 cert.validity.notAfter = new Date(2049, 11, 31);
335 if (addThumbPrintToName === true) { commonName += "-" + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); }
common.js
+1 -1
@@ -96,7 +96,7 @@ module.exports.data2blob = function (data) {
96 };
97
98 // Generate random numbers
99 -module.exports.random = function (max) { require('crypto').randomInt(0, max); };
99 +module.exports.random = function (max) { (require('crypto').randomBytes(4).readUInt32BE(0) % max); };
100
101 // Split a comma seperated string, ignoring commas in quotes.
102 module.exports.quoteSplit = function (str) {
multiserver.js
+1 -1
@@ -172,7 +172,7 @@ module.exports.CreateMultiServer = function (parent, args) {
172
173 // Get the next retry time in milliseconds
174 function getConnectRetryTime() {
175 - if (obj.retryBackoff < 30000) { obj.retryBackoff += require('crypto').randomInt(1000, 4000); }
175 + if (obj.retryBackoff < 30000) { obj.retryBackoff += ((require('crypto').randomBytes(4).readUInt32BE(0) % 3000) + 1000); }
176 return obj.retryBackoff;
177 }
178