speed up dhparam creation

This commit is contained in:
Girish Ramakrishnan
2021-11-16 09:53:12 -08:00
parent 48574ce350
commit f6356b2dff

View File

@@ -71,9 +71,10 @@ async function initSecrets() {
// TODO maybe skip this in tests if possible again
let dhparams = await get(exports.DHPARAMS);
if (!dhparams) {
debug('initSecrets: generating dhparams.pem. this takes forever');
debug('initSecrets: generating dhparams.pem');
if (constants.TEST) dhparams = safe.fs.readFileSync('/tmp/dhparams.pem');
if (!dhparams) dhparams = safe.child_process.execSync('openssl dhparam 2048');
// https://security.stackexchange.com/questions/95178/diffie-hellman-parameters-still-calculating-after-24-hours
if (!dhparams) dhparams = safe.child_process.execSync('openssl dhparam -dsaparam 2048');
if (!dhparams) throw new BoxError(BoxError.OPENSSL_ERROR, safe.error);
if (constants.TEST) safe.fs.writeFileSync('/tmp/dhparams.pem', dhparams);
if (!safe.fs.writeFileSync(paths.DHPARAMS_FILE, dhparams)) throw new BoxError(BoxError.FS_ERROR, `Could not save dhparams.pem: ${safe.error.message}`);