reverseproxy: add setUserCertificate

This commit is contained in:
Girish Ramakrishnan
2022-07-14 13:25:41 +05:30
parent d33fd7b886
commit 885d60f7cc
2 changed files with 20 additions and 14 deletions

View File

@@ -1,13 +1,14 @@
'use strict';
exports = module.exports = {
setFallbackCertificate,
setUserCertificate, // per location certificate
setFallbackCertificate, // per domain certificate
generateFallbackCertificate,
validateCertificate,
getCertificatePath,
getCertificatePath, // resolved cert path
ensureCertificate,
checkCerts,
@@ -540,20 +541,25 @@ async function writeAppConfigs(app) {
.concat(app.aliasDomains.map(ad => { return { domain: ad.domain, certificate: ad.certificate, fqdn: ad.fqdn, type: apps.LOCATION_TYPE_ALIAS }; }));
for (const appDomain of appDomains) {
const { certFilePath, keyFilePath } = getUserCertificatePathSync(appDomain.fqdn);
if (appDomain.certificate !== null) {
if (!safe.fs.writeFileSync(certFilePath, appDomain.certificate.cert)) throw safe.error;
if (!safe.fs.writeFileSync(keyFilePath, appDomain.certificate.key)) throw safe.error;
} else { // remove existing cert/key
if (!safe.fs.unlinkSync(certFilePath)) debug(`Error removing cert: ${safe.error.message}`);
if (!safe.fs.unlinkSync(keyFilePath)) debug(`Error removing key: ${safe.error.message}`);
}
const certificatePath = await getCertificatePath(appDomain.fqdn, appDomain.domain);
await writeAppNginxConfig(app, appDomain.fqdn, appDomain.type, certificatePath);
}
}
async function setUserCertificate(app, fqdn, certificate) {
const { certFilePath, keyFilePath } = getUserCertificatePathSync(fqdn);
if (certificate !== null) {
if (!safe.fs.writeFileSync(certFilePath, certificate.cert)) throw safe.error;
if (!safe.fs.writeFileSync(keyFilePath, certificate.key)) throw safe.error;
} else { // remove existing cert/key
if (!safe.fs.unlinkSync(certFilePath)) debug(`Error removing cert: ${safe.error.message}`);
if (!safe.fs.unlinkSync(keyFilePath)) debug(`Error removing key: ${safe.error.message}`);
}
await writeAppConfigs(app);
}
async function configureApp(app, auditSource) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof auditSource, 'object');