We use bash scripts and the openssl command line tool to maintain our internal PKI chain, this was the first thing that came to mind when scripting the auto renewal procedures:
is_cert_valid () {
# pem cert, pem cert chain, timestamp
local signed="$1" signer="$2" at_time="$3"
openssl verify -attime "$at_time" -CAfile "$signer" "$signed"
return $?
}
However, the exit code for openssl verify
does not reflect the validity of the given certificate, but (as far as I understand it) if the command failed to perform the check.
How would one go about rewriting is_cert_valid
so that it becomes usable in bash if statements? Assuming such thing is possible without using other programming languages like python or c.