# Forced command of the xmpp-cert-sync key from asxpio-ops: read a # certificate chain + key on stdin, check it, install it as # certs/.pem for ejabberd (which picks the matching file per # domain) and reload. set -eu umask 022 name=${SSH_ORIGINAL_COMMAND:-} case "$name" in asxp.io|*.asxp.io) ;; *) echo "refusing certificate name '$name'" >&2; exit 1 ;; esac case "$name" in *[!a-z0-9.-]*) echo "bad name" >&2; exit 1 ;; esac dir=/opt/xmpp/state/certs tmp=$(mktemp "$dir/.incoming.XXXXXX") trap 'rm -f "$tmp"' EXIT head -c 65536 > "$tmp" # Valid for at least another day, for this name, with its matching key openssl x509 -in "$tmp" -noout -checkend 86400 >/dev/null openssl x509 -in "$tmp" -noout -checkhost "$name" | grep -q "does match" cert_pub=$(openssl x509 -in "$tmp" -noout -pubkey | sha256sum) key_pub=$(openssl pkey -in "$tmp" -pubout | sha256sum) [ "$cert_pub" = "$key_pub" ] || { echo "key does not match certificate" >&2; exit 1; } chmod 0644 "$tmp" mv "$tmp" "$dir/$name.pem" trap - EXIT # Not running during a restore or on a rehearsal host: ejabberd reads the # file at its next start if podman container exists xmpp-ejabberd; then podman exec xmpp-ejabberd ejabberdctl reload_config fi logger -t xmpp-cert-install "installed $name.pem, $(openssl x509 -in "$dir/$name.pem" -noout -enddate)"