Skip to content

Commit 1982a94

Browse files
authored
Merge pull request #691 from tlhackque/master
Prefer API V2 when both offered in a single directory, improve test error reports
2 parents d2bdc92 + d7e3039 commit 1982a94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+377
-37
lines changed

getssl

+58-31
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@
266266
# 2021-07-22 Only pass +noidnout param to dig/drill(#682)(2.38)
267267
# 2021-07-25 Fix copy_file_to_location failures with ssh when suffix applied to file lacking an extension (tlhackque)(#686)
268268
# 2021-07-27 Support ftps://, FTPS_OPTIONS, remove default --insecure parameter to ftpes. Report caller(s) of error_exit in debug and test modes (tlhackque)(#687)(2.39)
269+
# 2021-07-30 Prefer API V2 when both offered (tlhackque) (#690) (2.40)
270+
# 2021-07-30 Run tests with -d to catch intermittent failures, Use fork's repo for upgrade tests. (tlhackque) (#692) (2.41)
269271
# ----------------------------------------------------------------------------------------
270272

271273
case :$SHELLOPTS: in
@@ -274,7 +276,7 @@ esac
274276

275277
PROGNAME=${0##*/}
276278
PROGDIR="$(cd "$(dirname "$0")" || exit; pwd -P;)"
277-
VERSION="2.39"
279+
VERSION="2.41"
278280

279281
# defaults
280282
ACCOUNT_KEY_LENGTH=4096
@@ -284,7 +286,11 @@ CA="https://acme-staging-v02.api.letsencrypt.org/directory"
284286
CHALLENGE_CHECK_TYPE="http"
285287
CHECK_REMOTE_WAIT=0
286288
CHECK_REMOTE="true"
287-
CODE_LOCATION="https://raw.githubusercontent.com/srvrco/getssl/master/getssl"
289+
if [[ -n "${GITHUB_REPOSITORY}" ]] ; then
290+
CODE_LOCATION="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/master/getssl"
291+
else
292+
CODE_LOCATION="https://raw.githubusercontent.com/srvrco/getssl/master/getssl"
293+
fi
288294
CSR_SUBJECT="/"
289295
CURL_USERAGENT="${PROGNAME}/${VERSION}"
290296
DEACTIVATE_AUTH="false"
@@ -330,10 +336,12 @@ DNS_WAIT_RETRY_ADD="false" # Try the dns_add_command again if the DNS recor
330336
# Private variables
331337
_CHECK_ALL=0
332338
_CREATE_CONFIG=0
339+
_CURL_VERSION=""
333340
_FORCE_RENEW=0
334341
_KEEP_VERSIONS=""
335342
_MUTE=0
336343
_NOTIFY_VALID=0
344+
_NOMETER=""
337345
_QUIET=0
338346
_RECREATE_CSR=0
339347
_REDIRECT_OUTPUT="1>/dev/null 2>&1"
@@ -562,15 +570,15 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
562570
check_result=$($DNS_CHECK_FUNC $DNS_CHECK_OPTIONS TXT "${rr}" "@${ns}" \
563571
| grep -i "^${rr}" \
564572
| grep 'IN\WTXT'|awk -F'"' '{ print $2}')
565-
debug "check_result=$check_result"
573+
debug "check_result=\"$check_result\""
566574
if [[ -z "$check_result" ]]; then
567575
# shellcheck disable=SC2086
568576
debug "$DNS_CHECK_FUNC" $DNS_CHECK_OPTIONS ANY "${rr}" "@${ns}"
569577
# shellcheck disable=SC2086
570578
check_result=$($DNS_CHECK_FUNC $DNS_CHECK_OPTIONS ANY "${rr}" "@${ns}" \
571579
| grep -i "^${rr}" \
572580
| grep 'IN\WTXT'|awk -F'"' '{ print $2}')
573-
debug "check_result=$check_result"
581+
debug "check_result=\"$check_result\""
574582
fi
575583
elif [[ "$DNS_CHECK_FUNC" == "host" ]]; then
576584
check_result=$($DNS_CHECK_FUNC -t TXT "${rr}" "${ns}" \
@@ -583,8 +591,8 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
583591
| grep 'text ='|awk -F'"' '{ print $2}')
584592
fi
585593
fi
586-
debug "expecting $auth_key"
587-
debug "${ns} gave ... $check_result"
594+
debug "expecting \"$auth_key\""
595+
debug "${ns} gave ... \"$check_result\""
588596

589597
if [[ "$check_result" == *"$auth_key"* ]]; then
590598
check_dns="success"
@@ -606,7 +614,7 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
606614
debug "dns check failed - removing existing value"
607615
del_dns_rr "${d}" "${auth_key}"
608616

609-
error_exit "checking ${rr} gave $check_result not $auth_key"
617+
error_exit "checking \"${rr}\" gave \"$check_result\" not \"$auth_key\""
610618
fi
611619
fi
612620
done
@@ -758,7 +766,7 @@ check_getssl_upgrade() { # check if a more recent version of code is available a
758766
if [ "$TEMP_UPGRADE_FILE" == "" ]; then
759767
error_exit "mktemp failed"
760768
fi
761-
curl --user-agent "$CURL_USERAGENT" --silent "$CODE_LOCATION" --output "$TEMP_UPGRADE_FILE"
769+
curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --silent "$CODE_LOCATION" --output "$TEMP_UPGRADE_FILE"
762770
errcode=$?
763771
if [[ $errcode -eq 60 ]]; then
764772
error_exit "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
@@ -941,7 +949,7 @@ copy_file_to_location() { # copies a file, using scp, sftp or ftp if required.
941949
fromfile=$(basename "$from")
942950
debug "davs user=$davsuser - pass=$davspass - host=$davshost port=$davsport dir=$davsdirn file=$davsfile"
943951
debug "from dir=$fromdir file=$fromfile"
944-
curl -u "${davsuser}:${davspass}" -T "${fromdir}/${fromfile}" "https://${davshost}:${davsport}${davsdirn}${davsfile}"
952+
curl ${_NOMETER} -u "${davsuser}:${davspass}" -T "${fromdir}/${fromfile}" "https://${davshost}:${davsport}${davsdirn}${davsfile}"
945953
elif [[ "${to:0:6}" == "ftpes:" ]] || [[ "${to:0:5}" == "ftps:" ]] ; then
946954
debug "using ftp to copy the file from $from"
947955
ftpuser=$(echo "$to"| awk -F: '{print $2}')
@@ -956,10 +964,10 @@ copy_file_to_location() { # copies a file, using scp, sftp or ftp if required.
956964
debug "from dir=$fromdir file=$fromfile"
957965
if [[ "${to:0:5}" == "ftps:" ]] ; then
958966
# shellcheck disable=SC2086
959-
curl $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" -T "${fromdir}/${fromfile}" "ftp://${ftphost}${ftpdirn}:990/"
967+
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" -T "${fromdir}/${fromfile}" "ftp://${ftphost}${ftpdirn}:990/"
960968
else
961969
# shellcheck disable=SC2086
962-
curl $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" -T "${fromdir}/${fromfile}" "ftp://${ftphost}${ftpdirn}/"
970+
curl ${_NOMETER} $FTPS_OPTIONS --ftp-ssl --ftp-ssl-reqd -u "${ftpuser}:${ftppass}" -T "${fromdir}/${fromfile}" "ftp://${ftphost}${ftpdirn}/"
963971
fi
964972
else
965973
if ! mkdir -p "$(dirname "$to")" ; then
@@ -1377,7 +1385,7 @@ for d in "${alldomains[@]}"; do
13771385
# ACME only allows port 80 (http), but redirects may use https. --insecure is used in case
13781386
# those certificates are being renewed. Let's Encrypt does the same. In this case, we verify
13791387
# that the correct data is returned, so this is safe.
1380-
if [[ ! "$(curl --user-agent "$CURL_USERAGENT" --insecure --silent --location "$wellknown_url")" == "$keyauthorization" ]]; then
1388+
if [[ ! "$(curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --insecure --silent --location "$wellknown_url")" == "$keyauthorization" ]]; then
13811389
error_exit "for some reason could not reach $wellknown_url - please check it manually"
13821390
fi
13831391
fi
@@ -1621,7 +1629,7 @@ get_certificate() { # get certificate for csr, if all domains validated.
16211629
CertData=$(awk ' $1 ~ "^Location" {print $2}' "$CURL_HEADER" |tr -d '\r')
16221630
if [[ "$CertData" ]] ; then
16231631
echo -----BEGIN CERTIFICATE----- > "$gc_certfile"
1624-
curl --user-agent "$CURL_USERAGENT" --silent "$CertData" | openssl base64 -e >> "$gc_certfile"
1632+
curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --silent "$CertData" | openssl base64 -e >> "$gc_certfile"
16251633
echo -----END CERTIFICATE----- >> "$gc_certfile"
16261634
info "Certificate saved in $CERT_FILE"
16271635
fi
@@ -1641,7 +1649,7 @@ get_certificate() { # get certificate for csr, if all domains validated.
16411649
| sed 's/>//g')
16421650
if [[ "$IssuerData" ]] ; then
16431651
echo -----BEGIN CERTIFICATE----- > "$gc_cafile"
1644-
curl --user-agent "$CURL_USERAGENT" --silent "$IssuerData" | openssl base64 -e >> "$gc_cafile"
1652+
curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --silent "$IssuerData" | openssl base64 -e >> "$gc_cafile"
16451653
echo -----END CERTIFICATE----- >> "$gc_cafile"
16461654
info "The intermediate CA cert is in $gc_cafile"
16471655
fi
@@ -1699,7 +1707,7 @@ get_certificate() { # get certificate for csr, if all domains validated.
16991707
cp "$gc_certfile" "$gc_fullchain"
17001708
while [[ -n "$issuer_url" ]]; do
17011709
debug Fetching certificate issuer from "$issuer_url"
1702-
issuer_cert=$(curl --user-agent "$CURL_USERAGENT" --silent "$issuer_url" | openssl x509 -inform der -outform pem)
1710+
issuer_cert=$(curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --silent "$issuer_url" | openssl x509 -inform der -outform pem)
17031711
debug Fetched issuer certificate "$(echo "$issuer_cert" | openssl x509 -inform pem -noout -text | awk 'BEGIN {FS="Subject: "} NF==2 {print $2; exit}')"
17041712
echo "$issuer_cert" >> "$gc_fullchain"
17051713

@@ -1714,7 +1722,7 @@ get_certificate() { # get certificate for csr, if all domains validated.
17141722
get_cr() { # get curl response
17151723
url="$1"
17161724
debug url "$url"
1717-
response=$(curl --user-agent "$CURL_USERAGENT" --silent "$url")
1725+
response=$(curl ${_NOMETER} --user-agent "$CURL_USERAGENT" --silent "$url")
17181726
ret=$?
17191727
debug response "${response//[$'\t\r\n']}"
17201728
code=$(json_get "$response" status)
@@ -1797,7 +1805,7 @@ get_signing_params() { # get signing parameters from key
17971805
}
17981806

17991807
graceful_exit() { # normal exit function.
1800-
exit_code=$1
1808+
exit_code="${1-0}"
18011809
clean_up
18021810
# shellcheck disable=SC2086
18031811
exit $exit_code
@@ -2055,7 +2063,7 @@ obtain_ca_resource_locations()
20552063
for suffix in "" "/directory" "/dir";
20562064
do
20572065
# Obtain CA resource locations
2058-
ca_all_loc=$(curl --user-agent "$CURL_USERAGENT" "${CA}${suffix}" 2>/dev/null)
2066+
ca_all_loc=$(curl ${_NOMETER} --user-agent "$CURL_USERAGENT" "${CA}${suffix}" 2>/dev/null)
20592067
debug "ca_all_loc from ${CA}${suffix} gives $ca_all_loc"
20602068
# APIv1
20612069
URL_new_reg=$(echo "$ca_all_loc" | grep "new-reg" | awk -F'"' '{print $4}')
@@ -2072,10 +2080,11 @@ obtain_ca_resource_locations()
20722080
fi
20732081
done
20742082

2075-
if [[ -n "$URL_new_reg" ]]; then
2076-
API=1
2077-
elif [[ -n "$URL_newAccount" ]]; then
2083+
# If a directory offers both versions, select V2.
2084+
if [[ -n "$URL_newAccount" ]]; then
20782085
API=2
2086+
elif [[ -n "$URL_new_reg" ]]; then
2087+
API=1
20792088
else
20802089
error_exit "unknown API version"
20812090
fi
@@ -2236,9 +2245,9 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
22362245
CURL_HEADER="$TEMP_DIR/curl.header"
22372246
dp="$TEMP_DIR/curl.dump"
22382247

2239-
CURL="curl "
2248+
CURL="curl ${_NOMETER} "
22402249
# shellcheck disable=SC2072
2241-
if [[ "$($CURL -V | head -1 | cut -d' ' -f2 )" > "7.33" ]]; then
2250+
if [[ ! "${_CURL_VERSION}" < "7.33" ]]; then
22422251
CURL="$CURL --http1.1 "
22432252
fi
22442253

@@ -2314,7 +2323,7 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
23142323
fi
23152324

23162325
if [[ $errcode -gt 0 || ( "$response" == "" && $url != *"revoke"* ) ]]; then
2317-
error_exit "ERROR curl \"$url\" failed with $errcode and returned $response"
2326+
error_exit "ERROR curl \"$url\" failed with $errcode and returned \"$response\""
23182327
fi
23192328

23202329
responseHeaders=$(cat "$CURL_HEADER")
@@ -2414,13 +2423,14 @@ signal_exit() { # Handle trapped signals
24142423
}
24152424

24162425
traceback() { # Print function traceback
2417-
local i d=1 lbl=" called"
2418-
echo "Traceback" >&2
2419-
for ((i=$((${#FUNCNAME[@]}-1)); i>0; i--)); do
2420-
if [[ ${i} -eq 1 ]] ; then lbl=" called traceback" ; fi
2421-
printf "%*s%s() line %d%s\n" "$d" '' "${FUNCNAME[$i]}" "${BASH_LINENO[$((i-1))]}" "$lbl" >&2
2422-
((d++))
2423-
done
2426+
local i d=1 lbl=" called"
2427+
debug "Traceback"
2428+
for ((i=$((${#FUNCNAME[@]}-1)); i>0; i--)); do
2429+
if [[ ${i} -eq 1 ]] ; then lbl=" called traceback" ; fi
2430+
debug "$(printf "%*s%s() line %d%s\n" "$d" '' "${FUNCNAME[$i]}" "${BASH_LINENO[$((i-1))]}" "$lbl")"
2431+
((d++))
2432+
done
2433+
return 0
24242434
}
24252435

24262436
urlbase64() { # urlbase64: base64 encoded string with '+' replaced with '-' and '/' replaced with '_'
@@ -2625,6 +2635,12 @@ write_openssl_conf() { # write out a minimal openssl conf
26252635
trap "signal_exit TERM" TERM HUP
26262636
trap "signal_exit INT" INT
26272637

2638+
# When running tests, use debug mode to capture intermittent faults
2639+
# Test harness will Save output in a temporary file, which is displayed if an error occurs
2640+
if [[ ${_RUNNING_TEST} -eq 1 ]] ; then
2641+
_USE_DEBUG=1
2642+
fi
2643+
26282644
# Parse command-line
26292645
while [[ -n ${1+defined} ]]; do
26302646
case $1 in
@@ -2720,6 +2736,17 @@ requires sed
27202736
requires sort
27212737
requires mktemp
27222738

2739+
# Make sure cURL doesn't display a progress meter (if it's new enough)
2740+
# --silent also does this, but suppresses warnings and informational messages too.
2741+
# TODO: see where --silent can be removed (if _NOMETER defaults to --silent for old versions?)
2742+
# This would help with debugging transfer errors.
2743+
2744+
_CURL_VERSION="$(curl -V | head -1 | cut -d' ' -f2 )"
2745+
# shellcheck disable=SC2072
2746+
if [[ ! "${_CURL_VERSION}" < "7.67" ]]; then
2747+
_NOMETER="--no-progress-meter"
2748+
fi
2749+
27232750
# Check if upgrades are available (unless they have specified -U to ignore Upgrade checks)
27242751
if [[ $_UPGRADE_CHECK -eq 1 ]]; then
27252752
check_getssl_upgrade

test/1-simple-http01-dig.bats

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load '/getssl/test/test_helper.bash'
77

88
# This is run for every test
99
setup() {
10+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1011
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1112
if [ -f /usr/bin/host ]; then
1213
mv /usr/bin/host /usr/bin/host.getssl.bak
@@ -18,6 +19,7 @@ setup() {
1819

1920

2021
teardown() {
22+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
2123
if [ -f /usr/bin/host.getssl.bak ]; then
2224
mv /usr/bin/host.getssl.bak /usr/bin/host
2325
fi

test/1-simple-http01-nslookup.bats

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load '/getssl/test/test_helper.bash'
77

88
# This is run for every test
99
setup() {
10+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1011
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1112
if [ -f /usr/bin/dig ]; then
1213
mv /usr/bin/dig /usr/bin/dig.getssl.bak
@@ -18,6 +19,7 @@ setup() {
1819

1920

2021
teardown() {
22+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
2123
if [ -f /usr/bin/dig.getssl.bak ]; then
2224
mv /usr/bin/dig.getssl.bak /usr/bin/dig
2325
fi

test/1-simple-http01-two-acl.bats

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ load '/getssl/test/test_helper.bash'
66

77

88
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
11+
}
12+
913
setup() {
14+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1015
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1116
}
1217

test/1-simple-http01.bats

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ load '/getssl/test/test_helper.bash'
66

77

88
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
11+
}
12+
913
setup() {
14+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1015
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1116
}
1217

test/10-mixed-case.bats

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ load '/getssl/test/test_helper.bash'
66

77

88
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
11+
}
12+
913
setup() {
14+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1015
if [ -z "$STAGING" ]; then
1116
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1217
fi

test/11-test--install.bats

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ load '/getssl/test/test_helper.bash'
66

77

88
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
11+
}
12+
913
setup() {
14+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
1015
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1116
}
1217

test/11-test-no-domain-storage.bats

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ load '/bats-assert/load.bash'
55
load '/getssl/test/test_helper.bash'
66

77

8+
setup() {
9+
[ ! -f $BATS_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
10+
}
11+
teardown() {
12+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_TMPDIR/failed.skip
13+
}
14+
815
@test "Check that if domain storage isn't set getssl doesn't try to delete /tmp" {
916
if [ -n "$STAGING" ]; then
1017
skip "Using staging server, skipping internal test"

0 commit comments

Comments
 (0)