From 822c04d4243b69864c26730ae19d2bf10249eb23 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Thu, 31 Oct 2019 23:58:11 +0200 Subject: [PATCH] Dehydrated: add libexec helpers --- .../overlay/usr/libexec/dehydrated-dumb-httpd | 27 +++++++++++++++++++ .../overlay/usr/libexec/dehydrated-hook | 15 +++++++++++ 2 files changed, 42 insertions(+) create mode 100755 board/common/overlay/usr/libexec/dehydrated-dumb-httpd create mode 100755 board/common/overlay/usr/libexec/dehydrated-hook diff --git a/board/common/overlay/usr/libexec/dehydrated-dumb-httpd b/board/common/overlay/usr/libexec/dehydrated-dumb-httpd new file mode 100755 index 0000000000..9130f7a7a4 --- /dev/null +++ b/board/common/overlay/usr/libexec/dehydrated-dumb-httpd @@ -0,0 +1,27 @@ +#!/bin/bash + +CHALLENGE="$1" +PORT=80 +LIFETIME=10 + +if [[ -z "${CHALLENGE}" ]]; then + echo "Usage $0 " + 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" diff --git a/board/common/overlay/usr/libexec/dehydrated-hook b/board/common/overlay/usr/libexec/dehydrated-hook new file mode 100755 index 0000000000..020150f294 --- /dev/null +++ b/board/common/overlay/usr/libexec/dehydrated-hook @@ -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