Skip to content

Commit dc7d2d4

Browse files
authored
Merge pull request #741 from srvrco/release2.46
Release 2.46
2 parents e4154c4 + f06e9a4 commit dc7d2d4

25 files changed

+189
-84
lines changed

getssl

+64-45
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@
280280
# 2021-11-10 Detect Solaris and use gnu tools (#701)(miesi)
281281
# 2021-11-12 Support acme-dns and fix CNAME issues (#722)(#308)
282282
# 2021-12-14 Enhancements for GoDaddy (support more levels of domain names, no longer require GODADDY_BASE, and actual deletion of resource records)
283+
# 2021-12-22 Don't show usage if run with --upgrade (#728)
284+
# 2021-12-23 Don't use +idnout if dig shows a warning (#688)
285+
# 2022-01-06 Support --account-id (#716)(2.46)
283286
# ----------------------------------------------------------------------------------------
284287

285288
case :$SHELLOPTS: in
@@ -288,7 +291,7 @@ esac
288291

289292
PROGNAME=${0##*/}
290293
PROGDIR="$(cd "$(dirname "$0")" || exit; pwd -P;)"
291-
VERSION="2.45"
294+
VERSION="2.46"
292295

293296
# defaults
294297
ACCOUNT_KEY_LENGTH=4096
@@ -358,6 +361,7 @@ _QUIET=0
358361
_RECREATE_CSR=0
359362
_REDIRECT_OUTPUT="1>/dev/null 2>&1"
360363
_REVOKE=0
364+
_SHOW_ACCOUNT_ID=0
361365
_TEST_SKIP_CNAME_CALL=0
362366
_TEST_SKIP_SOA_CALL=0
363367
_UPGRADE=0
@@ -842,7 +846,7 @@ check_getssl_upgrade() { # check if a more recent release is available
842846
# shellcheck disable=SC2086
843847
status=$(curl ${_NOMETER:---silent} -w "%{http_code}" --user-agent "$CURL_USERAGENT" "$CODE_LOCATION" --output "$TEMP_UPGRADE_FILE")
844848
errcode=$?
845-
debug errcode=$errcode
849+
debug curl errcode=$errcode
846850

847851
if [[ $errcode -eq 60 ]]; then
848852
error_exit "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
@@ -1274,39 +1278,42 @@ error_exit() { # give error message on error exit
12741278
}
12751279

12761280
find_dns_utils() {
1277-
HAS_NSLOOKUP=false
1278-
HAS_DIG_OR_DRILL=""
1279-
DIG_SUPPORTS_NOIDNOUT=false
1280-
HAS_HOST=false
1281-
if [[ -n "$(command -v nslookup 2>/dev/null)" ]]; then
1282-
debug "HAS NSLOOKUP=true"
1283-
HAS_NSLOOKUP=true
1284-
fi
1285-
1286-
if [[ -n "$(command -v drill 2>/dev/null)" ]]; then
1287-
HAS_DIG_OR_DRILL="drill"
1288-
elif [[ -n "$(command -v dig 2>/dev/null)" ]] && dig >/dev/null 2>&1; then
1289-
if dig -r >/dev/null 2>&1; then
1290-
# use dig -r so ~/.digrc is not used
1291-
HAS_DIG_OR_DRILL="dig -r"
1292-
else
1293-
HAS_DIG_OR_DRILL="dig"
1294-
fi
1281+
HAS_NSLOOKUP=false
1282+
HAS_DIG_OR_DRILL=""
1283+
DIG_SUPPORTS_NOIDNOUT=false
1284+
HAS_HOST=false
1285+
if [[ -n "$(command -v nslookup 2>/dev/null)" ]]; then
1286+
debug "HAS NSLOOKUP=true"
1287+
HAS_NSLOOKUP=true
1288+
fi
1289+
1290+
if [[ -n "$(command -v drill 2>/dev/null)" ]]; then
1291+
HAS_DIG_OR_DRILL="drill"
1292+
elif [[ -n "$(command -v dig 2>/dev/null)" ]] && dig >/dev/null 2>&1; then
1293+
if dig -r >/dev/null 2>&1; then
1294+
# use dig -r so ~/.digrc is not used
1295+
HAS_DIG_OR_DRILL="dig -r"
1296+
else
1297+
HAS_DIG_OR_DRILL="dig"
12951298
fi
1299+
fi
12961300

1297-
if [[ -n "$HAS_DIG_OR_DRILL" ]]; then
1298-
if $HAS_DIG_OR_DRILL +noidnout >/dev/null 2>&1; then
1299-
DIG_SUPPORTS_NOIDNOUT=true
1300-
fi
1301-
1302-
debug "HAS DIG_OR_DRILL=$HAS_DIG_OR_DRILL"
1303-
debug "DIG_SUPPORTS_NOIDNOUT=$DIG_SUPPORTS_NOIDNOUT"
1301+
if [[ -n "$HAS_DIG_OR_DRILL" ]]; then
1302+
if dig_output=$($HAS_DIG_OR_DRILL +noidnout localhost 2>&1 >/dev/null); then
1303+
# dig +noidnout on Ubuntu 18 succeeds, but outputs warning message to stderr - issue #688)
1304+
if [[ "$dig_output" != ";; IDN support not enabled" ]]; then
1305+
DIG_SUPPORTS_NOIDNOUT=true
1306+
fi
13041307
fi
13051308

1306-
if [[ -n "$(command -v host 2>/dev/null)" ]]; then
1307-
debug "HAS HOST=true"
1308-
HAS_HOST=true
1309-
fi
1309+
debug "HAS DIG_OR_DRILL=$HAS_DIG_OR_DRILL"
1310+
debug "DIG_SUPPORTS_NOIDNOUT=$DIG_SUPPORTS_NOIDNOUT"
1311+
fi
1312+
1313+
if [[ -n "$(command -v host 2>/dev/null)" ]]; then
1314+
debug "HAS HOST=true"
1315+
HAS_HOST=true
1316+
fi
13101317
}
13111318

13121319
find_ftp_command() {
@@ -1955,13 +1962,14 @@ help_message() { # print out the help message
19551962
-i, --install Install certificates and reload service
19561963
-q, --quiet Quiet mode (only outputs on error, success of new cert, or getssl was upgraded)
19571964
-Q, --mute Like -q, but also mute notification about successful upgrade
1958-
-r, --revoke "cert" "key" [CA_server] Revoke a certificate (the cert and key are required)
1965+
-r, --revoke "cert" "key" [CA_server] Revoke a certificate (the cert and key are required)
19591966
-u, --upgrade Upgrade getssl if a more recent version is available - can be used with or without domain(s)
19601967
-X, --experimental tag Upgrade to experimental releases, specified by tag (e.g. v9.43)
19611968
-U, --nocheck Do not check if a more recent version is available
19621969
-v --version Display current version of $PROGNAME
19631970
-w working_dir "Working directory"
19641971
--preferred-chain "chain" Use an alternate chain for the certificate
1972+
--account-id Display account id and exit
19651973
19661974
_EOF_
19671975
}
@@ -2591,7 +2599,7 @@ urlbase64_decode() {
25912599
usage() { # echos out the program usage
25922600
echo "Usage: $PROGNAME [-h|--help] [-d|--debug] [-c|--create] [-f|--force] [-a|--all] [-q|--quiet]"\
25932601
"[-Q|--mute] [-u|--upgrade] [-X|--experimental tag] [-U|--nocheck] [-r|--revoke cert key] [-w working_dir]"\
2594-
"[--preferred-chain chain] domain"
2602+
"[--preferred-chain chain] [--account-id] domain"
25952603
}
25962604

25972605
write_domain_template() { # write out a template file for a domain.
@@ -2825,6 +2833,8 @@ while [[ -n ${1+defined} ]]; do
28252833
shift; WORKING_DIR="$1" ;;
28262834
-preferred-chain | --preferred-chain)
28272835
shift; PREFERRED_CHAIN="$1" ;;
2836+
--account-id)
2837+
_SHOW_ACCOUNT_ID=1 ;;
28282838
--source)
28292839
return ;;
28302840
-*)
@@ -2897,9 +2907,13 @@ if [[ $_UPGRADE_CHECK -eq 1 ]]; then
28972907
check_getssl_upgrade
28982908
# if nothing in command line and no revocation and not only config check,
28992909
# then exit after upgrade
2900-
if [[ -z "$DOMAIN" ]] && [[ ${_CHECK_ALL} -ne 1 ]] && [[ ${_REVOKE} -ne 1 ]] && [ "${_ONLY_CHECK_CONFIG}" -ne 1 ]; then
2910+
if [[ -z "$DOMAIN" ]] \
2911+
&& [[ ${_CHECK_ALL} -ne 1 ]] \
2912+
&& [[ ${_REVOKE} -ne 1 ]] \
2913+
&& [ "${_ONLY_CHECK_CONFIG}" -ne 1 ] \
2914+
&& [[ ${_SHOW_ACCOUNT_ID} -ne 1 ]]; then
29012915
# if nothing in command line, print help before exit.
2902-
if [[ -z "$DOMAIN" ]] && [[ ${_CHECK_ALL} -ne 1 ]]; then
2916+
if [[ -z "$DOMAIN" ]] && [[ ${_CHECK_ALL} -ne 1 ]] && [[ ${_UPGRADE} -ne 1 ]]; then
29032917
help_message
29042918
fi
29052919
graceful_exit
@@ -3130,7 +3144,7 @@ if [[ $API -eq 2 ]]; then
31303144
fi
31313145

31323146
# if check_remote is true then connect and obtain the current certificate (if not forcing renewal)
3133-
if [[ "${CHECK_REMOTE}" == "true" ]] && [[ $_FORCE_RENEW -eq 0 ]]; then
3147+
if [[ "${CHECK_REMOTE}" == "true" ]] && [[ $_FORCE_RENEW -eq 0 ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]]; then
31343148
real_d=${DOMAIN##\*.}
31353149
debug "getting certificate for $DOMAIN from remote server ($real_d)"
31363150
if [[ "$DUAL_RSA_ECDSA" == "true" ]]; then
@@ -3249,7 +3263,7 @@ if [[ "$DUAL_RSA_ECDSA" == "false" ]] && [[ -s "$DOMAIN_DIR/${DOMAIN}.key" ]]; t
32493263
fi
32503264

32513265
# if there is an existing certificate file, check details.
3252-
if [[ -s "$CERT_FILE" ]]; then
3266+
if [[ -s "$CERT_FILE" ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]]; then
32533267
debug "certificate $CERT_FILE exists"
32543268
enddate=$(openssl x509 -in "$CERT_FILE" -noout -enddate 2>/dev/null| cut -d= -f 2-)
32553269
debug "local cert is valid until $enddate"
@@ -3277,7 +3291,7 @@ if [[ -s "$CERT_FILE" ]]; then
32773291
fi
32783292
# end of .... if there is an existing certificate file, check details.
32793293

3280-
if [[ ! -t 0 ]] && [[ "$PREVENT_NON_INTERACTIVE_RENEWAL" = "true" ]]; then
3294+
if [[ ! -t 0 ]] && [[ "$PREVENT_NON_INTERACTIVE_RENEWAL" = "true" ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]]; then
32813295
errmsg="$DOMAIN due for renewal,"
32823296
errmsg="${errmsg} but not completed due to PREVENT_NON_INTERACTIVE_RENEWAL=true in config"
32833297
error_exit "$errmsg"
@@ -3326,16 +3340,16 @@ info "Registering account"
33263340
# send the request to the ACME server.
33273341
if [[ $API -eq 1 ]]; then
33283342
if [[ "$ACCOUNT_EMAIL" ]] ; then
3329-
regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
3343+
regjson='{"resource": "new-reg", "contact": ["mailto: '$ACCOUNT_EMAIL'"], "agreement": "'$AGREEMENT'"}'
33303344
else
3331-
regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
3345+
regjson='{"resource": "new-reg", "agreement": "'$AGREEMENT'"}'
33323346
fi
33333347
send_signed_request "$URL_new_reg" "$regjson"
33343348
elif [[ $API -eq 2 ]]; then
33353349
if [[ "$ACCOUNT_EMAIL" ]] ; then
3336-
regjson='{"termsOfServiceAgreed": true, "contact": ["mailto: '$ACCOUNT_EMAIL'"]}'
3350+
regjson='{"termsOfServiceAgreed": true, "contact": ["mailto: '$ACCOUNT_EMAIL'"]}'
33373351
else
3338-
regjson='{"termsOfServiceAgreed": true}'
3352+
regjson='{"termsOfServiceAgreed": true}'
33393353
fi
33403354
send_signed_request "$URL_newAccount" "$regjson"
33413355
else
@@ -3346,19 +3360,24 @@ fi
33463360
if [[ "$code" == "" ]] || [[ "$code" == '201' ]] ; then
33473361
info "Registered"
33483362
KID=$(echo "$responseHeaders" | grep -i "^location" | awk '{print $2}'| tr -d '\r\n ')
3349-
debug "KID=_$KID}_"
3363+
debug "AccountId=$KID}"
33503364
echo "$response" > "$TEMP_DIR/account.json"
33513365
elif [[ "$code" == '409' ]] ; then
33523366
KID=$(echo "$responseHeaders" | grep -i "^location" | awk '{print $2}'| tr -d '\r\n ')
33533367
debug responseHeaders "$responseHeaders"
3354-
debug "Already registered KID=$KID"
3368+
debug "Already registered, AccountId=$KID"
33553369
elif [[ "$code" == '200' ]] ; then
33563370
KID=$(echo "$responseHeaders" | grep -i "^location" | awk '{print $2}'| tr -d '\r\n ')
33573371
debug responseHeaders "$responseHeaders"
3358-
debug "Already registered account, KID=${KID}"
3372+
debug "Already registered account, AccountId=${KID}"
33593373
else
33603374
error_exit "Error registering account ...$responseHeaders ... $(json_get "$response" detail)"
33613375
fi
3376+
3377+
if [[ ${_SHOW_ACCOUNT_ID} -eq 1 ]]; then
3378+
echo "Account Id is: $KID"
3379+
graceful_exit
3380+
fi
33623381
# end of registering account with CA
33633382

33643383
# verify each domain

test/0-test-usage.bats

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env bats
2+
3+
load '/bats-support/load.bash'
4+
load '/bats-assert/load.bash'
5+
load '/getssl/test/test_helper.bash'
6+
7+
8+
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_RUN_TMPDIR/failed.skip
11+
}
12+
13+
setup() {
14+
[ ! -f $BATS_RUN_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
15+
#export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
16+
}
17+
18+
19+
@test "Run getssl without any arguments to verify the usage message is shown" {
20+
if [ -n "$STAGING" ]; then
21+
skip "Using staging server, skipping internal test"
22+
fi
23+
run ${CODE_DIR}/getssl
24+
assert_line --partial "Usage: getssl"
25+
assert_success
26+
}
27+
28+
29+
@test "Run getssl with --nocheck and verify the usage message is shown" {
30+
if [ -n "$STAGING" ]; then
31+
skip "Using staging server, skipping internal test"
32+
fi
33+
run ${CODE_DIR}/getssl --nocheck
34+
assert_line --partial "Usage: getssl"
35+
assert_success
36+
}
37+
38+
39+
@test "Run getssl with --upgrade and verify the usage message is NOT shown" {
40+
if [ -n "$STAGING" ]; then
41+
skip "Using staging server, skipping internal test"
42+
fi
43+
run ${CODE_DIR}/getssl --upgrade
44+
refute_output
45+
assert_success
46+
}

test/11-test--install.bats

+18-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ setup() {
1515
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
1616
}
1717

18+
setup_file() {
19+
# Fail if not running in docker and /etc/getssl already exists
20+
TEST_FAILED=0
21+
if [ -d /etc/getssl ]; then
22+
echo "Test failed: /etc/getssl already exists" >&3
23+
TEST_FAILED=1
24+
touch $BATS_RUN_TMPDIR/failed.skip
25+
return 1
26+
fi
27+
}
28+
29+
teardown_file() {
30+
# Cleanup after tests
31+
if [ ${TEST_FAILED} == 0 ] && [ -d /etc/getssl ]; then
32+
rm -rf /etc/getssl
33+
fi
34+
}
35+
1836
@test "Check that config files in /etc/getssl works" {
1937
if [ -n "$STAGING" ]; then
2038
skip "Using staging server, skipping internal test"
@@ -23,9 +41,6 @@ setup() {
2341
CONFIG_FILE="getssl-http01.cfg"
2442
setup_environment
2543

26-
# Fail if not running in docker and /etc/getssl already exists
27-
refute [ -d /etc/getssl ]
28-
2944
# Create /etc/getssl/$DOMAIN
3045
mkdir -p /etc/getssl/${GETSSL_CMD_HOST}
3146

@@ -62,7 +77,4 @@ setup() {
6277
assert_line --partial 'copying domain certificate to'
6378
assert_line --partial 'copying private key to'
6479
assert_line --partial 'copying CA certificate to'
65-
66-
# Cleanup previous test
67-
rm -rf /etc/getssl
6880
}

test/40-cname-dns01-nslookup.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ EOF
6363
create_certificate
6464
assert_success
6565
assert_output --partial "nslookup -type=txt"
66-
check_output_for_errors
66+
#check_output_for_errors
6767
}
6868

6969

test/41-show-account-id.bats

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/env bats
2+
3+
load '/bats-support/load.bash'
4+
load '/bats-assert/load.bash'
5+
load '/getssl/test/test_helper.bash'
6+
7+
8+
# This is run for every test
9+
teardown() {
10+
[ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_RUN_TMPDIR/failed.skip
11+
}
12+
13+
setup() {
14+
[ ! -f $BATS_RUN_TMPDIR/failed.skip ] || skip "skipping tests after first failure"
15+
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
16+
}
17+
18+
19+
@test "Create new certificate using HTTP-01 verification (any dns tool)" {
20+
if [ -n "$STAGING" ]; then
21+
skip "Using staging server, skipping internal test"
22+
fi
23+
CONFIG_FILE="getssl-http01.cfg"
24+
setup_environment
25+
init_getssl
26+
create_certificate
27+
assert_success
28+
29+
run ${CODE_DIR}/getssl --account-id ${GETSSL_HOST}
30+
assert_line --partial "Account Id is:"
31+
assert_success
32+
}

test/Dockerfile-alpine

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN chown -R ftpuser.www-data /var/www
2323
RUN chmod g+w -R /var/www
2424

2525
# BATS (Bash Automated Testings)
26-
RUN git clone --depth 1 https://github.com/bats-core/bats-core.git /bats-core --branch v1.2.1
26+
RUN git clone --depth 1 https://github.com/bats-core/bats-core.git /bats-core
2727
RUN git clone --depth 1 https://github.com/bats-core/bats-support /bats-support
2828
RUN git clone --depth 1 https://github.com/bats-core/bats-assert /bats-assert
2929
RUN /bats-core/install.sh /usr/local

test/Dockerfile-bash4-0

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN chown -R ftpuser.www-data /var/www
2424
RUN chmod g+w -R /var/www
2525

2626
# BATS (Bash Automated Testings)
27-
RUN git clone https://github.com/bats-core/bats-core.git /bats-core --branch v1.2.1
27+
RUN git clone https://github.com/bats-core/bats-core.git /bats-core
2828
RUN git clone https://github.com/bats-core/bats-support /bats-support
2929
RUN git clone https://github.com/bats-core/bats-assert /bats-assert
3030
RUN /bats-core/install.sh /usr/local

test/Dockerfile-bash4-2

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN chown -R ftpuser.www-data /var/www
2424
RUN chmod g+w -R /var/www
2525

2626
# BATS (Bash Automated Testings)
27-
RUN git clone https://github.com/bats-core/bats-core.git /bats-core --branch v1.2.1
27+
RUN git clone https://github.com/bats-core/bats-core.git /bats-core
2828
RUN git clone https://github.com/bats-core/bats-support /bats-support
2929
RUN git clone https://github.com/bats-core/bats-assert /bats-assert
3030
RUN /bats-core/install.sh /usr/local

0 commit comments

Comments
 (0)