#!/bin/sh
# ./create-ssl-bundle.sh myserver.crt >myserver.chain
# ./create-ssl-bundle.sh intermediate.crt >>myserver.chain
# ./create-ssl-bundle.sh root.crt >>myserver.chain
# In apache-ssl-config.file place:
# NameVirtualHost *:443
# Change <VirtualHost *> to <VirtualHost *:443>
# SSLEngine On
# SSLCertificateKeyFile /etc/apache2/ssl/_iq-test_cc.key
# SSLCertificateFile /etc/apache2/ssl/chain.crt

#
# Convert PEM Certificate to ca-bundle.crt format
#

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:/'
