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 #!/usr/bin/env bash
# Marcello Golfieri # Marcello Golfieri
# Pieces here and there from zmcertmgr (addcacert, verifycrt) # 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) # Some variables here (common ones)
TEMP=/tmp/sslcheck123152343joewgjj34 TEMP=/tmp/sslcheck123152343joewgjj34
...@@ -60,8 +61,6 @@ addCACERT() { ...@@ -60,8 +61,6 @@ addCACERT() {
} }
showcertinfo() { showcertinfo() {
if [ ! -f ${1} ]; then if [ ! -f ${1} ]; then
echo No such file found: ${1} echo No such file found: ${1}
...@@ -171,7 +170,6 @@ verifycrtkey() { ...@@ -171,7 +170,6 @@ verifycrtkey() {
fi fi
} }
verifycrtchain () { verifycrtchain () {
cafile=$1 cafile=$1
crt=$2 crt=$2
...@@ -186,8 +184,6 @@ verifycrtchain () { ...@@ -186,8 +184,6 @@ verifycrtchain () {
fi fi
} }
ExplodeCACerts() ExplodeCACerts()
{ {
if [ ! -f "${1}" ]; then if [ ! -f "${1}" ]; then
...@@ -276,66 +272,35 @@ openssl verify -CApath $CACERTS_EXPLODED_DIR $CERTFILE ...@@ -276,66 +272,35 @@ openssl verify -CApath $CACERTS_EXPLODED_DIR $CERTFILE
######################## ########################
usage () { usage () {
echo "Usage: " COMMAND=$(basename $0)
echo " $0 -help" cat << EOF
echo " $0 verifycrt <priv_key> <ca_file> <certfile>" Usage:
echo " $0 verifycrtkey <priv_key> <certfile>" ${COMMAND} -help
echo " $0 verifycrtchain <ca_file> <certfile>" ${COMMAND} verifycrt <priv_key> <ca_file> <certfile>
echo " $0 verifypemformatting <pem_file>" ${COMMAND} verifycrtkey <priv_key> <certfile>
echo " $0 checkcrtexpiration [-days 30] [service]" ${COMMAND} verifycrtchain <ca_file> <certfile>
echo " $0 checkcert <cacerts_store_file> <certfile>" ${COMMAND} verifypemformatting <pem_file>
echo " $0 checkhost <cacerts_store_file> <hostname>:<port>" ${COMMAND} checkcrtexpiration [-days 30] [service]
echo " $0 showcertinfo <certfile>" ${COMMAND} checkcert <cacerts_store_file> <certfile>
echo " $0 showhostcert <hostname>:<port>" ${COMMAND} checkhost <cacerts_store_file> <hostname>:<port>
echo " $0 showhostfullcertbundle <hostname>:<port>" ${COMMAND} showcertinfo <certfile>
echo " $0 showhostchain <hostname>:<port>" ${COMMAND} showhostcert <hostname>:<port>
echo " $0 addcacert <cacerts_store_file> <certfile> [<alias>]" ${COMMAND} showhostfullcertbundle <hostname>:<port>
echo ${COMMAND} showhostchain <hostname>:<port>
${COMMAND} addcacert <cacerts_store_file> <certfile> [<alias>]
EOF
exit 1; exit 1;
} }
if [ $# = 0 ]; then
usage
fi
ACTION=$1 ACTION=$1
shift shift
ACTION_ROOT_DIR=$TEMP ACTION_ROOT_DIR=$TEMP
if [ "$(type -t ${ACTION})" = "function" ]; then
# check for valid usage ${ACTION} $@
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
else else
usage usage
fi fi
exit 0 exit 0
\ No newline at end of file
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