diff --git a/src/cert/acme2.js b/src/cert/acme2.js index 0da4c2e13..f32ef8cef 100644 --- a/src/cert/acme2.js +++ b/src/cert/acme2.js @@ -586,34 +586,34 @@ Acme2.prototype.getDirectory = function (callback) { }); }; -Acme2.prototype.getCertificate = function (hostname, domain, callback) { - assert.strictEqual(typeof hostname, 'string'); +Acme2.prototype.getCertificate = function (vhost, domain, callback) { + assert.strictEqual(typeof vhost, 'string'); assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof callback, 'function'); - debug(`getCertificate: start acme flow for ${hostname} from ${this.caDirectory}`); + debug(`getCertificate: start acme flow for ${vhost} from ${this.caDirectory}`); - if (hostname !== domain && this.wildcard) { // bare domain is not part of wildcard SAN - hostname = domains.makeWildcard(hostname); - debug(`getCertificate: will get wildcard cert for ${hostname}`); + if (vhost !== domain && this.wildcard) { // bare domain is not part of wildcard SAN + vhost = domains.makeWildcard(vhost); + debug(`getCertificate: will get wildcard cert for ${vhost}`); } const that = this; this.getDirectory(function (error) { if (error) return callback(error); - that.acmeFlow(hostname, domain, function (error) { + that.acmeFlow(vhost, domain, function (error) { if (error) return callback(error); var outdir = paths.APP_CERTS_DIR; - const certName = hostname.replace('*.', '_.'); + const certName = vhost.replace('*.', '_.'); callback(null, path.join(outdir, `${certName}.cert`), path.join(outdir, `${certName}.key`)); }); }); }; -function getCertificate(hostname, domain, options, callback) { - assert.strictEqual(typeof hostname, 'string'); +function getCertificate(vhost, domain, options, callback) { + assert.strictEqual(typeof vhost, 'string'); // this can also be a wildcard domain (for alias domains) assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof options, 'object'); assert.strictEqual(typeof callback, 'function'); @@ -623,6 +623,6 @@ function getCertificate(hostname, domain, options, callback) { debug(`getCertificate: attempt ${attempt++}`); let acme = new Acme2(options || { }); - acme.getCertificate(hostname, domain, retryCallback); + acme.getCertificate(vhost, domain, retryCallback); }, callback); } diff --git a/src/domains.js b/src/domains.js index 060a275b2..a9065506f 100644 --- a/src/domains.js +++ b/src/domains.js @@ -455,10 +455,11 @@ function removeRestrictedFields(domain) { return result; } -function makeWildcard(hostname) { - assert.strictEqual(typeof hostname, 'string'); +function makeWildcard(vhost) { + assert.strictEqual(typeof vhost, 'string'); - let parts = hostname.split('.'); + // if the vhost is like *.example.com, this function will do nothing + let parts = vhost.split('.'); parts[0] = '*'; return parts.join('.'); } diff --git a/src/reverseproxy.js b/src/reverseproxy.js index d2463b41d..027a42050 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -257,22 +257,22 @@ function setAppCertificateSync(location, domainObject, certificate) { return null; } -function getAcmeCertificate(hostname, domainObject, callback) { - assert.strictEqual(typeof hostname, 'string'); +function getAcmeCertificate(vhost, domainObject, callback) { + assert.strictEqual(typeof vhost, 'string'); // this can contain wildcard domain (for alias domains) assert.strictEqual(typeof domainObject, 'object'); assert.strictEqual(typeof callback, 'function'); let certFilePath, keyFilePath; - if (hostname !== domainObject.domain && domainObject.tlsConfig.wildcard) { // bare domain is not part of wildcard SAN - let certName = domains.makeWildcard(hostname).replace('*.', '_.'); + if (vhost !== domainObject.domain && domainObject.tlsConfig.wildcard) { // bare domain is not part of wildcard SAN + let certName = domains.makeWildcard(vhost).replace('*.', '_.'); certFilePath = path.join(paths.APP_CERTS_DIR, `${certName}.cert`); keyFilePath = path.join(paths.APP_CERTS_DIR, `${certName}.key`); if (fs.existsSync(certFilePath) && fs.existsSync(keyFilePath)) return callback(null, { certFilePath, keyFilePath }); } else { - certFilePath = path.join(paths.APP_CERTS_DIR, `${hostname}.cert`); - keyFilePath = path.join(paths.APP_CERTS_DIR, `${hostname}.key`); + certFilePath = path.join(paths.APP_CERTS_DIR, `${vhost}.cert`); + keyFilePath = path.join(paths.APP_CERTS_DIR, `${vhost}.key`); if (fs.existsSync(certFilePath) && fs.existsSync(keyFilePath)) return callback(null, { certFilePath, keyFilePath }); }