From dc047d31fa0c31872db8601a1b9fcd35f24d8589 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Fri, 19 Aug 2016 16:21:21 +0100 Subject: Set certificate times in one function. Reviewed-by: Rich Salz --- apps/apps.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'apps/apps.c') diff --git a/apps/apps.c b/apps/apps.c index 40b31a5844..1ce632f003 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -2589,3 +2589,37 @@ void corrupt_signature(const ASN1_STRING *signature) unsigned char *s = signature->data; s[signature->length - 1] ^= 0x1; } + +int set_cert_times(X509 *x, const char *startdate, const char *enddate, + int days) +{ + int rv = 0; + ASN1_TIME *tm = ASN1_TIME_new(); + if (tm == NULL) + goto err; + if (startdate == NULL || strcmp(startdate, "today") == 0) { + if (!X509_gmtime_adj(tm, 0)) + goto err; + } else if (!ASN1_TIME_set_string(tm, startdate)) { + goto err; + } + + if (!X509_set_notBefore(x, tm)) + goto err; + + if (enddate == NULL) { + if (!X509_time_adj_ex(tm, days, 0, NULL)) + goto err; + } else if (!ASN1_TIME_set_string(tm, enddate)) { + goto err; + } + + if (!X509_set_notAfter(x, tm)) + goto err; + + rv = 1; + + err: + ASN1_TIME_free(tm); + return rv; +} -- cgit v1.2.3