]> git.ipfire.org Git - thirdparty/dehydrated.git/commitdiff
New hook: generate_csr (see example hook script for more information, implements...
authorLukas Schauer <lukas@schauer.so>
Tue, 6 Feb 2018 19:54:58 +0000 (20:54 +0100)
committerLukas Schauer <lukas@schauer.so>
Tue, 6 Feb 2018 19:57:33 +0000 (20:57 +0100)
CHANGELOG
dehydrated
docs/examples/hook.sh

index ab546137778dc668c792d6303f541d6fcdb80368..6281cf7407c0e60d6daae178466c3fe9fc14387d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ This file contains a log of major changes in dehydrated
 
 ## Added
 - Support for ACME v02 (including wildcard certificates!)
+- New hook: generate_csr (see example hook script for more information)
 
 ## [0.5.0] - 2018-01-13
 ## Changed
index eda51bd629d5567b50ac56858b79c0b5fc6a556b..bd0319a0b9882acb9138c47292046548e965318e 100755 (executable)
@@ -1169,6 +1169,19 @@ command_sign_domains() {
 
     skip="no"
 
+    # Allow for external CSR generation
+    if [[ -n "${HOOK}" ]]; then
+      local csr="$("${HOOK}" "generate_csr" "${domain}" "${certdir}" "${domain} ${morenames}")"
+      if grep -q "\-----BEGIN CERTIFICATE REQUEST-----" <<< "${csr}"; then
+        altnames="$(extract_altnames "${csr}")"
+        domain="$(cut -d' ' -f1 <<< "${altnames}")"
+        morenames="$(cut -s -d' ' -f2- <<< "${altnames}")"
+        echo " + Using CSR from hook script (real names: ${altnames})"
+        printf "%s" "${csr}" > "${certdir}/cert-${timestamp}.csr"
+      fi
+    fi
+
+    # Check domain names of existing certificate
     if [[ -e "${cert}" ]]; then
       printf " + Checking domain name(s) of existing cert..."
 
index ccf731fc001f491f9e2b5987afd3da21b386f0a3..c85d92e50816eb334083dff93a7b54c3e7da8c44 100755 (executable)
@@ -105,6 +105,26 @@ request_failure() {
     #   The kind of request that was made (GET, POST...)
 }
 
+generate_csr() {
+    local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}"
+
+    # This hook is called before any certificate signing operation takes place.
+    # It can be used to generate or fetch a certificate signing request with external
+    # tools.
+    # The output should be just the cerificate signing request formatted as PEM.
+    #
+    # Parameters:
+    # - DOMAIN
+    #   The primary domain as specified in domains.txt. This does not need to
+    #   match with the domains in the CSR, it's basically just the directory name.
+    # - CERTDIR
+    #   Certificate output directory for this particular certificate. Can be used
+    #   for storing additional files.
+    # - ALTNAMES
+    #   All domain names for the current certificate as specified in domains.txt.
+    #   Again, this doesn't need to match with the CSR, it's just there for convenience.
+}
+
 startup_hook() {
   # This hook is called before the cron command to do some initial tasks
   # (e.g. starting a webserver).
@@ -120,6 +140,6 @@ exit_hook() {
 }
 
 HANDLER="$1"; shift
-if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|unchanged_cert|invalid_challenge|request_failure|startup_hook|exit_hook)$ ]]; then
+if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then
   "$HANDLER" "$@"
 fi