Skip to content

Commit 4d36be4

Browse files
committed
Fixes for stray http01 tokens with *ftp*
FTP_PORT not used by ftp. No code for sftp, davfs, ftpes, or ftps. Needs tests, but at least this won't fall thru to attempting to delete from local file system.
1 parent 92694d2 commit 4d36be4

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

getssl

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
# 2022-11-01 Add FTP_PORT
290290
# 2023-02-04 Create newline to ensure [SAN] section can be parsed (#792)(MRigal)
291291
# 2023-02-22 Remove cronie from deb package dependencies (2.48)
292+
# 2024-03-16 Use FTP_PORT when deleting ftp tokens. Delete tokens when using sftp, davfs, ftpes, ftps (#693,#839) (tlhackque)
292293
# ----------------------------------------------------------------------------------------
293294

294295
case :$SHELLOPTS: in
@@ -971,6 +972,8 @@ clean_up() { # Perform pre-exit housekeeping
971972
fi
972973
}
973974

975+
# When adding a new protocol type here, also add support to delete http01 tokens using it
976+
# in fulfill_challenges().
974977
copy_file_to_location() { # copies a file, using scp, sftp or ftp if required.
975978
cert=$1 # descriptive name, just used for display
976979
from=$2 # current file location
@@ -1542,24 +1545,56 @@ for d in "${alldomains[@]}"; do
15421545
ftplocn=$(echo "${t_loc}"| awk -F: '{print $5}')
15431546
debug "$FTP_COMMAND user=$ftpuser - pass=$ftppass - host=$ftphost location=$ftplocn"
15441547
$FTP_COMMAND <<- EOF
1545-
open $ftphost
1548+
open $ftphost $FTP_PORT
15461549
user $ftpuser $ftppass
15471550
cd $ftplocn
15481551
delete ${token:?}
15491552
EOF
1553+
elif [[ "${to:0:5}" == "sftp:" ]] ; then
1554+
debug "using sftp to delete token file"
1555+
ftpuser=$(echo "$to"| awk -F: '{print $2}')
1556+
ftppass=$(echo "$to"| awk -F: '{print $3}')
1557+
ftphost=$(echo "$to"| awk -F: '{print $4}')
1558+
ftplocn=$(echo "$to"| awk -F: '{print $5}')
1559+
ftpdirn=$(dirname "$ftplocn")
1560+
if [ -n "$FTP_PORT" ]; then SFTP_PORT="-P $FTP_PORT"; else SFTP_PORT=""; fi
1561+
debug "sftp $SFTP_OPTS user=$ftpuser - pass=$ftppass - host=$ftphost port=$FTP_PORT loc=$ftplocn file=${token:?}"
1562+
# shellcheck disable=SC2086
1563+
sshpass -p "$ftppass" sftp $SFTP_OPTS $SFTP_PORT "$ftpuser@$ftphost" <<- _EOF
1564+
cd $ftpdirn
1565+
rm ./${token:>}
1566+
_EOF
1567+
elif [[ "${to:0:5}" == "davs:" ]] ; then
1568+
debug "using davs to delete the token"
1569+
davsuser=$(echo "$to"| awk -F: '{print $2}')
1570+
davspass=$(echo "$to"| awk -F: '{print $3}')
1571+
davshost=$(echo "$to"| awk -F: '{print $4}')
1572+
davsport=$(echo "$to"| awk -F: '{print $5}')
1573+
davslocn=$(echo "$to"| awk -F: '{print $6}')
1574+
davsdirn=$(dirname "$davslocn")
1575+
davsdirn=$(echo "${davsdirn}/" | sed 's,//,/,g')
1576+
davsfile=$(basename "$davslocn")
1577+
debug "davs user=$davsuser - pass=$davspass - host=$davshost port=$davsport dir=$davsdirn file=$davsfile"
1578+
# shellcheck disable=SC2086
1579+
curl ${_NOMETER} -u "${davsuser}:${davspass}" -X "DELETE" "https://${davshost}:${davsport}${davsdirn}${davsfile}"
15501580
elif [[ "${t_loc:0:6}" == "ftpes:" ]] || [[ "${t_loc:0:5}" == "ftps:" ]] ; then
1581+
if [ -n "$FTP_PORT" ]; then SFTP_PORT=":${FTP_PORT}"; fi
15511582
debug "using ftp to delete the file from $from"
15521583
ftpuser=$(echo "${t_loc}"| awk -F: '{print $2}')
15531584
ftppass=$(echo "${t_loc}"| awk -F: '{print $3}')
15541585
ftphost=$(echo "${t_loc}"| awk -F: '{print $4}')
15551586
ftplocn=$(echo "${t_loc}"| awk -F: '{print $5}')
1556-
debug "ftp user=$ftpuser - pass=$ftppass - host=$ftphost file=${ftplocnn/${token:?}"
1587+
SFTP_PORT=""
1588+
if [ -z "$FTP_PORT" ]; then
1589+
SFTP_PORT=":990"
1590+
fi
1591+
debug "ftp user=$ftpuser - pass=$ftppass - host=$ftphost file=${ftplocn}/${token:?}"
15571592
if [[ "${to:0:5}" == "ftps:" ]] ; then
15581593
# shellcheck disable=SC2086
1559-
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" --silent -Q "DELE ${token:?}}" "ftp://${ftphost}${ftplocn}:990/"
1594+
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" --silent -Q "DELE ${token:?}}" "ftp://${ftphost}${SFTP_PORT}/${ftplocn}/"
15601595
else
15611596
# shellcheck disable=SC2086
1562-
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" --silent -Q "DELE ${token:?}" "ftp://${ftphost}${ftplocn}/"
1597+
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" --silent -Q "DELE ${token:?}" "ftp://${ftphost}${SFTP_PORT}/${ftplocn}/"
15631598
fi
15641599
else
15651600
rm -f "${t_loc:?}/${token:?}"

0 commit comments

Comments
 (0)