aboutsummaryrefslogtreecommitdiffstats
path: root/ualpn.sh.in
blob: 372ed276c3b3c46fccac992788bc757f2b8c6532 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/sh
# This source code is released into the public domain.

. __LIBDIR__/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" != "tls-alpn-01" ]; then
	exit 1
fi

case "$ACTION" in
	begin)
		_verbose "creating validation token %s" "$_file"
		status="$(ualpn <<EOF
auth ${DOMAIN} ${AUTH}
EOF
)"
		if [ "$status" = "OK" ]; then
			exit 0
		else
			exit 1
		fi
		;;

	done|failed)
		_verbose "deleting validation token %s" "$_file"
		status="$(ualpn <<EOF
unauth ${DOMAIN}
EOF
)"
		if [ "$status" = "OK" ]; then
			exit 0
		else
			exit 1
		fi
		;;

	*)
		_fatal "unknown action: %s" "$ACTION"
		;;
esac