Commit 916dca32 authored by Marcello Golfieri's avatar Marcello Golfieri
Browse files

refactoring: quick cleanup of usage and main. Many rookie inneficiencies as it...

refactoring: quick cleanup of usage and main. Many rookie inneficiencies as it was my first big script ever
parent 0049d9cb
#!/usr/bin/env bash
# Marcello Golfieri
# Pieces here and there from zmcertmgr (addcacert, verifycrt)
# See https://www.zimbra.com/legal/licensing/ for more info on the topic
# Some variables here (common ones)
TEMP=/tmp/sslcheck123152343joewgjj34
......@@ -60,8 +61,6 @@ addCACERT() {
}
showcertinfo() {
if [ ! -f ${1} ]; then
echo No such file found: ${1}
......@@ -171,7 +170,6 @@ verifycrtkey() {
fi
}
verifycrtchain () {
cafile=$1
crt=$2
......@@ -186,8 +184,6 @@ verifycrtchain () {
fi
}
ExplodeCACerts()
{
if [ ! -f "${1}" ]; then
......@@ -276,64 +272,33 @@ openssl verify -CApath $CACERTS_EXPLODED_DIR $CERTFILE
########################
usage () {
echo "Usage: "
echo " $0 -help"
echo " $0 verifycrt <priv_key> <ca_file> <certfile>"
echo " $0 verifycrtkey <priv_key> <certfile>"
echo " $0 verifycrtchain <ca_file> <certfile>"
echo " $0 verifypemformatting <pem_file>"
echo " $0 checkcrtexpiration [-days 30] [service]"
echo " $0 checkcert <cacerts_store_file> <certfile>"
echo " $0 checkhost <cacerts_store_file> <hostname>:<port>"
echo " $0 showcertinfo <certfile>"
echo " $0 showhostcert <hostname>:<port>"
echo " $0 showhostfullcertbundle <hostname>:<port>"
echo " $0 showhostchain <hostname>:<port>"
echo " $0 addcacert <cacerts_store_file> <certfile> [<alias>]"
echo
COMMAND=$(basename $0)
cat << EOF
Usage:
${COMMAND} -help
${COMMAND} verifycrt <priv_key> <ca_file> <certfile>
${COMMAND} verifycrtkey <priv_key> <certfile>
${COMMAND} verifycrtchain <ca_file> <certfile>
${COMMAND} verifypemformatting <pem_file>
${COMMAND} checkcrtexpiration [-days 30] [service]
${COMMAND} checkcert <cacerts_store_file> <certfile>
${COMMAND} checkhost <cacerts_store_file> <hostname>:<port>
${COMMAND} showcertinfo <certfile>
${COMMAND} showhostcert <hostname>:<port>
${COMMAND} showhostfullcertbundle <hostname>:<port>
${COMMAND} showhostchain <hostname>:<port>
${COMMAND} addcacert <cacerts_store_file> <certfile> [<alias>]
EOF
exit 1;
}
if [ $# = 0 ]; then
usage
fi
ACTION=$1
shift
ACTION_ROOT_DIR=$TEMP
# check for valid usage
if [ x"$ACTION" = "xcheckhost" ]; then
checkhost $@
elif [ x"$ACTION" = "xcheckcert" ]; then
checkcert $@
elif [ x"$ACTION" = "xverifypemformatting" ]; then
verifypemformatting $@
elif [ x"$ACTION" = "xverifycrt" ]; then
verifycrt $@
elif [ x"$ACTION" = "xverifycrtkey" ]; then
verifycrtkey $@
elif [ x"$ACTION" = "xverifycrtchain" ]; then
verifycrtchain $@
elif [ x"$ACTION" = "xshowhostcertfullchain" ]; then
showhostcertfullchain $@
elif [ x"$ACTION" = "xshowhostcert" ]; then
showhostcert $@
elif [ x"$ACTION" = "xshowcertinfo" ]; then
showcertinfo $@
elif [ x"$ACTION" = "xshowhostfullcertbundle" ]; then
showhostfullcertbundle $@
elif [ x"$ACTION" = "xshowhostchain" ]; then
showhostchain $@
elif [ x"$ACTION" = "xcheckcrtexpiration" ]; then
checkCertExpiration $@
elif [ x"$ACTION" = "xaddcacert" ]; then
addCACERT $@
elif [ x"$ACTION" = "x-help" -o x"$ACTION" = "xhelp" -o x"$ACTION" = "x-h" -o x"$ACTION" = "x--help" ]; then
usage
if [ "$(type -t ${ACTION})" = "function" ]; then
${ACTION} $@
else
usage
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment