From c0cadc993c04e2ed79c00e8e7361b98e9c0feb16 Mon Sep 17 00:00:00 2001 From: Arzhan Kinzhalin Date: Thu, 6 Jul 2017 07:54:58 +0000 Subject: [PATCH] Implement list command. --- clrtrust | 52 ++++++++++++++++++++++++++++-- test/generate-clear.bats | 6 ++++ test/generate-local.bats | 6 ++++ test/generate-mix.bats | 6 ++++ test/generate-with-distrusted.bats | 5 +++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/clrtrust b/clrtrust index 5f27425..bc79f84 100755 --- a/clrtrust +++ b/clrtrust @@ -231,11 +231,59 @@ EOF } function print_list_help { - true + cat < + File: + Authority: + Expires: +EOF } function cmd_list { - true + local _certs + local _id + local _info + local _indent + while [ $# -gt 0 ]; do + case $1 in + -h|--help) + print_list_help + return 0 + ;; + esac + done + _id=1 + _indent=" " + if [ ! -d ${CLR_TRUST_STORE}/anchors ]; then + 1>&2 echo "${CLR_TRUST_STORE} is not a trust store." \ + " Use ${BASENAME} generate to create the store." + return 128 + fi + _certs=`find ${CLR_TRUST_STORE}/anchors -maxdepth 1 -type f | LC_COLLATE=C sort` + if [ -z ${_certs} ]; then + test ! -z $VERBOSE && echo "Nothing is trusted. No anchors found in ${CLR_TRUST_STORE}." + return 0 + fi + + echo "$_certs" | while read _crt; do + _info=`openssl x509 -in ${_crt} -noout -issuer -enddate \ + | sed -e "s/^issuer=\s*/${_indent}Authority: /" -e "s/^notAfter=\s*/${_indent}Expires: /"` + if [ $? -ne 0 ]; then + 1>&2 echo "${_crt} is not an X.509 certificate." + fi + cat <