Fix end-date format depending on system

This commit is contained in:
Jérémy Dubois 2022-03-29 18:15:57 +02:00
parent 047c6e334a
commit 6d71a5a177
1 changed files with 21 additions and 6 deletions

View File

@ -49,7 +49,7 @@ Create a client certificate with key and CSR directly generated on server :
-p, --password prompt the user for a password to set on the client key
--password-file if provided with a path to a readable file, the first line is read and set as password on the client key
--days specify how many days the certificate should be valid
--end-date specify until which date the certificate should be valid, in MM/DD/[YY]YY [hh:mm:ss] format
--end-date specify until which date the certificate should be valid, in "MM/DD/YYYY hh:mm:ss" format
--non-interactive do not prompt the user, and exit if an error occurs
--replace-existing if the certificate already exists, revoke it before creating a new one
@ -490,12 +490,24 @@ create() {
crt_expiration_arg="-days ${days}"
fi
if [ -n "${end_date}" ]; then
cert_end_date=$(TZ=:Zulu date --date "${end_date}" +"%Y%m%d%H%M%SZ" 2> /dev/null)
# shellcheck disable=SC2181
if [ "$?" -ne 0 ]; then
error "Invalid end date format : \`${end_date}' can't be parsed by date(1)"
if [ "${SYSTEM}" = "linux" ]; then
cert_end_date=$(TZ=:Zulu date --date "${end_date}" +"%Y%m%d%H%M%SZ" 2> /dev/null)
# shellcheck disable=SC2181
if [ "$?" -ne 0 ]; then
error "Invalid end date format: \`${end_date}' can't be parsed by date(1). Expected format: MM/DD/[YY]YY [hh[:mm[:ss]]]."
else
crt_expiration_arg="-enddate ${cert_end_date}"
fi
elif [ "${SYSTEM}" = "openbsd" ]; then
cert_end_date=$(TZ=:Zulu date -f "%m/%d/%C%y %H:%M:%S" -j "${end_date}" +"%Y%m%d%H%M%SZ" 2> /dev/null)
# shellcheck disable=SC2181
if [ "$?" -ne 0 ]; then
error "Invalid end date format: \`${end_date}' can't be parsed by date(1). Expected format: MM/DD/YYYY hh:mm:ss."
else
crt_expiration_arg="-enddate ${cert_end_date}"
fi
else
crt_expiration_arg="-enddate ${cert_end_date}"
error "System ${SYSTEM} not supported."
fi
fi
if [ "${non_interactive}" -eq 1 ]; then
@ -901,6 +913,9 @@ is_group() {
}
main() {
# Know what system we are on, because OpenBSD and Linux do not implement date(1) in the same way
SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
# default config
# TODO : override with /etc/default/shellpki
CONF_FILE="/etc/shellpki/openssl.cnf"