Extract function cert_end_date()

This commit is contained in:
Jérémy Lecour 2020-05-04 23:12:48 +02:00 committed by Jérémy Lecour
parent 7630d8b182
commit d8a5d04fd0
2 changed files with 6 additions and 1 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Rename internal function usage() to show_usage()
* More readable variable names
* verify_ca_password() looks for a previously set password and verifies it
* Extract function cert_end_date()
### Deprecated

View file

@ -587,6 +587,10 @@ list() {
echo "${certs}" | grep -Eo "CN\s*=[^,/]*" | cut -d'=' -f2 | xargs -n1
}
cert_end_date() {
"${OPENSSL_BIN}" x509 -noout -enddate -in "${1}" | cut -d'=' -f2
}
check() {
# default expiration alert
# TODO : permit override with parameters
@ -594,7 +598,7 @@ check() {
cur_epoch=$(date -u +'%s')
for cert in ${CRT_DIR}/*; do
end_date=$(openssl x509 -noout -enddate -in "${cert}" | cut -d'=' -f2)
end_date=$(cert_end_date "${cert}")
end_epoch=$(date -ud "${end_date}" +'%s')
diff_epoch=$(( end_epoch - cur_epoch ))
diff_day=$(( diff_epoch / 60 / 60 / 24 ))