aboutsummaryrefslogtreecommitdiffstats
path: root/http.sh
diff options
context:
space:
mode:
authorLexi Winter <ivy@FreeBSD.org>2025-06-03 12:34:59 +0100
committerLexi Winter <ivy@FreeBSD.org>2025-06-03 12:34:59 +0100
commit40c249d4401f6ee889c2e398e7605952772eb6ce (patch)
tree2251eb0de826b9a333909af3b02d170ffb22e00c /http.sh
parent6e19b042cbc9d5ff195eaf8f5c31243d36a7d56f (diff)
downloadlfacme-40c249d4401f6ee889c2e398e7605952772eb6ce.tar.gz
lfacme-40c249d4401f6ee889c2e398e7605952772eb6ce.tar.bz2
add an "http" challenge handler
Diffstat (limited to 'http.sh')
-rw-r--r--http.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/http.sh b/http.sh
new file mode 100644
index 0000000..ef60d26
--- /dev/null
+++ b/http.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+# This source code is released into the public domain.
+
+. /usr/local/share/lfacme/init.sh
+
+# begin, done or failed
+ACTION=$1
+# ACME method, must be http-01.
+METHOD=$2
+# The full domain name we're authorising.
+DOMAIN=$3
+# Token name.
+TOKEN=$4
+# The token value we need to create.
+AUTH=$5
+
+if [ "$#" -ne 5 ]; then
+ _fatal "missing arguments"
+fi
+
+if [ "$METHOD" != "http-01" ]; then
+ _warn "skip method %s" "$METHOD"
+ exit 1
+fi
+
+if [ -z "$ACME_HTTP_CHALLENGE_DIR" ]; then
+ _fatal "must set ACME_HTTP_CHALLENGE_DIR"
+fi
+
+if ! [ -d "$ACME_HTTP_CHALLENGE_DIR" ]; then
+ _fatal "missing $ACME_HTTP_CHALLENGE_DIR"
+fi
+
+_file="${ACME_HTTP_CHALLENGE_DIR}/${TOKEN}"
+
+case "$ACTION" in
+ begin)
+ echo "$AUTH" >"$_file"
+ exit $?
+ ;;
+
+ done|failed)
+ rm -f "$_file"
+ exit $?
+ ;;
+
+ *)
+ _fatal "unknown action: %s" "$ACTION"
+ ;;
+esac