Created
April 21, 2020 17:53
-
-
Save kaskavalci/46aaf62465f361194fa3c05ffeb810e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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