mail: move dkim keys into the database

This commit is contained in:
Girish Ramakrishnan
2021-10-11 19:51:29 -07:00
parent a63e04359c
commit dc8ec9dcd8
7 changed files with 108 additions and 85 deletions
+3 -1
View File
@@ -147,6 +147,8 @@ async function add(domain, data, auditSource) {
let error = validateTlsConfig(tlsConfig, provider);
if (error) throw error;
const dkimKey = await mail.generateDkimKey();
if (!dkimSelector) {
// create a unique suffix. this lets one add this domain can be added in another cloudron instance and not have their dkim selector conflict
const suffix = crypto.createHash('sha256').update(settings.dashboardDomain()).digest('hex').substr(0, 6);
@@ -159,7 +161,7 @@ async function add(domain, data, auditSource) {
let queries = [
{ query: 'INSERT INTO domains (domain, zoneName, provider, configJson, tlsConfigJson, fallbackCertificateJson) VALUES (?, ?, ?, ?, ?, ?)',
args: [ domain, zoneName, provider, JSON.stringify(result.sanitizedConfig), JSON.stringify(tlsConfig), JSON.stringify(fallbackCertificate) ] },
{ query: 'INSERT INTO mail (domain, dkimSelector) VALUES (?, ?)', args: [ domain, dkimSelector || 'cloudron' ] },
{ query: 'INSERT INTO mail (domain, dkimKeyJson, dkimSelector) VALUES (?, ?, ?)', args: [ domain, JSON.stringify(dkimKey), dkimSelector || 'cloudron' ] },
];
[error] = await safe(database.transaction(queries));