@@ -608,12 +608,12 @@ const internalCertificate = {
608
608
checkPrivateKey : ( private_key ) => {
609
609
return tempWrite ( private_key , '/tmp' )
610
610
. then ( ( filepath ) => {
611
- return utils . exec ( 'openssl rsa -in ' + filepath + ' -check -noout' )
611
+ let key_type = private_key . includes ( '-----BEGIN RSA' ) ? 'rsa' : 'ec' ;
612
+ return utils . exec ( 'openssl ' + key_type + ' -in ' + filepath + ' -check -noout 2>&1 ' )
612
613
. then ( ( result ) => {
613
- if ( ! result . toLowerCase ( ) . includes ( 'key ok' ) ) {
614
- throw new error . ValidationError ( result ) ;
614
+ if ( ! result . toLowerCase ( ) . includes ( 'key ok' ) && ! result . toLowerCase ( ) . includes ( 'key valid' ) ) {
615
+ throw new error . ValidationError ( 'Result Validation Error: ' + result ) ;
615
616
}
616
-
617
617
fs . unlinkSync ( filepath ) ;
618
618
return true ;
619
619
} ) . catch ( ( err ) => {
@@ -788,9 +788,9 @@ const internalCertificate = {
788
788
789
789
logger . info ( `Requesting Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
790
790
791
- const credentials_loc = '/etc/letsencrypt/credentials-' + certificate . id ;
792
- const credentials_cmd = 'echo \'' + certificate . meta . dns_provider_credentials . replace ( '\'' , '\\\'' ) + '\' > \'' + credentials_loc + '\' && chmod 600 \'' + credentials_loc + '\'' ;
793
- const prepare_cmd = 'pip3 install ' + dns_plugin . package_name + '==' + dns_plugin . package_version ;
791
+ const credentials_loc = '/etc/letsencrypt/credentials/credentials -' + certificate . id ;
792
+ const credentials_cmd = 'mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + certificate . meta . dns_provider_credentials . replace ( '\'' , '\\\'' ) + '\' > \'' + credentials_loc + '\' && chmod 600 \'' + credentials_loc + '\'' ;
793
+ const prepare_cmd = 'pip3 install ' + dns_plugin . package_name + '==' + dns_plugin . package_version + ' ' + dns_plugin . dependencies ;
794
794
795
795
// Whether the plugin has a --<name>-credentials argument
796
796
const has_config_arg = certificate . meta . dns_provider !== 'route53' ;
@@ -818,11 +818,9 @@ const internalCertificate = {
818
818
if ( certificate . meta . dns_provider === 'route53' ) {
819
819
main_cmd = 'AWS_CONFIG_FILE=\'' + credentials_loc + '\' ' + main_cmd ;
820
820
}
821
-
822
- const teardown_cmd = `rm '${ credentials_loc } '` ;
823
821
824
822
if ( debug_mode ) {
825
- logger . info ( 'Command:' , `${ credentials_cmd } && ${ prepare_cmd } && ${ main_cmd } && ${ teardown_cmd } ` ) ;
823
+ logger . info ( 'Command:' , `${ credentials_cmd } && ${ prepare_cmd } && ${ main_cmd } ` ) ;
826
824
}
827
825
828
826
return utils . exec ( credentials_cmd )
@@ -831,11 +829,15 @@ const internalCertificate = {
831
829
. then ( ( ) => {
832
830
return utils . exec ( main_cmd )
833
831
. then ( async ( result ) => {
834
- await utils . exec ( teardown_cmd ) ;
835
832
logger . info ( result ) ;
836
833
return result ;
837
834
} ) ;
838
835
} ) ;
836
+ } ) . catch ( async ( err ) => {
837
+ // Don't fail if file does not exist
838
+ const delete_credentials_cmd = `rm -f '${ credentials_loc } ' || true` ;
839
+ await utils . exec ( delete_credentials_cmd ) ;
840
+ throw err ;
839
841
} ) ;
840
842
} ,
841
843
@@ -922,10 +924,6 @@ const internalCertificate = {
922
924
923
925
logger . info ( `Renewing Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
924
926
925
- const credentials_loc = '/etc/letsencrypt/credentials-' + certificate . id ;
926
- const credentials_cmd = 'echo \'' + certificate . meta . dns_provider_credentials . replace ( '\'' , '\\\'' ) + '\' > \'' + credentials_loc + '\' && chmod 600 \'' + credentials_loc + '\'' ;
927
- const prepare_cmd = 'pip3 install ' + dns_plugin . package_name + '==' + dns_plugin . package_version ;
928
-
929
927
let main_cmd =
930
928
certbot_command + ' renew --non-interactive ' +
931
929
'--cert-name "npm-' + certificate . id + '" ' +
@@ -934,26 +932,18 @@ const internalCertificate = {
934
932
935
933
// Prepend the path to the credentials file as an environment variable
936
934
if ( certificate . meta . dns_provider === 'route53' ) {
937
- main_cmd = 'AWS_CONFIG_FILE=\'' + credentials_loc + '\' ' + main_cmd ;
935
+ const credentials_loc = '/etc/letsencrypt/credentials/credentials-' + certificate . id ;
936
+ main_cmd = 'AWS_CONFIG_FILE=\'' + credentials_loc + '\' ' + main_cmd ;
938
937
}
939
938
940
- const teardown_cmd = `rm '${ credentials_loc } '` ;
941
-
942
939
if ( debug_mode ) {
943
- logger . info ( 'Command:' , ` ${ credentials_cmd } && ${ prepare_cmd } && ${ main_cmd } && ${ teardown_cmd } ` ) ;
940
+ logger . info ( 'Command:' , main_cmd ) ;
944
941
}
945
942
946
- return utils . exec ( credentials_cmd )
947
- . then ( ( ) => {
948
- return utils . exec ( prepare_cmd )
949
- . then ( ( ) => {
950
- return utils . exec ( main_cmd )
951
- . then ( async ( result ) => {
952
- await utils . exec ( teardown_cmd ) ;
953
- logger . info ( result ) ;
954
- return result ;
955
- } ) ;
956
- } ) ;
943
+ return utils . exec ( main_cmd )
944
+ . then ( async ( result ) => {
945
+ logger . info ( result ) ;
946
+ return result ;
957
947
} ) ;
958
948
} ,
959
949
@@ -965,20 +955,21 @@ const internalCertificate = {
965
955
revokeLetsEncryptSsl : ( certificate , throw_errors ) => {
966
956
logger . info ( 'Revoking Let\'sEncrypt certificates for Cert #' + certificate . id + ': ' + certificate . domain_names . join ( ', ' ) ) ;
967
957
968
- let cmd = certbot_command + ' revoke --non-interactive ' +
958
+ const main_cmd = certbot_command + ' revoke --non-interactive ' +
969
959
'--cert-path "/etc/letsencrypt/live/npm-' + certificate . id + '/fullchain.pem" ' +
970
960
'--delete-after-revoke ' +
971
961
( le_staging ? '--staging' : '' ) ;
972
962
963
+ // Don't fail command if file does not exist
964
+ const delete_credentials_cmd = `rm -f '/etc/letsencrypt/credentials/credentials-${ certificate . id } ' || true` ;
965
+
973
966
if ( debug_mode ) {
974
- logger . info ( 'Command:' , cmd ) ;
967
+ logger . info ( 'Command:' , main_cmd + '; ' + delete_credentials_cmd ) ;
975
968
}
976
969
977
- return utils . exec ( cmd )
978
- . then ( ( result ) => {
979
- if ( debug_mode ) {
980
- logger . info ( 'Command:' , cmd ) ;
981
- }
970
+ return utils . exec ( main_cmd )
971
+ . then ( async ( result ) => {
972
+ await utils . exec ( delete_credentials_cmd ) ;
982
973
logger . info ( result ) ;
983
974
return result ;
984
975
} )
0 commit comments