diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2016-08-19 16:21:21 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2016-08-19 16:52:58 +0100 |
commit | dc047d31fa0c31872db8601a1b9fcd35f24d8589 (patch) | |
tree | 751aa4ab6e7c2344281f6f9f73130d07f650cee6 /apps/apps.c | |
parent | 3a60d6fa2f8a908d972f8787dc137acb7b8b26e3 (diff) | |
download | openssl-dc047d31fa0c31872db8601a1b9fcd35f24d8589.tar.gz |
Set certificate times in one function.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'apps/apps.c')
-rw-r--r-- | apps/apps.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; +} |