Skip to content

Instantly share code, notes, and snippets.

@lstellway
Last active February 23, 2022 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstellway/41f90155b1f57560b240154be257df60 to your computer and use it in GitHub Desktop.
Save lstellway/41f90155b1f57560b240154be257df60 to your computer and use it in GitHub Desktop.
Shell utility to help find the certificates used by a specified FQDN on Synology NAS
#!/bin/sh
# Help
if [ "$1" == "-h" -o "$1" == "--help" ]; then
SCRIPT="$(basename ${0})"
cat <<EOF
${SCRIPT}
Shell utility to help find the certificates used by a specified FQDN on Synology NAS
Usage
${SCRIPT} example.com
EOF
exit
fi
# Ensure a FQDN is provided
if [ -z "$1" ]; then
printf "Please provide a domain name to search for.\n"
exit 1
fi
# Get the related service ID
SERVICE=$(jq -r 'keys[] as $k | select($k != "version") | select(.[$k].frontend.fqdn | contains("'$1'")) | $k' "/usr/syno/etc/www/ReverseProxy.json")
if [ -z "$SERVICE" ]; then
printf "Could not find service with requested FQDN.\n"
exit 1
fi
# Get certificates used by service
DIR="/usr/syno/etc/certificate/_archive"
ID=$(jq -r 'keys[] as $k | select(.[$k].services[0].service == "'$SERVICE'") | $k' "${DIR}/INFO")
if [ -z "${ID}" ]; then
printf "No certificates could be found for the requested service.\n"
exit 1
fi
cat <<EOF
${DIR}/${ID}/cert.pem
${DIR}/${ID}/chain.pem
${DIR}/${ID}/fullchain.pem
${DIR}/${ID}/privkey.pem
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment