|
|
@ -209,6 +209,7 @@ const internalCertificate = {
|
|
|
|
.patchAndFetchById(certificate.id, {
|
|
|
|
.patchAndFetchById(certificate.id, {
|
|
|
|
expires_on: moment(cert_info.dates.to, 'X').format('YYYY-MM-DD HH:mm:ss')
|
|
|
|
expires_on: moment(cert_info.dates.to, 'X').format('YYYY-MM-DD HH:mm:ss')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(utils.omitRow(omissions()))
|
|
|
|
.then((saved_row) => {
|
|
|
|
.then((saved_row) => {
|
|
|
|
// Add cert data for audit log
|
|
|
|
// Add cert data for audit log
|
|
|
|
saved_row.meta = _.assign({}, saved_row.meta, {
|
|
|
|
saved_row.meta = _.assign({}, saved_row.meta, {
|
|
|
@ -732,29 +733,29 @@ const internalCertificate = {
|
|
|
|
|
|
|
|
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -subject -noout')
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -subject -noout')
|
|
|
|
.then((result) => {
|
|
|
|
.then((result) => {
|
|
|
|
|
|
|
|
// Examples:
|
|
|
|
|
|
|
|
// subject=CN = *.jc21.com
|
|
|
|
// subject=CN = something.example.com
|
|
|
|
// subject=CN = something.example.com
|
|
|
|
const regex = /(?:subject=)?[^=]+=\s+(\S+)/gim;
|
|
|
|
const regex = /(?:subject=)?[^=]+=\s+(\S+)/gim;
|
|
|
|
const match = regex.exec(result);
|
|
|
|
const match = regex.exec(result);
|
|
|
|
|
|
|
|
if (match && typeof match[1] !== 'undefined') {
|
|
|
|
if (typeof match[1] === 'undefined') {
|
|
|
|
|
|
|
|
throw new error.ValidationError('Could not determine subject from certificate: ' + result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
certData['cn'] = match[1];
|
|
|
|
certData['cn'] = match[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -issuer -noout');
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -issuer -noout');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
.then((result) => {
|
|
|
|
.then((result) => {
|
|
|
|
|
|
|
|
// Examples:
|
|
|
|
// issuer=C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
|
|
|
|
// issuer=C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
|
|
|
|
|
|
|
|
// issuer=C = US, O = Let's Encrypt, CN = E5
|
|
|
|
|
|
|
|
// issuer=O = NginxProxyManager, CN = NginxProxyManager Intermediate CA","O = NginxProxyManager, CN = NginxProxyManager Intermediate CA
|
|
|
|
const regex = /^(?:issuer=)?(.*)$/gim;
|
|
|
|
const regex = /^(?:issuer=)?(.*)$/gim;
|
|
|
|
const match = regex.exec(result);
|
|
|
|
const match = regex.exec(result);
|
|
|
|
|
|
|
|
if (match && typeof match[1] !== 'undefined') {
|
|
|
|
if (typeof match[1] === 'undefined') {
|
|
|
|
|
|
|
|
throw new error.ValidationError('Could not determine issuer from certificate: ' + result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
certData['issuer'] = match[1];
|
|
|
|
certData['issuer'] = match[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -dates -noout');
|
|
|
|
return utils.exec('openssl x509 -in ' + certificate_file + ' -dates -noout');
|
|
|
@ -829,18 +830,18 @@ const internalCertificate = {
|
|
|
|
requestLetsEncryptSsl: (certificate) => {
|
|
|
|
requestLetsEncryptSsl: (certificate) => {
|
|
|
|
logger.info('Requesting Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
logger.info('Requesting Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
|
|
|
|
|
|
|
|
const cmd = certbotCommand + ' certonly ' +
|
|
|
|
const cmd = `${certbotCommand} certonly ` +
|
|
|
|
'--config "' + letsencryptConfig + '" ' +
|
|
|
|
`--config '${letsencryptConfig}' ` +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--cert-name "npm-' + certificate.id + '" ' +
|
|
|
|
`--cert-name "npm-${certificate.id}" ` +
|
|
|
|
'--agree-tos ' +
|
|
|
|
'--agree-tos ' +
|
|
|
|
'--authenticator webroot ' +
|
|
|
|
'--authenticator webroot ' +
|
|
|
|
'--email "' + certificate.meta.letsencrypt_email + '" ' +
|
|
|
|
`--email '${certificate.meta.letsencrypt_email}' ` +
|
|
|
|
'--preferred-challenges "dns,http" ' +
|
|
|
|
'--preferred-challenges "dns,http" ' +
|
|
|
|
'--domains "' + certificate.domain_names.join(',') + '" ' +
|
|
|
|
`--domains "${certificate.domain_names.join(',')}" ` +
|
|
|
|
(letsencryptStaging ? '--staging' : '') +
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}' ` : '') +
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}'` : '');
|
|
|
|
(letsencryptStaging && letsencryptServer === null ? '--staging ' : '');
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('Command:', cmd);
|
|
|
|
logger.info('Command:', cmd);
|
|
|
|
|
|
|
|
|
|
|
@ -871,25 +872,26 @@ const internalCertificate = {
|
|
|
|
const hasConfigArg = certificate.meta.dns_provider !== 'route53';
|
|
|
|
const hasConfigArg = certificate.meta.dns_provider !== 'route53';
|
|
|
|
|
|
|
|
|
|
|
|
let mainCmd = certbotCommand + ' certonly ' +
|
|
|
|
let mainCmd = certbotCommand + ' certonly ' +
|
|
|
|
'--config "' + letsencryptConfig + '" ' +
|
|
|
|
`--config '${letsencryptConfig}' ` +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--cert-name "npm-' + certificate.id + '" ' +
|
|
|
|
`--cert-name 'npm-${certificate.id}' ` +
|
|
|
|
'--agree-tos ' +
|
|
|
|
'--agree-tos ' +
|
|
|
|
'--email "' + certificate.meta.letsencrypt_email + '" ' +
|
|
|
|
`--email '${certificate.meta.letsencrypt_email}' ` +
|
|
|
|
'--domains "' + certificate.domain_names.join(',') + '" ' +
|
|
|
|
`--domains '${certificate.domain_names.join(',')}' ` +
|
|
|
|
'--authenticator ' + dnsPlugin.full_plugin_name + ' ' +
|
|
|
|
`--authenticator '${dnsPlugin.full_plugin_name}' ` +
|
|
|
|
(
|
|
|
|
(
|
|
|
|
hasConfigArg
|
|
|
|
hasConfigArg
|
|
|
|
? '--' + dnsPlugin.full_plugin_name + '-credentials "' + credentialsLocation + '"'
|
|
|
|
? `--${dnsPlugin.full_plugin_name}-credentials '${credentialsLocation}' `
|
|
|
|
: ''
|
|
|
|
: ''
|
|
|
|
) +
|
|
|
|
) +
|
|
|
|
(
|
|
|
|
(
|
|
|
|
certificate.meta.propagation_seconds !== undefined
|
|
|
|
certificate.meta.propagation_seconds !== undefined
|
|
|
|
? ' --' + dnsPlugin.full_plugin_name + '-propagation-seconds ' + certificate.meta.propagation_seconds
|
|
|
|
? `--${dnsPlugin.full_plugin_name}-propagation-seconds '${certificate.meta.propagation_seconds}' `
|
|
|
|
: ''
|
|
|
|
: ''
|
|
|
|
) +
|
|
|
|
) +
|
|
|
|
(letsencryptStaging ? ' --staging' : '');
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}' ` : '') +
|
|
|
|
|
|
|
|
(letsencryptStaging && letsencryptServer === null ? '--staging ' : '');
|
|
|
|
|
|
|
|
|
|
|
|
// Prepend the path to the credentials file as an environment variable
|
|
|
|
// Prepend the path to the credentials file as an environment variable
|
|
|
|
if (certificate.meta.dns_provider === 'route53') {
|
|
|
|
if (certificate.meta.dns_provider === 'route53') {
|
|
|
@ -966,14 +968,15 @@ const internalCertificate = {
|
|
|
|
logger.info('Renewing Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
logger.info('Renewing Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
|
|
|
|
|
|
|
|
const cmd = certbotCommand + ' renew --force-renewal ' +
|
|
|
|
const cmd = certbotCommand + ' renew --force-renewal ' +
|
|
|
|
'--config "' + letsencryptConfig + '" ' +
|
|
|
|
`--config '${letsencryptConfig}' ` +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--cert-name "npm-' + certificate.id + '" ' +
|
|
|
|
`--cert-name 'npm-${certificate.id}' ` +
|
|
|
|
'--preferred-challenges "dns,http" ' +
|
|
|
|
'--preferred-challenges "dns,http" ' +
|
|
|
|
'--no-random-sleep-on-renew ' +
|
|
|
|
'--no-random-sleep-on-renew ' +
|
|
|
|
'--disable-hook-validation ' +
|
|
|
|
'--disable-hook-validation ' +
|
|
|
|
(letsencryptStaging ? '--staging' : '');
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}' ` : '') +
|
|
|
|
|
|
|
|
(letsencryptStaging && letsencryptServer === null ? '--staging ' : '');
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('Command:', cmd);
|
|
|
|
logger.info('Command:', cmd);
|
|
|
|
|
|
|
|
|
|
|
@ -998,13 +1001,14 @@ const internalCertificate = {
|
|
|
|
logger.info(`Renewing Let'sEncrypt certificates via ${dnsPlugin.name} for Cert #${certificate.id}: ${certificate.domain_names.join(', ')}`);
|
|
|
|
logger.info(`Renewing Let'sEncrypt certificates via ${dnsPlugin.name} for Cert #${certificate.id}: ${certificate.domain_names.join(', ')}`);
|
|
|
|
|
|
|
|
|
|
|
|
let mainCmd = certbotCommand + ' renew --force-renewal ' +
|
|
|
|
let mainCmd = certbotCommand + ' renew --force-renewal ' +
|
|
|
|
'--config "' + letsencryptConfig + '" ' +
|
|
|
|
`--config "${letsencryptConfig}" ` +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--cert-name "npm-' + certificate.id + '" ' +
|
|
|
|
`--cert-name 'npm-${certificate.id}' ` +
|
|
|
|
'--disable-hook-validation ' +
|
|
|
|
'--disable-hook-validation ' +
|
|
|
|
'--no-random-sleep-on-renew ' +
|
|
|
|
'--no-random-sleep-on-renew ' +
|
|
|
|
(letsencryptStaging ? ' --staging' : '');
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}' ` : '') +
|
|
|
|
|
|
|
|
(letsencryptStaging && letsencryptServer === null ? '--staging ' : '');
|
|
|
|
|
|
|
|
|
|
|
|
// Prepend the path to the credentials file as an environment variable
|
|
|
|
// Prepend the path to the credentials file as an environment variable
|
|
|
|
if (certificate.meta.dns_provider === 'route53') {
|
|
|
|
if (certificate.meta.dns_provider === 'route53') {
|
|
|
@ -1030,12 +1034,13 @@ const internalCertificate = {
|
|
|
|
logger.info('Revoking Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
logger.info('Revoking Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
|
|
|
|
|
|
|
|
|
|
|
|
const mainCmd = certbotCommand + ' revoke ' +
|
|
|
|
const mainCmd = certbotCommand + ' revoke ' +
|
|
|
|
'--config "' + letsencryptConfig + '" ' +
|
|
|
|
`--config '${letsencryptConfig}' ` +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--work-dir "/tmp/letsencrypt-lib" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--logs-dir "/tmp/letsencrypt-log" ' +
|
|
|
|
'--cert-path "/etc/letsencrypt/live/npm-' + certificate.id + '/fullchain.pem" ' +
|
|
|
|
`--cert-path '/etc/letsencrypt/live/npm-${certificate.id}/fullchain.pem' ` +
|
|
|
|
'--delete-after-revoke ' +
|
|
|
|
'--delete-after-revoke ' +
|
|
|
|
(letsencryptStaging ? '--staging' : '');
|
|
|
|
(letsencryptServer !== null ? `--server '${letsencryptServer}' ` : '') +
|
|
|
|
|
|
|
|
(letsencryptStaging && letsencryptServer === null ? '--staging ' : '');
|
|
|
|
|
|
|
|
|
|
|
|
// Don't fail command if file does not exist
|
|
|
|
// Don't fail command if file does not exist
|
|
|
|
const delete_credentialsCmd = `rm -f '/etc/letsencrypt/credentials/credentials-${certificate.id}' || true`;
|
|
|
|
const delete_credentialsCmd = `rm -f '/etc/letsencrypt/credentials/credentials-${certificate.id}' || true`;
|
|
|
|