From 74cd88c33b1abbf39ac4e076d93354f9de5ae643 Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Wed, 24 Jan 2018 11:43:03 +0100 Subject: [PATCH] List subcommand can filter by valid/revoked cert --- shellpki.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/shellpki.sh b/shellpki.sh index 91d9327..316a677 100755 --- a/shellpki.sh +++ b/shellpki.sh @@ -52,7 +52,7 @@ Revoke a client cert with is commonName (CN) : List all actually valid commonName (CN) : - ${0} list + ${0} list [-a|v|r] EOF } @@ -269,7 +269,35 @@ revoke() { } list() { - [ -f /etc/shellpki/ca/index.txt ] && grep -Eo "CN\s*=[^,/]*" "${CADIR}/index.txt" | cut -d'=' -f2 | xargs -n1 + [ -f /etc/shellpki/ca/index.txt ] || exit 0 + + list_valid=0 + list_revoked=1 + + while getopts "avr" opt; do + case "$opt" in + a) + list_valid=0 + list_revoked=0 + shift;; + v) + list_valid=0 + list_revoked=1 + shift;; + r) + list_valid=1 + list_revoked=0 + shift;; + esac + done + + [ "${list_valid}" -eq 0 ] && certs=$(grep "^V" "${CADIR}/index.txt") + + [ "${list_revoked}" -eq 0 ] && certs=$(grep "^R" "${CADIR}/index.txt") + + [ "${list_valid}" -eq 0 ] && [ "${list_revoked}" -eq 0 ] && certs=$(cat "${CADIR}/index.txt") + + echo "${certs}" | grep -Eo "CN\s*=[^,/]*" | cut -d'=' -f2 | xargs -n1 } main() {