Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save david50407/4291726dac3c7ec78493 to your computer and use it in GitHub Desktop.
Save david50407/4291726dac3c7ec78493 to your computer and use it in GitHub Desktop.
Read a SSL certificate issued by StartSSL and bundle intermediate certificates into it so it works everywhere
#!/bin/bash
set -eo pipefail
cert_file="$1"
if [ -z "$cert_file" ]; then
echo "Usage: create-startssl-cert-bundle CERTIFICATE_FILE" >&2
echo >&2
echo "Bundles StartSSL's intermediate certs and writes combined certificate to stdout" >&2
exit 1
fi
matched_url="$(openssl x509 -in "$cert_file" -noout -text \
| grep --only-matching --extended 'http://aia\.startssl\.com/certs/sub\.class(1|2)\.server\.ca\.crt')"
if [ -z "$matched_url" ]; then
echo "This doesn't look like a StartSSL certificate" >&2
exit 1
fi
cert_url="${matched_url%.crt}.pem"
# Read only first certificate out of file
sed '/--END CERTIFICATE--/q' "$cert_file"
curl --silent "$cert_url"
curl --silent "http://www.startssl.com/certs/ca.pem"
@cgarnier
Copy link

thanks =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment