@@ -608,12 +608,12 @@ const internalCertificate = {
608608 checkPrivateKey : ( private_key ) => {
609609 return tempWrite ( private_key , '/tmp' )
610610 . 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 ' )
612613 . 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 ) ;
615616 }
616-
617617 fs . unlinkSync ( filepath ) ;
618618 return true ;
619619 } ) . catch ( ( err ) => {
@@ -788,9 +788,9 @@ const internalCertificate = {
788788
789789 logger . info ( `Requesting Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
790790
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 ;
794794
795795 // Whether the plugin has a --<name>-credentials argument
796796 const has_config_arg = certificate . meta . dns_provider !== 'route53' ;
@@ -818,11 +818,9 @@ const internalCertificate = {
818818 if ( certificate . meta . dns_provider === 'route53' ) {
819819 main_cmd = 'AWS_CONFIG_FILE=\'' + credentials_loc + '\' ' + main_cmd ;
820820 }
821-
822- const teardown_cmd = `rm '${ credentials_loc } '` ;
823821
824822 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 } ` ) ;
826824 }
827825
828826 return utils . exec ( credentials_cmd )
@@ -831,11 +829,15 @@ const internalCertificate = {
831829 . then ( ( ) => {
832830 return utils . exec ( main_cmd )
833831 . then ( async ( result ) => {
834- await utils . exec ( teardown_cmd ) ;
835832 logger . info ( result ) ;
836833 return result ;
837834 } ) ;
838835 } ) ;
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 ;
839841 } ) ;
840842 } ,
841843
@@ -922,10 +924,6 @@ const internalCertificate = {
922924
923925 logger . info ( `Renewing Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
924926
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-
929927 let main_cmd =
930928 certbot_command + ' renew --non-interactive ' +
931929 '--cert-name "npm-' + certificate . id + '" ' +
@@ -934,26 +932,18 @@ const internalCertificate = {
934932
935933 // Prepend the path to the credentials file as an environment variable
936934 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 ;
938937 }
939938
940- const teardown_cmd = `rm '${ credentials_loc } '` ;
941-
942939 if ( debug_mode ) {
943- logger . info ( 'Command:' , ` ${ credentials_cmd } && ${ prepare_cmd } && ${ main_cmd } && ${ teardown_cmd } ` ) ;
940+ logger . info ( 'Command:' , main_cmd ) ;
944941 }
945942
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 ;
957947 } ) ;
958948 } ,
959949
@@ -965,20 +955,21 @@ const internalCertificate = {
965955 revokeLetsEncryptSsl : ( certificate , throw_errors ) => {
966956 logger . info ( 'Revoking Let\'sEncrypt certificates for Cert #' + certificate . id + ': ' + certificate . domain_names . join ( ', ' ) ) ;
967957
968- let cmd = certbot_command + ' revoke --non-interactive ' +
958+ const main_cmd = certbot_command + ' revoke --non-interactive ' +
969959 '--cert-path "/etc/letsencrypt/live/npm-' + certificate . id + '/fullchain.pem" ' +
970960 '--delete-after-revoke ' +
971961 ( le_staging ? '--staging' : '' ) ;
972962
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+
973966 if ( debug_mode ) {
974- logger . info ( 'Command:' , cmd ) ;
967+ logger . info ( 'Command:' , main_cmd + '; ' + delete_credentials_cmd ) ;
975968 }
976969
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 ) ;
982973 logger . info ( result ) ;
983974 return result ;
984975 } )
0 commit comments