3 # dehydrated by lukas2511
4 # Source: https://github.com/lukas2511/dehydrated
6 # This script is licensed under The MIT License (see LICENSE for more information).
11 [[ -n "${ZSH_VERSION:-}" ]] && set -o SH_WORD_SPLIT && set +o FUNCTION_ARGZERO
12 umask 077 # paranoid umask, we're creating private keys
14 # Find directory in which this script is stored by traversing all symbolic links
16 while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
17 DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
18 SOURCE="$(readlink "$SOURCE")"
19 [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
21 SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
23 BASEDIR="${SCRIPTDIR}"
25 # Create (identifiable) temporary files
27 # shellcheck disable=SC2068
28 mktemp ${@:-} "${TMPDIR:-/tmp}/dehydrated-XXXXXX"
31 # Check for script dependencies
32 check_dependencies() {
33 # just execute some dummy and/or version commands to see if required tools exist and are actually usable
34 openssl version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary."
35 _sed "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions."
36 command -v grep > /dev/null 2>&1 || _exiterr "This script requires grep."
37 command -v mktemp > /dev/null 2>&1 || _exiterr "This script requires mktemp."
38 command -v diff > /dev/null 2>&1 || _exiterr "This script requires diff."
40 # curl returns with an error code in some ancient versions so we have to catch that
42 curl -V > /dev/null 2>&1
45 if [[ ! "${retcode}" = "0" ]] && [[ ! "${retcode}" = "2" ]]; then
46 _exiterr "This script requires curl."
51 __KEY_ALGO="${KEY_ALGO}"
52 __OCSP_MUST_STAPLE="${OCSP_MUST_STAPLE}"
53 __PRIVATE_KEY_RENEW="${PRIVATE_KEY_RENEW}"
54 __KEYSIZE="${KEYSIZE}"
55 __CHALLENGETYPE="${CHALLENGETYPE}"
57 __WELLKNOWN="${WELLKNOWN}"
58 __HOOK_CHAIN="${HOOK_CHAIN}"
59 __OPENSSL_CNF="${OPENSSL_CNF}"
60 __RENEW_DAYS="${RENEW_DAYS}"
61 __IP_VERSION="${IP_VERSION}"
65 KEY_ALGO="${__KEY_ALGO}"
66 OCSP_MUST_STAPLE="${__OCSP_MUST_STAPLE}"
67 PRIVATE_KEY_RENEW="${__PRIVATE_KEY_RENEW}"
68 KEYSIZE="${__KEYSIZE}"
69 CHALLENGETYPE="${__CHALLENGETYPE}"
71 WELLKNOWN="${__WELLKNOWN}"
72 HOOK_CHAIN="${__HOOK_CHAIN}"
73 OPENSSL_CNF="${__OPENSSL_CNF}"
74 RENEW_DAYS="${__RENEW_DAYS}"
75 IP_VERSION="${__IP_VERSION}"
78 # verify configuration values
80 [[ "${CHALLENGETYPE}" =~ (http-01|dns-01) ]] || _exiterr "Unknown challenge type ${CHALLENGETYPE}... can not continue."
81 if [[ "${CHALLENGETYPE}" = "dns-01" ]] && [[ -z "${HOOK}" ]]; then
82 _exiterr "Challenge type dns-01 needs a hook script for deployment... can not continue."
84 if [[ "${CHALLENGETYPE}" = "http-01" && ! -d "${WELLKNOWN}" ]]; then
85 _exiterr "WELLKNOWN directory doesn't exist, please create ${WELLKNOWN} and set appropriate permissions."
87 [[ "${KEY_ALGO}" =~ ^(rsa|prime256v1|secp384r1)$ ]] || _exiterr "Unknown public key algorithm ${KEY_ALGO}... can not continue."
88 if [[ -n "${IP_VERSION}" ]]; then
89 [[ "${IP_VERSION}" = "4" || "${IP_VERSION}" = "6" ]] || _exiterr "Unknown IP version ${IP_VERSION}... can not continue."
93 # Setup default config values, search for and load configuration files
95 # Check for config in various locations
96 if [[ -z "${CONFIG:-}" ]]; then
97 for check_config in "/etc/dehydrated" "/usr/local/etc/dehydrated" "${PWD}" "${SCRIPTDIR}"; do
98 if [[ -f "${check_config}/config" ]]; then
99 BASEDIR="${check_config}"
100 CONFIG="${check_config}/config"
107 CA="https://acme-v01.api.letsencrypt.org/directory"
108 CA_TERMS="https://acme-v01.api.letsencrypt.org/terms"
112 CHALLENGETYPE="http-01"
121 PRIVATE_KEY_RENEW="yes"
122 PRIVATE_KEY_ROLLOVER="no"
124 OPENSSL_CNF="$(openssl version -d | cut -d\" -f2)/openssl.cnf"
127 OCSP_MUST_STAPLE="no"
130 if [[ -z "${CONFIG:-}" ]]; then
132 echo "# !! WARNING !! No main config file found, using default config!" >&2
134 elif [[ -f "${CONFIG}" ]]; then
135 echo "# INFO: Using main config file ${CONFIG}"
136 BASEDIR="$(dirname "${CONFIG}")"
137 # shellcheck disable=SC1090
140 _exiterr "Specified config file doesn't exist."
143 if [[ -n "${CONFIG_D}" ]]; then
144 if [[ ! -d "${CONFIG_D}" ]]; then
145 _exiterr "The path ${CONFIG_D} specified for CONFIG_D does not point to a directory." >&2
148 for check_config_d in "${CONFIG_D}"/*.sh; do
149 if [[ ! -e "${check_config_d}" ]]; then
150 echo "# !! WARNING !! Extra configuration directory ${CONFIG_D} exists, but no configuration found in it." >&2
152 elif [[ -f "${check_config_d}" ]] && [[ -r "${check_config_d}" ]]; then
153 echo "# INFO: Using additional config file ${check_config_d}"
154 # shellcheck disable=SC1090
155 . "${check_config_d}"
157 _exiterr "Specified additional config ${check_config_d} is not readable or not a file at all." >&2
162 # Remove slash from end of BASEDIR. Mostly for cleaner outputs, doesn't change functionality.
163 BASEDIR="${BASEDIR%%/}"
165 # Check BASEDIR and set default variables
166 [[ -d "${BASEDIR}" ]] || _exiterr "BASEDIR does not exist: ${BASEDIR}"
168 CAHASH="$(echo "${CA}" | urlbase64)"
169 [[ -z "${ACCOUNTDIR}" ]] && ACCOUNTDIR="${BASEDIR}/accounts"
170 mkdir -p "${ACCOUNTDIR}/${CAHASH}"
171 [[ -f "${ACCOUNTDIR}/${CAHASH}/config" ]] && . "${ACCOUNTDIR}/${CAHASH}/config"
172 ACCOUNT_KEY="${ACCOUNTDIR}/${CAHASH}/account_key.pem"
173 ACCOUNT_KEY_JSON="${ACCOUNTDIR}/${CAHASH}/registration_info.json"
175 if [[ -f "${BASEDIR}/private_key.pem" ]] && [[ ! -f "${ACCOUNT_KEY}" ]]; then
176 echo "! Moving private_key.pem to ${ACCOUNT_KEY}"
177 mv "${BASEDIR}/private_key.pem" "${ACCOUNT_KEY}"
179 if [[ -f "${BASEDIR}/private_key.json" ]] && [[ ! -f "${ACCOUNT_KEY_JSON}" ]]; then
180 echo "! Moving private_key.json to ${ACCOUNT_KEY_JSON}"
181 mv "${BASEDIR}/private_key.json" "${ACCOUNT_KEY_JSON}"
184 [[ -z "${CERTDIR}" ]] && CERTDIR="${BASEDIR}/certs"
185 [[ -z "${DOMAINS_TXT}" ]] && DOMAINS_TXT="${BASEDIR}/domains.txt"
186 [[ -z "${WELLKNOWN}" ]] && WELLKNOWN="/var/www/dehydrated"
187 [[ -z "${LOCKFILE}" ]] && LOCKFILE="${BASEDIR}/lock"
188 [[ -n "${PARAM_LOCKFILE_SUFFIX:-}" ]] && LOCKFILE="${LOCKFILE}-${PARAM_LOCKFILE_SUFFIX}"
189 [[ -n "${PARAM_NO_LOCK:-}" ]] && LOCKFILE=""
191 [[ -n "${PARAM_HOOK:-}" ]] && HOOK="${PARAM_HOOK}"
192 [[ -n "${PARAM_CERTDIR:-}" ]] && CERTDIR="${PARAM_CERTDIR}"
193 [[ -n "${PARAM_CHALLENGETYPE:-}" ]] && CHALLENGETYPE="${PARAM_CHALLENGETYPE}"
194 [[ -n "${PARAM_KEY_ALGO:-}" ]] && KEY_ALGO="${PARAM_KEY_ALGO}"
195 [[ -n "${PARAM_OCSP_MUST_STAPLE:-}" ]] && OCSP_MUST_STAPLE="${PARAM_OCSP_MUST_STAPLE}"
196 [[ -n "${PARAM_IP_VERSION:-}" ]] && IP_VERSION="${PARAM_IP_VERSION}"
206 # Lockfile handling (prevents concurrent access)
207 if [[ -n "${LOCKFILE}" ]]; then
208 LOCKDIR="$(dirname "${LOCKFILE}")"
209 [[ -w "${LOCKDIR}" ]] || _exiterr "Directory ${LOCKDIR} for LOCKFILE ${LOCKFILE} is not writable, aborting."
210 ( set -C; date > "${LOCKFILE}" ) 2>/dev/null || _exiterr "Lock file '${LOCKFILE}' present, aborting."
211 remove_lock() { rm -f "${LOCKFILE}"; }
212 trap 'remove_lock' EXIT
216 CA_DIRECTORY="$(http_request get "${CA}")"
217 CA_NEW_CERT="$(printf "%s" "${CA_DIRECTORY}" | get_json_string_value new-cert)" &&
218 CA_NEW_AUTHZ="$(printf "%s" "${CA_DIRECTORY}" | get_json_string_value new-authz)" &&
219 CA_NEW_REG="$(printf "%s" "${CA_DIRECTORY}" | get_json_string_value new-reg)" &&
220 # shellcheck disable=SC2015
221 CA_REVOKE_CERT="$(printf "%s" "${CA_DIRECTORY}" | get_json_string_value revoke-cert)" ||
222 _exiterr "Problem retrieving ACME/CA-URLs, check if your configured CA points to the directory entrypoint."
224 # Export some environment variables to be used in hook script
225 export WELLKNOWN BASEDIR CERTDIR CONFIG COMMAND
227 # Checking for private key ...
228 register_new_key="no"
229 if [[ -n "${PARAM_ACCOUNT_KEY:-}" ]]; then
230 # a private key was specified from the command line so use it for this run
231 echo "Using private key ${PARAM_ACCOUNT_KEY} instead of account key"
232 ACCOUNT_KEY="${PARAM_ACCOUNT_KEY}"
233 ACCOUNT_KEY_JSON="${PARAM_ACCOUNT_KEY}.json"
235 # Check if private account key exists, if it doesn't exist yet generate a new one (rsa key)
236 if [[ ! -e "${ACCOUNT_KEY}" ]]; then
237 REAL_LICENSE="$(http_request head "${CA_TERMS}" | (grep Location: || true) | awk -F ': ' '{print $2}' | tr -d '\n\r')"
238 if [[ -z "${REAL_LICENSE}" ]]; then
240 printf 'Error retrieving terms of service from certificate authority.\n'
241 printf 'Please set LICENSE in config manually.\n'
244 if [[ ! "${LICENSE}" = "${REAL_LICENSE}" ]]; then
245 if [[ "${PARAM_ACCEPT_TERMS:-}" = "yes" ]]; then
246 LICENSE="${REAL_LICENSE}"
249 printf 'To use dehydrated with this certificate authority you have to agree to their terms of service which you can find here: %s\n\n' "${REAL_LICENSE}"
250 printf 'To accept these terms of service run `%s --register --accept-terms`.\n' "${0}"
255 echo "+ Generating account key..."
256 _openssl genrsa -out "${ACCOUNT_KEY}" "${KEYSIZE}"
257 register_new_key="yes"
260 openssl rsa -in "${ACCOUNT_KEY}" -check 2>/dev/null > /dev/null || _exiterr "Account key is not valid, can not continue."
262 # Get public components from private key and calculate thumbprint
263 pubExponent64="$(printf '%x' "$(openssl rsa -in "${ACCOUNT_KEY}" -noout -text | awk '/publicExponent/ {print $2}')" | hex2bin | urlbase64)"
264 pubMod64="$(openssl rsa -in "${ACCOUNT_KEY}" -noout -modulus | cut -d'=' -f2 | hex2bin | urlbase64)"
266 thumbprint="$(printf '{"e":"%s","kty":"RSA","n":"%s"}' "${pubExponent64}" "${pubMod64}" | openssl dgst -sha256 -binary | urlbase64)"
268 # If we generated a new private key in the step above we have to register it with the acme-server
269 if [[ "${register_new_key}" = "yes" ]]; then
270 echo "+ Registering account key with ACME server..."
271 [[ ! -z "${CA_NEW_REG}" ]] || _exiterr "Certificate authority doesn't allow registrations."
272 # If an email for the contact has been provided then adding it to the registration request
274 if [[ -n "${CONTACT_EMAIL}" ]]; then
275 (signed_request "${CA_NEW_REG}" '{"resource": "new-reg", "contact":["mailto:'"${CONTACT_EMAIL}"'"], "agreement": "'"$LICENSE"'"}' > "${ACCOUNT_KEY_JSON}") || FAILED=true
277 (signed_request "${CA_NEW_REG}" '{"resource": "new-reg", "agreement": "'"$LICENSE"'"}' > "${ACCOUNT_KEY_JSON}") || FAILED=true
279 if [[ "${FAILED}" = "true" ]]; then
282 echo "Error registering account key. See message above for more information."
283 rm "${ACCOUNT_KEY}" "${ACCOUNT_KEY_JSON}"
290 # Different sed version for different os types...
292 if [[ "${OSTYPE}" = "Linux" ]]; then
299 # Print error message and exit with error
301 echo "ERROR: ${1}" >&2
305 # Remove newlines and whitespace from json
307 tr -d '\r\n' | _sed -e 's/ +/ /g' -e 's/\{ /{/g' -e 's/ \}/}/g' -e 's/\[ /[/g' -e 's/ \]/]/g'
310 # Encode data as url-safe formatted base64
312 # urlbase64: base64 encoded string with '+' replaced with '-' and '/' replaced with '_'
313 openssl base64 -e | tr -d '\n\r' | _sed -e 's:=*$::g' -e 'y:+/:-_:'
316 # Convert hex string to binary data
318 # Remove spaces, add leading zero, escape as hex string and parse with printf
319 printf -- "$(cat | _sed -e 's/[[:space:]]//g' -e 's/^(.(.{2})*)$/0\1/' -e 's/(.{2})/\\x\1/g')"
322 # Get string value from json dictionary
323 get_json_string_value() {
325 filter=$(printf 's/.*"%s": *"\([^"]*\)".*/\\1/p' "$1")
331 filter='s/\[[^][]*\]/null/g'
332 # remove three levels of nested arrays
333 sed -e "${filter}" -e "${filter}" -e "${filter}"
336 # OpenSSL writes to stderr/stdout even when there are no errors. So just
337 # display the output if the exit code was != 0 to simplify debugging.
340 out="$(openssl "${@}" 2>&1)"
343 if [[ ${res} -ne 0 ]]; then
344 echo " + ERROR: failed to run $* (Exitcode: ${res})" >&2
353 # Send http(s) request with specified method
355 tempcont="$(_mktemp)"
357 if [[ -n "${IP_VERSION:-}" ]]; then
358 ip_version="-${IP_VERSION}"
362 if [[ "${1}" = "head" ]]; then
363 statuscode="$(curl ${ip_version:-} -A "dehydrated" -s -w "%{http_code}" -o "${tempcont}" "${2}" -I)"
365 elif [[ "${1}" = "get" ]]; then
366 statuscode="$(curl ${ip_version:-} -A "dehydrated" -s -w "%{http_code}" -o "${tempcont}" "${2}")"
368 elif [[ "${1}" = "post" ]]; then
369 statuscode="$(curl ${ip_version:-} -A "dehydrated" -s -w "%{http_code}" -o "${tempcont}" "${2}" -d "${3}")"
373 _exiterr "Unknown request method: ${1}"
377 if [[ ! "${curlret}" = "0" ]]; then
378 _exiterr "Problem connecting to server (${1} for ${2}; curl returned with ${curlret})"
381 if [[ ! "${statuscode:0:1}" = "2" ]]; then
382 if [[ ! "${2}" = "${CA_TERMS}" ]] || [[ ! "${statuscode:0:1}" = "3" ]]; then
383 echo " + ERROR: An error occurred while sending ${1}-request to ${2} (Status ${statuscode})" >&2
386 cat "${tempcont}" >&2
390 # An exclusive hook for the {1}-request error might be useful (e.g., for sending an e-mail to admins)
391 if [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]]; then
392 errtxt=`cat ${tempcont}`
393 "${HOOK}" "request_failure" "${statuscode}" "${errtxt}" "${1}"
398 # Wait for hook script to clean the challenge if used
399 if [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]] && [[ -n "${challenge_token:+set}" ]]; then
400 "${HOOK}" "clean_challenge" '' "${challenge_token}" "${keyauth}"
403 # remove temporary domains.txt file if used
404 [[ -n "${PARAM_DOMAIN:-}" && -n "${DOMAINS_TXT:-}" ]] && rm "${DOMAINS_TXT}"
413 # Send signed request
415 # Encode payload as urlbase64
416 payload64="$(printf '%s' "${2}" | urlbase64)"
418 # Retrieve nonce from acme-server
419 nonce="$(http_request head "${CA}" | grep Replay-Nonce: | awk -F ': ' '{print $2}' | tr -d '\n\r')"
421 # Build header with just our public key and algorithm information
422 header='{"alg": "RS256", "jwk": {"e": "'"${pubExponent64}"'", "kty": "RSA", "n": "'"${pubMod64}"'"}}'
424 # Build another header which also contains the previously received nonce and encode it as urlbase64
425 protected='{"alg": "RS256", "jwk": {"e": "'"${pubExponent64}"'", "kty": "RSA", "n": "'"${pubMod64}"'"}, "nonce": "'"${nonce}"'"}'
426 protected64="$(printf '%s' "${protected}" | urlbase64)"
428 # Sign header with nonce and our payload with our private key and encode signature as urlbase64
429 signed64="$(printf '%s' "${protected64}.${payload64}" | openssl dgst -sha256 -sign "${ACCOUNT_KEY}" | urlbase64)"
431 # Send header + extended header + payload + signature to the acme-server
432 data='{"header": '"${header}"', "protected": "'"${protected64}"'", "payload": "'"${payload64}"'", "signature": "'"${signed64}"'"}'
434 http_request post "${1}" "${data}"
437 # Extracts all subject names from a CSR
438 # Outputs either the CN, or the SANs, one per line
440 csr="${1}" # the CSR itself (not a file)
442 if ! <<<"${csr}" openssl req -verify -noout 2>/dev/null; then
443 _exiterr "Certificate signing request isn't valid"
446 reqtext="$( <<<"${csr}" openssl req -noout -text )"
447 if <<<"${reqtext}" grep -q '^[[:space:]]*X509v3 Subject Alternative Name:[[:space:]]*$'; then
448 # SANs used, extract these
449 altnames="$( <<<"${reqtext}" grep -A1 '^[[:space:]]*X509v3 Subject Alternative Name:[[:space:]]*$' | tail -n1 )"
450 # split to one per line:
451 # shellcheck disable=SC1003
452 altnames="$( <<<"${altnames}" _sed -e 's/^[[:space:]]*//; s/, /\'$'\n''/g' )"
453 # we can only get DNS: ones signed
454 if grep -qv '^DNS:' <<<"${altnames}"; then
455 _exiterr "Certificate signing request contains non-DNS Subject Alternative Names"
457 # strip away the DNS: prefix
458 altnames="$( <<<"${altnames}" _sed -e 's/^DNS://' )"
462 # No SANs, extract CN
463 altnames="$( <<<"${reqtext}" grep '^[[:space:]]*Subject:' | _sed -e 's/.* CN=([^ /,]*).*/\1/' )"
468 # Create certificate for domain(s) and outputs it FD 3
470 csr="${1}" # the CSR itself (not a file)
472 if { true >&3; } 2>/dev/null; then
475 _exiterr "sign_csr: FD 3 not open"
480 if [ -z "${altnames}" ]; then
481 altnames="$( extract_altnames "${csr}" )"
484 if [[ -z "${CA_NEW_AUTHZ}" ]] || [[ -z "${CA_NEW_CERT}" ]]; then
485 _exiterr "Certificate authority doesn't allow certificate signing"
489 if [[ -n "${ZSH_VERSION:-}" ]]; then
490 local -A challenge_altnames challenge_uris challenge_tokens keyauths deploy_args
492 local -a challenge_altnames challenge_uris challenge_tokens keyauths deploy_args
496 for altname in ${altnames}; do
497 # Ask the acme-server for new challenge token and extract them from the resulting json block
498 echo " + Requesting challenge for ${altname}..."
499 response="$(signed_request "${CA_NEW_AUTHZ}" '{"resource": "new-authz", "identifier": {"type": "dns", "value": "'"${altname}"'"}}' | clean_json)"
501 challenge_status="$(printf '%s' "${response}" | rm_json_arrays | get_json_string_value status)"
502 if [ "${challenge_status}" = "valid" ]; then
503 echo " + Already validated!"
507 challenges="$(printf '%s\n' "${response}" | sed -n 's/.*\("challenges":[^\[]*\[[^]]*]\).*/\1/p')"
508 repl=$'\n''{' # fix syntax highlighting in Vim
509 challenge="$(printf "%s" "${challenges//\{/${repl}}" | grep \""${CHALLENGETYPE}"\")"
510 challenge_token="$(printf '%s' "${challenge}" | get_json_string_value token | _sed 's/[^A-Za-z0-9_\-]/_/g')"
511 challenge_uri="$(printf '%s' "${challenge}" | get_json_string_value uri)"
513 if [[ -z "${challenge_token}" ]] || [[ -z "${challenge_uri}" ]]; then
514 _exiterr "Can't retrieve challenges (${response})"
517 # Challenge response consists of the challenge token and the thumbprint of our public certificate
518 keyauth="${challenge_token}.${thumbprint}"
520 case "${CHALLENGETYPE}" in
522 # Store challenge response in well-known location and make world-readable (so that a webserver can access it)
523 printf '%s' "${keyauth}" > "${WELLKNOWN}/${challenge_token}"
524 chmod a+r "${WELLKNOWN}/${challenge_token}"
525 keyauth_hook="${keyauth}"
528 # Generate DNS entry content for dns-01 validation
529 keyauth_hook="$(printf '%s' "${keyauth}" | openssl dgst -sha256 -binary | urlbase64)"
533 challenge_altnames[${idx}]="${altname}"
534 challenge_uris[${idx}]="${challenge_uri}"
535 keyauths[${idx}]="${keyauth}"
536 challenge_tokens[${idx}]="${challenge_token}"
537 # Note: assumes args will never have spaces!
538 deploy_args[${idx}]="${altname} ${challenge_token} ${keyauth_hook}"
541 challenge_count="${idx}"
543 # Wait for hook script to deploy the challenges if used
544 if [[ ${challenge_count} -ne 0 ]]; then
545 # shellcheck disable=SC2068
546 [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" = "yes" ]] && "${HOOK}" "deploy_challenge" ${deploy_args[@]}
549 # Respond to challenges
552 if [ ${challenge_count} -ne 0 ]; then
553 for altname in "${challenge_altnames[@]:0}"; do
554 challenge_token="${challenge_tokens[${idx}]}"
555 keyauth="${keyauths[${idx}]}"
557 # Wait for hook script to deploy the challenge if used
558 # shellcheck disable=SC2086
559 [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]] && "${HOOK}" "deploy_challenge" ${deploy_args[${idx}]}
561 # Ask the acme-server to verify our challenge and wait until it is no longer pending
562 echo " + Responding to challenge for ${altname}..."
563 result="$(signed_request "${challenge_uris[${idx}]}" '{"resource": "challenge", "keyAuthorization": "'"${keyauth}"'"}' | clean_json)"
565 reqstatus="$(printf '%s\n' "${result}" | get_json_string_value status)"
567 while [[ "${reqstatus}" = "pending" ]]; do
569 result="$(http_request get "${challenge_uris[${idx}]}")"
570 reqstatus="$(printf '%s\n' "${result}" | get_json_string_value status)"
573 [[ "${CHALLENGETYPE}" = "http-01" ]] && rm -f "${WELLKNOWN}/${challenge_token}"
575 # Wait for hook script to clean the challenge if used
576 if [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]] && [[ -n "${challenge_token}" ]]; then
577 # shellcheck disable=SC2086
578 "${HOOK}" "clean_challenge" ${deploy_args[${idx}]}
582 if [[ "${reqstatus}" = "valid" ]]; then
583 echo " + Challenge is valid!"
585 [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" != "yes" ]] && "${HOOK}" "invalid_challenge" "${altname}" "${result}"
590 # Wait for hook script to clean the challenges if used
591 # shellcheck disable=SC2068
592 if [[ ${challenge_count} -ne 0 ]]; then
593 [[ -n "${HOOK}" ]] && [[ "${HOOK_CHAIN}" = "yes" ]] && "${HOOK}" "clean_challenge" ${deploy_args[@]}
596 if [[ "${reqstatus}" != "valid" ]]; then
597 # Clean up any remaining challenge_tokens if we stopped early
598 if [[ "${CHALLENGETYPE}" = "http-01" ]] && [[ ${challenge_count} -ne 0 ]]; then
599 while [ ${idx} -lt ${#challenge_tokens[@]} ]; do
600 rm -f "${WELLKNOWN}/${challenge_tokens[${idx}]}"
605 _exiterr "Challenge is invalid! (returned: ${reqstatus}) (result: ${result})"
608 # Finally request certificate from the acme-server and store it in cert-${timestamp}.pem and link from cert.pem
609 echo " + Requesting certificate..."
610 csr64="$( <<<"${csr}" openssl req -outform DER | urlbase64)"
611 crt64="$(signed_request "${CA_NEW_CERT}" '{"resource": "new-cert", "csr": "'"${csr64}"'"}' | openssl base64 -e)"
612 crt="$( printf -- '-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----\n' "${crt64}" )"
614 # Try to load the certificate to detect corruption
615 echo " + Checking certificate..."
616 _openssl x509 -text <<<"${crt}"
620 unset challenge_token
627 # grep uri from certificate
628 local issuer_cert_uri
629 issuer_cert_uri="$(openssl x509 -in "${certificate}" -noout -text | (grep 'CA Issuers - URI:' | cut -d':' -f2-) || true)"
630 if [[ -n "${issuer_cert_uri}" ]]; then
631 # create temporary files
634 tmpcert_raw="$(_mktemp)"
637 # download certificate
638 http_request get "${issuer_cert_uri}" > "${tmpcert_raw}"
641 if grep -q "BEGIN CERTIFICATE" "${tmpcert_raw}"; then mv "${tmpcert_raw}" "${tmpcert}"
643 elif openssl x509 -in "${tmpcert_raw}" -inform DER -out "${tmpcert}" -outform PEM 2> /dev/null > /dev/null; then :
645 elif openssl pkcs7 -in "${tmpcert_raw}" -inform DER -out "${tmpcert}" -outform PEM -print_certs 2> /dev/null > /dev/null; then :
646 # Unknown certificate type
647 else _exiterr "Unknown certificate type in chain"
650 printf "\n%s\n" "${issuer_cert_uri}"
652 walk_chain "${tmpcert}"
653 rm -f "${tmpcert}" "${tmpcert_raw}"
657 # Create certificate for domain(s)
661 timestamp="$(date +%s)"
663 echo " + Signing domains..."
664 if [[ -z "${CA_NEW_AUTHZ}" ]] || [[ -z "${CA_NEW_CERT}" ]]; then
665 _exiterr "Certificate authority doesn't allow certificate signing"
668 # If there is no existing certificate directory => make it
669 if [[ ! -e "${CERTDIR}/${domain}" ]]; then
670 echo " + Creating new directory ${CERTDIR}/${domain} ..."
671 mkdir -p "${CERTDIR}/${domain}" || _exiterr "Unable to create directory ${CERTDIR}/${domain}"
674 privkey="privkey.pem"
675 # generate a new private key if we need or want one
676 if [[ ! -r "${CERTDIR}/${domain}/privkey.pem" ]] || [[ "${PRIVATE_KEY_RENEW}" = "yes" ]]; then
677 echo " + Generating private key..."
678 privkey="privkey-${timestamp}.pem"
679 case "${KEY_ALGO}" in
680 rsa) _openssl genrsa -out "${CERTDIR}/${domain}/privkey-${timestamp}.pem" "${KEYSIZE}";;
681 prime256v1|secp384r1) _openssl ecparam -genkey -name "${KEY_ALGO}" -out "${CERTDIR}/${domain}/privkey-${timestamp}.pem";;
684 # move rolloverkey into position (if any)
685 if [[ -r "${CERTDIR}/${domain}/privkey.pem" && -r "${CERTDIR}/${domain}/privkey.roll.pem" && "${PRIVATE_KEY_RENEW}" = "yes" && "${PRIVATE_KEY_ROLLOVER}" = "yes" ]]; then
686 echo " + Moving Rolloverkey into position.... "
687 mv "${CERTDIR}/${domain}/privkey.roll.pem" "${CERTDIR}/${domain}/privkey-tmp.pem"
688 mv "${CERTDIR}/${domain}/privkey-${timestamp}.pem" "${CERTDIR}/${domain}/privkey.roll.pem"
689 mv "${CERTDIR}/${domain}/privkey-tmp.pem" "${CERTDIR}/${domain}/privkey-${timestamp}.pem"
691 # generate a new private rollover key if we need or want one
692 if [[ ! -r "${CERTDIR}/${domain}/privkey.roll.pem" && "${PRIVATE_KEY_ROLLOVER}" = "yes" && "${PRIVATE_KEY_RENEW}" = "yes" ]]; then
693 echo " + Generating private rollover key..."
694 case "${KEY_ALGO}" in
695 rsa) _openssl genrsa -out "${CERTDIR}/${domain}/privkey.roll.pem" "${KEYSIZE}";;
696 prime256v1|secp384r1) _openssl ecparam -genkey -name "${KEY_ALGO}" -out "${CERTDIR}/${domain}/privkey.roll.pem";;
699 # delete rolloverkeys if disabled
700 if [[ -r "${CERTDIR}/${domain}/privkey.roll.pem" && ! "${PRIVATE_KEY_ROLLOVER}" = "yes" ]]; then
701 echo " + Removing Rolloverkey (feature disabled)..."
702 rm -f "${CERTDIR}/${domain}/privkey.roll.pem"
705 # Generate signing request config and the actual signing request
706 echo " + Generating signing request..."
708 for altname in ${altnames}; do
709 SAN+="DNS:${altname}, "
712 local tmp_openssl_cnf
713 tmp_openssl_cnf="$(_mktemp)"
714 cat "${OPENSSL_CNF}" > "${tmp_openssl_cnf}"
715 printf "[SAN]\nsubjectAltName=%s" "${SAN}" >> "${tmp_openssl_cnf}"
716 if [ "${OCSP_MUST_STAPLE}" = "yes" ]; then
717 printf "\n1.3.6.1.5.5.7.1.24=DER:30:03:02:01:05" >> "${tmp_openssl_cnf}"
719 openssl req -new -sha256 -key "${CERTDIR}/${domain}/${privkey}" -out "${CERTDIR}/${domain}/cert-${timestamp}.csr" -subj "/CN=${domain}/" -reqexts SAN -config "${tmp_openssl_cnf}"
720 rm -f "${tmp_openssl_cnf}"
722 crt_path="${CERTDIR}/${domain}/cert-${timestamp}.pem"
723 # shellcheck disable=SC2086
724 sign_csr "$(< "${CERTDIR}/${domain}/cert-${timestamp}.csr" )" ${altnames} 3>"${crt_path}"
726 # Create fullchain.pem
727 echo " + Creating fullchain.pem..."
728 cat "${crt_path}" > "${CERTDIR}/${domain}/fullchain-${timestamp}.pem"
729 walk_chain "${crt_path}" > "${CERTDIR}/${domain}/chain-${timestamp}.pem"
730 cat "${CERTDIR}/${domain}/chain-${timestamp}.pem" >> "${CERTDIR}/${domain}/fullchain-${timestamp}.pem"
733 [[ "${privkey}" = "privkey.pem" ]] || ln -sf "privkey-${timestamp}.pem" "${CERTDIR}/${domain}/privkey.pem"
735 ln -sf "chain-${timestamp}.pem" "${CERTDIR}/${domain}/chain.pem"
736 ln -sf "fullchain-${timestamp}.pem" "${CERTDIR}/${domain}/fullchain.pem"
737 ln -sf "cert-${timestamp}.csr" "${CERTDIR}/${domain}/cert.csr"
738 ln -sf "cert-${timestamp}.pem" "${CERTDIR}/${domain}/cert.pem"
740 # Wait for hook script to clean the challenge and to deploy cert if used
741 [[ -n "${HOOK}" ]] && "${HOOK}" "deploy_cert" "${domain}" "${CERTDIR}/${domain}/privkey.pem" "${CERTDIR}/${domain}/cert.pem" "${CERTDIR}/${domain}/fullchain.pem" "${CERTDIR}/${domain}/chain.pem" "${timestamp}"
743 unset challenge_token
748 # Description: Register account key
755 # Description: Sign/renew non-existant/changed/expiring certificates.
756 command_sign_domains() {
759 if [[ -n "${PARAM_DOMAIN:-}" ]]; then
760 DOMAINS_TXT="$(_mktemp)"
761 printf -- "${PARAM_DOMAIN}" > "${DOMAINS_TXT}"
762 elif [[ -e "${DOMAINS_TXT}" ]]; then
763 if [[ ! -r "${DOMAINS_TXT}" ]]; then
764 _exiterr "domains.txt found but not readable"
767 _exiterr "domains.txt not found and --domain not given"
770 # Generate certificates for all domains found in domains.txt. Check if existing certificate are about to expire
773 for line in $(<"${DOMAINS_TXT}" tr -d '\r' | awk '{print tolower($0)}' | _sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]+/ /g' | (grep -vE '^(#|$)' || true)); do
776 domain="$(printf '%s\n' "${line}" | cut -d' ' -f1)"
777 morenames="$(printf '%s\n' "${line}" | cut -s -d' ' -f2-)"
778 cert="${CERTDIR}/${domain}/cert.pem"
780 force_renew="${PARAM_FORCE:-no}"
782 if [[ -z "${morenames}" ]];then
783 echo "Processing ${domain}"
785 echo "Processing ${domain} with alternative names: ${morenames}"
789 # for now this loads the certificate specific config in a subshell and parses a diff of set variables.
790 # we could just source the config file but i decided to go this way to protect people from accidentally overriding
791 # variables used internally by this script itself.
792 if [[ -n "${DOMAINS_D}" ]]; then
793 certconfig="${DOMAINS_D}/${domain}"
795 certconfig="${CERTDIR}/${domain}/config"
798 if [ -f "${certconfig}" ]; then
799 echo " + Using certificate specific config file!"
803 beforevars="$(_mktemp)"
804 aftervars="$(_mktemp)"
805 set > "${beforevars}"
806 # shellcheck disable=SC1090
809 diff -u "${beforevars}" "${aftervars}" | grep -E '^\+[^+]'
813 config_var="$(echo "${cfgline:1}" | cut -d'=' -f1)"
814 config_value="$(echo "${cfgline:1}" | cut -d'=' -f2-)"
815 case "${config_var}" in
816 KEY_ALGO|OCSP_MUST_STAPLE|PRIVATE_KEY_RENEW|PRIVATE_KEY_ROLLOVER|KEYSIZE|CHALLENGETYPE|HOOK|WELLKNOWN|HOOK_CHAIN|OPENSSL_CNF|RENEW_DAYS)
817 echo " + ${config_var} = ${config_value}"
818 declare -- "${config_var}=${config_value}"
821 *) echo " ! Setting ${config_var} on a per-certificate base is not (yet) supported"
827 export WELLKNOWN CHALLENGETYPE KEY_ALGO PRIVATE_KEY_ROLLOVER
829 if [[ -e "${cert}" ]]; then
830 printf " + Checking domain name(s) of existing cert..."
832 certnames="$(openssl x509 -in "${cert}" -text -noout | grep DNS: | _sed 's/DNS://g' | tr -d ' ' | tr ',' '\n' | sort -u | tr '\n' ' ' | _sed 's/ $//')"
833 givennames="$(echo "${domain}" "${morenames}"| tr ' ' '\n' | sort -u | tr '\n' ' ' | _sed 's/ $//' | _sed 's/^ //')"
835 if [[ "${certnames}" = "${givennames}" ]]; then
839 echo " + Domain name(s) are not matching!"
840 echo " + Names in old certificate: ${certnames}"
841 echo " + Configured names: ${givennames}"
842 echo " + Forcing renew."
847 if [[ -e "${cert}" ]]; then
848 echo " + Checking expire date of existing cert..."
849 valid="$(openssl x509 -enddate -noout -in "${cert}" | cut -d= -f2- )"
851 printf " + Valid till %s " "${valid}"
852 if openssl x509 -checkend $((RENEW_DAYS * 86400)) -noout -in "${cert}"; then
853 printf "(Longer than %d days). " "${RENEW_DAYS}"
854 if [[ "${force_renew}" = "yes" ]]; then
855 echo "Ignoring because renew was forced!"
857 # Certificate-Names unchanged and cert is still valid
858 echo "Skipping renew!"
859 [[ -n "${HOOK}" ]] && "${HOOK}" "unchanged_cert" "${domain}" "${CERTDIR}/${domain}/privkey.pem" "${CERTDIR}/${domain}/cert.pem" "${CERTDIR}/${domain}/fullchain.pem" "${CERTDIR}/${domain}/chain.pem"
863 echo "(Less than ${RENEW_DAYS} days). Renewing!"
867 # shellcheck disable=SC2086
868 if [[ "${PARAM_KEEP_GOING:-}" = "yes" ]]; then
869 sign_domain ${line} &
876 # remove temporary domains.txt file if used
877 [[ -n "${PARAM_DOMAIN:-}" ]] && rm -f "${DOMAINS_TXT}"
879 [[ -n "${HOOK}" ]] && "${HOOK}" "exit_hook"
883 # Usage: --signcsr (-s) path/to/csr.pem
884 # Description: Sign a given CSR, output CRT on stdout (advanced usage)
886 # redirect stdout to stderr
887 # leave stdout over at fd 3 to output the cert
893 if [ ! -r "${csrfile}" ]; then
894 _exiterr "Could not read certificate signing request ${csrfile}"
898 certfile="$(_mktemp)"
899 sign_csr "$(< "${csrfile}" )" 3> "${certfile}"
903 cat "${certfile}" >&3
907 if [ -n "${PARAM_FULL_CHAIN:-}" ]; then
908 # get and convert ca cert
909 chainfile="$(_mktemp)"
910 tmpchain="$(_mktemp)"
911 http_request get "$(openssl x509 -in "${certfile}" -noout -text | grep 'CA Issuers - URI:' | cut -d':' -f2-)" > "${tmpchain}"
912 if grep -q "BEGIN CERTIFICATE" "${tmpchain}"; then
913 mv "${tmpchain}" "${chainfile}"
915 openssl x509 -in "${tmpchain}" -inform DER -out "${chainfile}" -outform PEM
920 cat "${chainfile}" >&3
931 # Usage: --revoke (-r) path/to/cert.pem
932 # Description: Revoke specified certificate
936 [[ -n "${CA_REVOKE_CERT}" ]] || _exiterr "Certificate authority doesn't allow certificate revocation."
939 if [[ -L "${cert}" ]]; then
940 # follow symlink and use real certificate name (so we move the real file and not the symlink at the end)
942 link_target="$(readlink -n "${cert}")"
943 if [[ "${link_target}" =~ ^/ ]]; then
944 cert="${link_target}"
946 cert="$(dirname "${cert}")/${link_target}"
949 [[ -f "${cert}" ]] || _exiterr "Could not find certificate ${cert}"
951 echo "Revoking ${cert}"
953 cert64="$(openssl x509 -in "${cert}" -inform PEM -outform DER | urlbase64)"
954 response="$(signed_request "${CA_REVOKE_CERT}" '{"resource": "revoke-cert", "certificate": "'"${cert64}"'"}' | clean_json)"
955 # if there is a problem with our revoke request _request (via signed_request) will report this and "exit 1" out
956 # so if we are here, it is safe to assume the request was successful
958 echo " + Renaming certificate to ${cert}-revoked"
959 mv -f "${cert}" "${cert}-revoked"
962 # Usage: --cleanup (-gc)
963 # Description: Move unused certificate files to archive directory
967 # Create global archive directory if not existant
968 if [[ ! -e "${BASEDIR}/archive" ]]; then
969 mkdir "${BASEDIR}/archive"
972 # Loop over all certificate directories
973 for certdir in "${CERTDIR}/"*; do
974 # Skip if entry is not a folder
975 [[ -d "${certdir}" ]] || continue
977 # Get certificate name
978 certname="$(basename "${certdir}")"
980 # Create certitifaces archive directory if not existant
981 archivedir="${BASEDIR}/archive/${certname}"
982 if [[ ! -e "${archivedir}" ]]; then
983 mkdir "${archivedir}"
986 # Loop over file-types (certificates, keys, signing-requests, ...)
987 for filetype in cert.csr cert.pem chain.pem fullchain.pem privkey.pem; do
988 # Skip if symlink is broken
989 [[ -r "${certdir}/${filetype}" ]] || continue
991 # Look up current file in use
992 current="$(basename "$(readlink "${certdir}/${filetype}")")"
994 # Split filetype into name and extension
995 filebase="$(echo "${filetype}" | cut -d. -f1)"
996 fileext="$(echo "${filetype}" | cut -d. -f2)"
998 # Loop over all files of this type
999 for file in "${certdir}/${filebase}-"*".${fileext}"; do
1000 # Handle case where no files match the wildcard
1001 [[ -f "${file}" ]] || break
1003 # Check if current file is in use, if unused move to archive directory
1004 filename="$(basename "${file}")"
1005 if [[ ! "${filename}" = "${current}" ]]; then
1006 echo "Moving unused file to archive directory: ${certname}/${filename}"
1007 mv "${certdir}/${filename}" "${archivedir}/${filename}"
1016 # Usage: --help (-h)
1017 # Description: Show help text
1019 printf "Usage: %s [-h] [command [argument]] [parameter [argument]] [parameter [argument]] ...\n\n" "${0}"
1020 printf "Default command: help\n\n"
1022 grep -e '^[[:space:]]*# Usage:' -e '^[[:space:]]*# Description:' -e '^command_.*()[[:space:]]*{' "${0}" | while read -r usage; read -r description; read -r command; do
1023 if [[ ! "${usage}" =~ Usage ]] || [[ ! "${description}" =~ Description ]] || [[ ! "${command}" =~ ^command_ ]]; then
1024 _exiterr "Error generating help text."
1026 printf " %-32s %s\n" "${usage##"# Usage: "}" "${description##"# Description: "}"
1028 printf -- "\nParameters:\n"
1029 grep -E -e '^[[:space:]]*# PARAM_Usage:' -e '^[[:space:]]*# PARAM_Description:' "${0}" | while read -r usage; read -r description; do
1030 if [[ ! "${usage}" =~ Usage ]] || [[ ! "${description}" =~ Description ]]; then
1031 _exiterr "Error generating help text."
1033 printf " %-32s %s\n" "${usage##"# PARAM_Usage: "}" "${description##"# PARAM_Description: "}"
1038 # Description: Output configuration variables for use in other scripts
1040 echo "# dehydrated configuration"
1042 typeset -p CA LICENSE CERTDIR CHALLENGETYPE DOMAINS_D DOMAINS_TXT HOOK HOOK_CHAIN RENEW_DAYS ACCOUNT_KEY ACCOUNT_KEY_JSON KEYSIZE WELLKNOWN PRIVATE_KEY_RENEW OPENSSL_CNF CONTACT_EMAIL LOCKFILE
1045 # Main method (parses script arguments and calls command_* methods)
1049 [[ -z "${COMMAND}" ]] || _exiterr "Only one command can be executed at a time. See help (-h) for more information."
1053 check_parameters() {
1054 if [[ -z "${1:-}" ]]; then
1055 echo "The specified command requires additional parameters. See help:" >&2
1059 elif [[ "${1:0:1}" = "-" ]]; then
1060 _exiterr "Invalid argument: ${1}"
1064 [[ -z "${@}" ]] && eval set -- "--help"
1066 while (( ${#} )); do
1078 set_command sign_domains
1082 set_command register
1085 # PARAM_Usage: --accept-terms
1086 # PARAM_Description: Accept CAs terms of service
1088 PARAM_ACCEPT_TERMS="yes"
1093 set_command sign_csr
1094 check_parameters "${1:-}"
1101 check_parameters "${1:-}"
1102 PARAM_REVOKECERT="${1}"
1109 # PARAM_Usage: --full-chain (-fc)
1110 # PARAM_Description: Print full chain when using --signcsr
1112 PARAM_FULL_CHAIN="1"
1115 # PARAM_Usage: --ipv4 (-4)
1116 # PARAM_Description: Resolve names to IPv4 addresses only
1118 PARAM_IP_VERSION="4"
1121 # PARAM_Usage: --ipv6 (-6)
1122 # PARAM_Description: Resolve names to IPv6 addresses only
1124 PARAM_IP_VERSION="6"
1127 # PARAM_Usage: --domain (-d) domain.tld
1128 # PARAM_Description: Use specified domain name(s) instead of domains.txt entry (one certificate!)
1131 check_parameters "${1:-}"
1132 if [[ -z "${PARAM_DOMAIN:-}" ]]; then
1135 PARAM_DOMAIN="${PARAM_DOMAIN} ${1}"
1139 # PARAM_Usage: --keep-going (-g)
1140 # PARAM_Description: Keep going after encountering an error while creating/renewing multiple certificates in cron mode
1142 PARAM_KEEP_GOING="yes"
1145 # PARAM_Usage: --force (-x)
1146 # PARAM_Description: Force renew of certificate even if it is longer valid than value in RENEW_DAYS
1151 # PARAM_Usage: --no-lock (-n)
1152 # PARAM_Description: Don't use lockfile (potentially dangerous!)
1157 # PARAM_Usage: --lock-suffix example.com
1158 # PARAM_Description: Suffix lockfile name with a string (useful for with -d)
1161 check_parameters "${1:-}"
1162 PARAM_LOCKFILE_SUFFIX="${1}"
1165 # PARAM_Usage: --ocsp
1166 # PARAM_Description: Sets option in CSR indicating OCSP stapling to be mandatory
1168 PARAM_OCSP_MUST_STAPLE="yes"
1171 # PARAM_Usage: --privkey (-p) path/to/key.pem
1172 # PARAM_Description: Use specified private key instead of account key (useful for revocation)
1175 check_parameters "${1:-}"
1176 PARAM_ACCOUNT_KEY="${1}"
1179 # PARAM_Usage: --config (-f) path/to/config
1180 # PARAM_Description: Use specified config file
1183 check_parameters "${1:-}"
1187 # PARAM_Usage: --hook (-k) path/to/hook.sh
1188 # PARAM_Description: Use specified script for hooks
1191 check_parameters "${1:-}"
1195 # PARAM_Usage: --out (-o) certs/directory
1196 # PARAM_Description: Output certificates into the specified directory
1199 check_parameters "${1:-}"
1200 PARAM_CERTDIR="${1}"
1203 # PARAM_Usage: --challenge (-t) http-01|dns-01
1204 # PARAM_Description: Which challenge should be used? Currently http-01 and dns-01 are supported
1207 check_parameters "${1:-}"
1208 PARAM_CHALLENGETYPE="${1}"
1211 # PARAM_Usage: --algo (-a) rsa|prime256v1|secp384r1
1212 # PARAM_Description: Which public key algorithm should be used? Supported: rsa, prime256v1 and secp384r1
1215 check_parameters "${1:-}"
1216 PARAM_KEY_ALGO="${1}"
1220 echo "Unknown parameter detected: ${1}" >&2
1230 case "${COMMAND}" in
1232 sign_domains) command_sign_domains;;
1233 register) command_register;;
1234 sign_csr) command_sign_csr "${PARAM_CSR}";;
1235 revoke) command_revoke "${PARAM_REVOKECERT}";;
1236 cleanup) command_cleanup;;
1237 *) command_help; exit 1;;
1244 # Check for missing dependencies