#!/bin/bash
#
CMD=$(basename $0)
CMDVER="1.0"
CMDSTR="$CMD v$CMDVER (2018/04)"

usage()
{
	echo "usage: $CMD basename    (eg: $CMD customer_short_name)" >&2
	exit 1
}


# (MAIN)

[ $# != 1 ] && usage

base=$1

cd /etc/ssl/certs

for file in $(ls ${base}*.pem) $(ls ${base}*.crt)
do
	out=$(openssl x509 -text -noout -in $file 2>/dev/null)
        issuer=$(echo "$out" | grep 'Issuer: ' | sed -e 's/.*Issuer: //')
        subj=$(echo "$out" | grep 'Subject: ' | sed -e 's/.*Subject: //')
        from=$(echo "$out" | grep 'Not Before:' | sed -e 's/.*Not Before: //')
	set - $from; from="$1 $2 $4"
        to=$(echo "$out" | grep 'Not After :' | sed -e 's/.*Not After : //')
	set - $to; to="$1 $2 $4"

	printf "%-20s %-12s %-12s %-30.30s %-30.30s" $file "$from" "$to" "$subj" "$issuer"
	echo
done

cd /etc/ssl/private

for file in $(ls ${base}*)
do
	printf "%-20s " $file
	openssl rsa -check -in $file 2>/dev/null | grep '^RSA '
done

exit 0
