admin-stuff/bundle_certs.sh
2017-02-21 02:14:51 +01:00

24 lines
798 B
Bash
Executable File

#!/bin/sh
#
# Convert PEM Certificate to ca-bundle.crt format
#
# example:
# ./bundle_certs.sh myserver.crt >myserver.chain
# ./bundle_certs.sh intermediate.crt >>myserver.chain
# ./bundle_certs.sh root.crt >>myserver.chain
test ! $1 && printf "Usage: `basename $0` certificate" && exit 1
# Friendly Name and Underline Friendly Name with equal signs
openssl x509 -in $1 -text -noout | sed -e 's/^ *Subject:.*CN=\([^,]*\).*/\1/p;t c' -e 'd;:c' -e 's/./=/g'
# Output Fingerprint and swap = for :
openssl x509 -in $1 -noout -fingerprint | sed -e 's/=/: /'
# Output PEM Data:
echo 'PEM Data:'
# Output Certificate
openssl x509 -in $1
# Output Certificate text swapping Certificate with Certificate Ingredients
openssl x509 -in $1 -text -noout | sed -e 's/^Certificate:/Certificate Ingredients:/'