Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created February 11, 2017 10:26
Show Gist options
  • Save v6ak/ab9c98256ce47c4d489288a979fdca5f to your computer and use it in GitHub Desktop.
Save v6ak/ab9c98256ce47c4d489288a979fdca5f to your computer and use it in GitHub Desktop.
Extracts cert from Sandstorm JSON file and skips trust anchor (the root CA)
#!/bin/bash
. /opt/sandstorm/sandstorm.conf # Well, no one except root can write the file, so it is probably acceptable to execute it.
certjsonfile=$(ls "/opt/sandstorm/var/sandcats/https/$SANDCATS_HOSTNAME/"*.response-json | sort -r -n | head -n1)
keyfile=$(sed 's/\.response-json$//' <<< "$certjsonfile")
certfile="$keyfile.crt"
cat "$certjsonfile" | jq '.cert, (.ca|.[1:]|reverse)[]' --raw-output > "$certfile"
ln -sfT "$certfile" "/etc/current-certs/$SANDCATS_HOSTNAME.crt"
ln -sfT "$keyfile" "/etc/current-certs/$SANDCATS_HOSTNAME.key"
sudo systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment