@@ -221,7 +221,7 @@ const internalCertificate = {
221
221
await certificateModel
222
222
. query ( )
223
223
. deleteById ( certificate . id ) ;
224
-
224
+
225
225
throw error ;
226
226
} ) ;
227
227
} else {
@@ -615,13 +615,26 @@ const internalCertificate = {
615
615
checkPrivateKey : ( private_key ) => {
616
616
return tempWrite ( private_key , '/tmp' )
617
617
. 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 )
620
627
. then ( ( result ) => {
628
+ if ( debug_mode ) {
629
+ logger . info ( 'checkPrivateKey result: ' + result ) ;
630
+ }
621
631
if ( ! result . toLowerCase ( ) . includes ( 'key ok' ) && ! result . toLowerCase ( ) . includes ( 'key valid' ) ) {
622
632
throw new error . ValidationError ( 'Result Validation Error: ' + result ) ;
623
633
}
624
634
fs . unlinkSync ( filepath ) ;
635
+ if ( debug_mode ) {
636
+ logger . info ( 'checkPrivateKey completed' ) ;
637
+ }
625
638
return true ;
626
639
} ) . catch ( ( err ) => {
627
640
fs . unlinkSync ( filepath ) ;
@@ -660,9 +673,17 @@ const internalCertificate = {
660
673
*/
661
674
getCertificateInfoFromFile : ( certificate_file , throw_expired ) => {
662
675
let cert_data = { } ;
676
+ const cmd = 'openssl x509 -in ' + certificate_file + ' -subject -noout' ;
663
677
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 )
665
683
. then ( ( result ) => {
684
+ if ( debug_mode ) {
685
+ logger . info ( 'getCertificateInfoFromFile result: ' + result ) ;
686
+ }
666
687
// subject=CN = something.example.com
667
688
let regex = / (?: s u b j e c t = ) ? [ ^ = ] + = \s + ( \S + ) / gim;
668
689
let match = regex . exec ( result ) ;
@@ -674,9 +695,16 @@ const internalCertificate = {
674
695
cert_data [ 'cn' ] = match [ 1 ] ;
675
696
} )
676
697
. 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 ) ;
678
703
} )
679
704
. then ( ( result ) => {
705
+ if ( debug_mode ) {
706
+ logger . info ( 'getCertificateInfoFromFile result: ' + result ) ;
707
+ }
680
708
// issuer=C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
681
709
let regex = / ^ (?: i s s u e r = ) ? ( .* ) $ / gim;
682
710
let match = regex . exec ( result ) ;
@@ -688,9 +716,16 @@ const internalCertificate = {
688
716
cert_data [ 'issuer' ] = match [ 1 ] ;
689
717
} )
690
718
. 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 ) ;
692
724
} )
693
725
. then ( ( result ) => {
726
+ if ( debug_mode ) {
727
+ logger . info ( 'getCertificateInfoFromFile result: ' + result ) ;
728
+ }
694
729
// notBefore=Jul 14 04:04:29 2018 GMT
695
730
// notAfter=Oct 12 04:04:29 2018 GMT
696
731
let valid_from = null ;
@@ -725,6 +760,10 @@ const internalCertificate = {
725
760
to : valid_to
726
761
} ;
727
762
763
+ if ( debug_mode ) {
764
+ logger . info ( 'getCertificateInfoFromFile completed: ' + JSON . stringify ( cert_data ) ) ;
765
+ }
766
+
728
767
return cert_data ;
729
768
} ) . catch ( ( err ) => {
730
769
throw new error . ValidationError ( 'Certificate is not valid (' + err . message + ')' , err ) ;
@@ -802,21 +841,21 @@ const internalCertificate = {
802
841
// Whether the plugin has a --<name>-credentials argument
803
842
const has_config_arg = certificate . meta . dns_provider !== 'route53' ;
804
843
805
- let main_cmd =
844
+ let main_cmd =
806
845
certbot_command + ' certonly --non-interactive ' +
807
846
'--cert-name "npm-' + certificate . id + '" ' +
808
847
'--agree-tos ' +
809
- '--email "' + certificate . meta . letsencrypt_email + '" ' +
848
+ '--email "' + certificate . meta . letsencrypt_email + '" ' +
810
849
'--domains "' + certificate . domain_names . join ( ',' ) + '" ' +
811
850
'--authenticator ' + dns_plugin . full_plugin_name + ' ' +
812
851
(
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 + '"'
815
854
: ''
816
855
) +
817
856
(
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
820
859
: ''
821
860
) +
822
861
( le_staging ? ' --staging' : '' ) ;
@@ -862,7 +901,7 @@ const internalCertificate = {
862
901
} )
863
902
. then ( ( certificate ) => {
864
903
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 ;
866
905
867
906
return renewMethod ( certificate )
868
907
. then ( ( ) => {
@@ -931,7 +970,7 @@ const internalCertificate = {
931
970
932
971
logger . info ( `Renewing Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
933
972
934
- let main_cmd =
973
+ let main_cmd =
935
974
certbot_command + ' renew --non-interactive ' +
936
975
'--cert-name "npm-' + certificate . id + '" ' +
937
976
'--disable-hook-validation' +
0 commit comments