Dehydrated: add libexec helpers

This commit is contained in:
Calin Crisan 2019-10-31 23:58:11 +02:00
parent 24200be6a2
commit 822c04d424
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#!/bin/bash
CHALLENGE="$1"
PORT=80
LIFETIME=10
if [[ -z "${CHALLENGE}" ]]; then
echo "Usage $0 <challenge>"
exit 1
fi
function make_response() {
echo -en "HTTP/1.1 200 OK\r\n"
echo -en "Content-Length: ${#CHALLENGE}\r\n"
echo -en "Content-Type: text/plain\r\n"
echo -en "Connection: close\r\n\r\n${CHALLENGE}"
}
start_time=$(date +%s)
echo "Dumb httpd started"
while true; do
make_response | nc -l -w "${LIFETIME}" -p ${PORT} >/dev/null
if (( $(date +%s) - ${start_time} > ${LIFETIME} )); then
break
fi
done
echo "Dumb httpd exit"

View File

@ -0,0 +1,15 @@
#!/bin/bash
SSL_DIR="/data/etc/ssl"
CERT_FILE="${SSL_DIR}/cert.pem"
KEY_FILE="${SSL_DIR}/privkey.pem"
if [[ "$1" == "deploy_challenge" ]]; then
/usr/libexec/dehydrated-dumb-httpd "$4" &
elif [[ "$1" == "deploy_cert" ]]; then
logger -t dehydrated "deploying certificate & rebooting"
mkdir -p "${SSL_DIR}"
cp "$3" "${KEY_FILE}"
cp "$4" "${CERT_FILE}"
reboot
fi