Skip to content

Instantly share code, notes, and snippets.

@kaskavalci
Created April 21, 2020 17:53
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 kaskavalci/46aaf62465f361194fa3c05ffeb810e0 to your computer and use it in GitHub Desktop.
Save kaskavalci/46aaf62465f361194fa3c05ffeb810e0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author: kdecherf
# This script is copied directly from https://kdecherf.com/blog/2015/04/10/show-the-certificate-chain-of-a-local-x509-file/
# License: CC BY-NC-SA 3.0
# https://creativecommons.org/licenses/by-nc-sa/3.0/
chain_pem="${1}"
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 x509 -noout -subject -issuer"
}
/-----BEGIN CERTIFICATE-----/ {
printf "%2d: ", ind
}
{
printf $0"\n" | showcert
}
/-----END CERTIFICATE-----/ {
close(showcert)
ind ++
}
' "${chain_pem}"
echo
openssl verify -untrusted "${chain_pem}" "${chain_pem}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment