Browse Source

mktemp not working correctly on Alpine Linux (added XXXXXX to template)

Fixes #612
pull/613/head
Tim Kimber 5 years ago
parent
commit
c8415df61d
No known key found for this signature in database GPG Key ID: 3E1804964E76BD18
3 changed files with 65 additions and 4 deletions
  1. +7
    -4
      getssl
  2. +47
    -0
      test/29-check-mktemp-failure.bats
  3. +11
    -0
      test/u3-mktemp-template.bats

+ 7
- 4
getssl View File

@ -621,7 +621,7 @@ check_config() { # check the config files for all obvious errors
fi
dn=0
tmplist=$(mktemp 2>/dev/null || mktemp -t getssl)
tmplist=$(mktemp 2>/dev/null || mktemp -t getssl.XXXXXX) || error_exit "mktemp failed"
for d in "${alldomains[@]}"; do # loop over domains (dn is domain number)
debug "checking domain $d"
if [[ "$(grep "^${d}$" "$tmplist")" = "$d" ]]; then
@ -695,7 +695,10 @@ check_config() { # check the config files for all obvious errors
}
check_getssl_upgrade() { # check if a more recent version of code is available available
TEMP_UPGRADE_FILE="$(mktemp 2>/dev/null || mktemp -t getssl)"
TEMP_UPGRADE_FILE="$(mktemp 2>/dev/null || mktemp -t getssl.XXXXXX)"
if [ "$TEMP_UPGRADE_FILE" == "" ]; then
error_exit "mktemp failed"
fi
curl --user-agent "$CURL_USERAGENT" --silent "$CODE_LOCATION" --output "$TEMP_UPGRADE_FILE"
errcode=$?
if [[ $errcode -eq 60 ]]; then
@ -918,7 +921,7 @@ create_csr() { # create a csr using a given key (if it doesn't already exist)
if [[ ! -s "$csr_file" ]] || [[ "$_RECREATE_CSR" == "1" ]]; then
info "creating domain csr - $csr_file"
# create a temporary config file, for portability.
tmp_conf=$(mktemp 2>/dev/null || mktemp -t getssl)
tmp_conf=$(mktemp 2>/dev/null || mktemp -t getssl) || error_exit "mktemp failed"
cat "$SSLCONF" > "$tmp_conf"
printf "[SAN]\n%s" "$SANLIST" >> "$tmp_conf"
# add OCSP Must-Staple to the domain csr
@ -1928,7 +1931,7 @@ revoke_certificate() { # revoke a certificate
ACCOUNT_KEY="$REVOKE_KEY"
# need to set the revoke key as "account_key" since it's used in send_signed_request.
get_signing_params "$REVOKE_KEY"
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t getssl)
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t getssl) || error_exit "mktemp failed"
debug "revoking from $URL_revoke"
rcertdata=$(sed '1d;$d' "$REVOKE_CERT" | tr -d "\r\n" | tr '/+' '_-' | tr -d '= ')
send_signed_request "$URL_revoke" "{\"certificate\": \"$rcertdata\",\"reason\": $REVOKE_REASON}"


+ 47
- 0
test/29-check-mktemp-failure.bats View File

@ -0,0 +1,47 @@
#! /usr/bin/env bats
load '/bats-support/load.bash'
load '/bats-assert/load.bash'
load '/getssl/test/test_helper.bash'
# This is run for every test
setup() {
if [ -z "$STAGING" ]; then
export CURL_CA_BUNDLE=/root/pebble-ca-bundle.crt
fi
}
@test "Check that getssl -c fails with an error message if mktemp fails" {
if [ -n "$STAGING" ]; then
skip "Internal test, no need to test on staging server"
else
CONFIG_FILE="getssl-http01.cfg"
fi
# set TMPDIR to an invalid directory and check for failure
export TMPDIR=/getssl.invalid.directory
setup_environment
run ${CODE_DIR}/getssl -c "$GETSSL_CMD_HOST"
assert_failure
assert_line --partial "mktemp failed"
}
@test "Check that getssl fails with an error message if mktemp fails" {
if [ -n "$STAGING" ]; then
skip "Internal test, no need to test on staging server"
else
CONFIG_FILE="getssl-http01.cfg"
fi
setup_environment
init_getssl
# set TMPDIR to an invalid directory and check for failure
export TMPDIR=/getssl.invalid.directory
create_certificate
assert_failure
assert_line --partial "mktemp failed"
}

+ 11
- 0
test/u3-mktemp-template.bats View File

@ -0,0 +1,11 @@
#! /usr/bin/env bats
load '/bats-support/load.bash'
load '/bats-assert/load.bash'
load '/getssl/test/test_helper.bash'
@test "Check mktemp -t getssl.XXXXXX works on all platforms" {
run mktemp -t getssl.XXXXXX
assert_success
}

Loading…
Cancel
Save