Skip to content

Instantly share code, notes, and snippets.

@kshaa
Created June 1, 2020 11:14
Show Gist options
  • Save kshaa/56c92521062a886b45ec641e30ebc5a6 to your computer and use it in GitHub Desktop.
Save kshaa/56c92521062a886b45ec641e30ebc5a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
chain_pem="${1}"
if [[ -z "${2}" ]]; then
ssl_flags="x509 -noout -text"
else
ssl_flags="${2}"
fi
echo "SSL Flags: ${ssl_flags}\n"
if [[ ! -f "${chain_pem}" ]]; then
echo "Usage: $0 BASE64_CERTIFICATE_CHAIN_FILE" >&2
exit 1
fi
if ! openssl x509 -in "${chain_pem}" -noout 2>/dev/null ; then
echo "${chain_pem} is not a certificate" >&2
exit 1
fi
awk -F'\n' "
BEGIN {
showcert = \"openssl ${ssl_flags}\"
}
/-----BEGIN CERTIFICATE-----/ {
printf \"%2d: \", ind
}
{
printf \$0\"\n\" | showcert
}
/-----END CERTIFICATE-----/ {
close(showcert)
ind ++
}
" "${chain_pem}"
echo
openssl verify -untrusted "${chain_pem}" "${chain_pem}"
@kshaa
Copy link
Author

kshaa commented Jun 1, 2020

Sourced from https://kdecherf.com/blog/2015/04/10/show-the-certificate-chain-of-a-local-x509-file/
Modified to print whole certificates by default and to optionally allow for custom openssl flags.

Example: ssl_chain.sh certificate.pem
Verbose example: ssl_chain.sh certificate.pem "x509 -noout -subject -issuer"

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