Skip to content

Instantly share code, notes, and snippets.

@koshatul
Created July 16, 2018 03:07
Show Gist options
  • Save koshatul/b36ff4c9040f21545b8755ea04aaa227 to your computer and use it in GitHub Desktop.
Save koshatul/b36ff4c9040f21545b8755ea04aaa227 to your computer and use it in GitHub Desktop.
SSL CA bundle split and openssl on each certificate
#!/bin/bash
set +e
CA_BUNDLE="${1}"
shift
if [ ! -s "${CA_BUNDLE}" ]; then
echo "usage: ${0} <ca bundle file> [openssl commands]"
echo "example: ${0} ca-bundle.pem -noout -subject -issuer"
exit 2
fi
TMP_DIR=$(mktemp -d)
csplit -k -f "${TMP_DIR}/cert" "${CA_BUNDLE}" '/END CERTIFICATE/+1' {100} >/dev/null 2>/dev/null
for I in ${TMP_DIR}/cert*; do
if [ -s "${I}" ]; then
echo "####################################################################"
openssl x509 -in "${I}" "${@}"
fi
done
rm -r -f "${TMP_DIR}"
@koshatul
Copy link
Author

Example:

$ sslCertSplit.sh comodorsa_intermediate_bundle.crt -noout -subject -issuer -dates
####################################################################
subject= /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
issuer= /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
notBefore=Feb 12 00:00:00 2014 GMT
notAfter=Feb 11 23:59:59 2029 GMT
####################################################################
subject= /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
issuer= /C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
notBefore=May 30 10:48:38 2000 GMT
notAfter=May 30 10:48:38 2020 GMT
####################################################################
subject= /C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
issuer= /C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
notBefore=May 30 10:48:38 2000 GMT
notAfter=May 30 10:48:38 2020 GMT

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