Skip to content

Instantly share code, notes, and snippets.

@roening
Forked from koshatul/sslCertSplit.sh
Created January 30, 2024 12:40
Show Gist options
  • Select an option

  • Save roening/756bd41fb72979d63fe75a14ad578294 to your computer and use it in GitHub Desktop.

Select an option

Save roening/756bd41fb72979d63fe75a14ad578294 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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment