Skip to content

Commit 270b8b3

Browse files
committed
Added much debug to certificate checks
1 parent bc1c50a commit 270b8b3

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

backend/internal/certificate.js

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const internalCertificate = {
221221
await certificateModel
222222
.query()
223223
.deleteById(certificate.id);
224-
224+
225225
throw error;
226226
});
227227
} else {
@@ -615,13 +615,26 @@ const internalCertificate = {
615615
checkPrivateKey: (private_key) => {
616616
return tempWrite(private_key, '/tmp')
617617
.then((filepath) => {
618-
let key_type = private_key.includes('-----BEGIN RSA') ? 'rsa' : 'ec';
619-
return utils.exec('openssl ' + key_type + ' -in ' + filepath + ' -check -noout 2>&1 ')
618+
const key_type = private_key.includes('-----BEGIN RSA') ? 'rsa' : 'ec';
619+
const cmd = 'openssl ' + key_type + ' -in ' + filepath + ' -check -noout 2>&1 ';
620+
621+
if (debug_mode) {
622+
logger.info('checkPrivateKey type: ' + key_type + ' ...');
623+
logger.info('checkPrivateKey command: ' + cmd);
624+
}
625+
626+
return utils.exec(cmd)
620627
.then((result) => {
628+
if (debug_mode) {
629+
logger.info('checkPrivateKey result: ' + result);
630+
}
621631
if (!result.toLowerCase().includes('key ok') && !result.toLowerCase().includes('key valid') ) {
622632
throw new error.ValidationError('Result Validation Error: ' + result);
623633
}
624634
fs.unlinkSync(filepath);
635+
if (debug_mode) {
636+
logger.info('checkPrivateKey completed');
637+
}
625638
return true;
626639
}).catch((err) => {
627640
fs.unlinkSync(filepath);
@@ -660,9 +673,17 @@ const internalCertificate = {
660673
*/
661674
getCertificateInfoFromFile: (certificate_file, throw_expired) => {
662675
let cert_data = {};
676+
const cmd = 'openssl x509 -in ' + certificate_file + ' -subject -noout';
663677

664-
return utils.exec('openssl x509 -in ' + certificate_file + ' -subject -noout')
678+
if (debug_mode) {
679+
logger.info('getCertificateInfoFromFile command: ' + cmd);
680+
}
681+
682+
return utils.exec(cmd)
665683
.then((result) => {
684+
if (debug_mode) {
685+
logger.info('getCertificateInfoFromFile result: ' + result);
686+
}
666687
// subject=CN = something.example.com
667688
let regex = /(?:subject=)?[^=]+=\s+(\S+)/gim;
668689
let match = regex.exec(result);
@@ -674,9 +695,16 @@ const internalCertificate = {
674695
cert_data['cn'] = match[1];
675696
})
676697
.then(() => {
677-
return utils.exec('openssl x509 -in ' + certificate_file + ' -issuer -noout');
698+
const cmd2 = 'openssl x509 -in ' + certificate_file + ' -issuer -noout';
699+
if (debug_mode) {
700+
logger.info('getCertificateInfoFromFile command: ' + cmd2);
701+
}
702+
return utils.exec(cmd2);
678703
})
679704
.then((result) => {
705+
if (debug_mode) {
706+
logger.info('getCertificateInfoFromFile result: ' + result);
707+
}
680708
// issuer=C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
681709
let regex = /^(?:issuer=)?(.*)$/gim;
682710
let match = regex.exec(result);
@@ -688,9 +716,16 @@ const internalCertificate = {
688716
cert_data['issuer'] = match[1];
689717
})
690718
.then(() => {
691-
return utils.exec('openssl x509 -in ' + certificate_file + ' -dates -noout');
719+
const cmd3 = 'openssl x509 -in ' + certificate_file + ' -dates -noout';
720+
if (debug_mode) {
721+
logger.info('getCertificateInfoFromFile command: ' + cmd3);
722+
}
723+
return utils.exec(cmd3);
692724
})
693725
.then((result) => {
726+
if (debug_mode) {
727+
logger.info('getCertificateInfoFromFile result: ' + result);
728+
}
694729
// notBefore=Jul 14 04:04:29 2018 GMT
695730
// notAfter=Oct 12 04:04:29 2018 GMT
696731
let valid_from = null;
@@ -725,6 +760,10 @@ const internalCertificate = {
725760
to: valid_to
726761
};
727762

763+
if (debug_mode) {
764+
logger.info('getCertificateInfoFromFile completed: ' + JSON.stringify(cert_data));
765+
}
766+
728767
return cert_data;
729768
}).catch((err) => {
730769
throw new error.ValidationError('Certificate is not valid (' + err.message + ')', err);
@@ -802,21 +841,21 @@ const internalCertificate = {
802841
// Whether the plugin has a --<name>-credentials argument
803842
const has_config_arg = certificate.meta.dns_provider !== 'route53';
804843

805-
let main_cmd =
844+
let main_cmd =
806845
certbot_command + ' certonly --non-interactive ' +
807846
'--cert-name "npm-' + certificate.id + '" ' +
808847
'--agree-tos ' +
809-
'--email "' + certificate.meta.letsencrypt_email + '" ' +
848+
'--email "' + certificate.meta.letsencrypt_email + '" ' +
810849
'--domains "' + certificate.domain_names.join(',') + '" ' +
811850
'--authenticator ' + dns_plugin.full_plugin_name + ' ' +
812851
(
813-
has_config_arg
814-
? '--' + dns_plugin.full_plugin_name + '-credentials "' + credentials_loc + '"'
852+
has_config_arg
853+
? '--' + dns_plugin.full_plugin_name + '-credentials "' + credentials_loc + '"'
815854
: ''
816855
) +
817856
(
818-
certificate.meta.propagation_seconds !== undefined
819-
? ' --' + dns_plugin.full_plugin_name + '-propagation-seconds ' + certificate.meta.propagation_seconds
857+
certificate.meta.propagation_seconds !== undefined
858+
? ' --' + dns_plugin.full_plugin_name + '-propagation-seconds ' + certificate.meta.propagation_seconds
820859
: ''
821860
) +
822861
(le_staging ? ' --staging' : '');
@@ -862,7 +901,7 @@ const internalCertificate = {
862901
})
863902
.then((certificate) => {
864903
if (certificate.provider === 'letsencrypt') {
865-
let renewMethod = certificate.meta.dns_challenge ? internalCertificate.renewLetsEncryptSslWithDnsChallenge : internalCertificate.renewLetsEncryptSsl;
904+
let renewMethod = certificate.meta.dns_challenge ? internalCertificate.renewLetsEncryptSslWithDnsChallenge : internalCertificate.renewLetsEncryptSsl;
866905

867906
return renewMethod(certificate)
868907
.then(() => {
@@ -931,7 +970,7 @@ const internalCertificate = {
931970

932971
logger.info(`Renewing Let'sEncrypt certificates via ${dns_plugin.display_name} for Cert #${certificate.id}: ${certificate.domain_names.join(', ')}`);
933972

934-
let main_cmd =
973+
let main_cmd =
935974
certbot_command + ' renew --non-interactive ' +
936975
'--cert-name "npm-' + certificate.id + '" ' +
937976
'--disable-hook-validation' +

0 commit comments

Comments
 (0)