start moving openssl commands into openssl.js

This commit is contained in:
Girish Ramakrishnan
2026-01-17 13:38:17 +01:00
parent 3a1cd8f67f
commit efccf2729b
9 changed files with 404 additions and 326 deletions

View File

@@ -4,8 +4,6 @@ exports = module.exports = {
restart,
start,
generateDkimKey,
onDomainAdded,
onDomainRemoved,
@@ -25,7 +23,6 @@ exports = module.exports = {
const assert = require('node:assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
crypto = require('node:crypto'),
debug = require('debug')('box:mailserver'),
dns = require('./dns.js'),
docker = require('./docker.js'),
@@ -37,8 +34,6 @@ const assert = require('node:assert'),
Location = require('./location.js'),
locks = require('./locks.js'),
mail = require('./mail.js'),
os = require('node:os'),
path = require('node:path'),
paths = require('./paths.js'),
platform = require('./platform.js'),
reverseProxy = require('./reverseproxy.js'),
@@ -49,25 +44,6 @@ const assert = require('node:assert'),
tasks = require('./tasks.js'),
users = require('./users.js');
async function generateDkimKey() {
const publicKeyFilePath = path.join(os.tmpdir(), `dkim-${crypto.randomBytes(4).readUInt32LE(0)}.public`);
const privateKeyFilePath = path.join(os.tmpdir(), `dkim-${crypto.randomBytes(4).readUInt32LE(0)}.private`);
// https://www.unlocktheinbox.com/dkim-key-length-statistics/ and https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-authentication-dkim-easy.html for key size
await shell.spawn('openssl', ['genrsa', '-out', privateKeyFilePath, '1024'], {});
await shell.spawn('openssl', ['rsa', '-in', privateKeyFilePath, '-out', publicKeyFilePath, '-pubout', '-outform', 'PEM'], {});
const publicKey = safe.fs.readFileSync(publicKeyFilePath, 'utf8');
if (!publicKey) throw new BoxError(BoxError.FS_ERROR, safe.error.message);
safe.fs.unlinkSync(publicKeyFilePath);
const privateKey = safe.fs.readFileSync(privateKeyFilePath, 'utf8');
if (!privateKey) throw new BoxError(BoxError.FS_ERROR, safe.error.message);
safe.fs.unlinkSync(privateKeyFilePath);
return { publicKey, privateKey };
}
async function createMailConfig(mailFqdn) {
assert.strictEqual(typeof mailFqdn, 'string');