summaryrefslogtreecommitdiff
path: root/regress/lib/libcrypto
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2022-06-30 09:13:50 +0000
committerBob Beck <beck@cvs.openbsd.org>2022-06-30 09:13:50 +0000
commitb6b4f70137ac6df61e1155295020cae5c61a6662 (patch)
treef01f7e3b4b014ab914e432e31e0bf002967050ea /regress/lib/libcrypto
parent4b8a7de62bf02963edfe1305a75722877c5bd689 (diff)
Add valid time test from ruby regress, and check ASN1_time_to_tm
against recorded time value.
Diffstat (limited to 'regress/lib/libcrypto')
-rw-r--r--regress/lib/libcrypto/asn1/asn1time.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/regress/lib/libcrypto/asn1/asn1time.c b/regress/lib/libcrypto/asn1/asn1time.c
index ca54087dd78..6709e7af4a8 100644
--- a/regress/lib/libcrypto/asn1/asn1time.c
+++ b/regress/lib/libcrypto/asn1/asn1time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1time.c,v 1.12 2022/06/30 08:41:01 beck Exp $ */
+/* $OpenBSD: asn1time.c,v 1.13 2022/06/30 09:13:49 beck Exp $ */
/*
* Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
*
@@ -100,6 +100,16 @@ struct asn1_time_test asn1_goodtime_tests[] = {
struct asn1_time_test asn1_gentime_tests[] = {
{
+ .str = "20161208193400Z",
+ .data = "20161208193400Z",
+ .time = 1481225640,
+ .der = {
+ 0x18, 0x0f, 0x32, 0x30, 0x31, 0x36, 0x31, 0x32,
+ 0x30, 0x38, 0x31, 0x39, 0x33, 0x34, 0x30, 0x30,
+ 0x5a,
+ },
+ },
+ {
.str = "19700101000000Z",
.data = "19700101000000Z",
.time = 0,
@@ -279,6 +289,7 @@ asn1_gentime_test(int test_no, struct asn1_time_test *att)
ASN1_GENERALIZEDTIME *gt = NULL;
int failure = 1;
int len;
+ struct tm tm;
if (ASN1_GENERALIZEDTIME_set_string(NULL, att->str) != 1) {
fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n",
@@ -297,6 +308,21 @@ asn1_gentime_test(int test_no, struct asn1_time_test *att)
if (asn1_compare_str(test_no, gt, att->str) != 0)
goto done;
+ if (ASN1_TIME_to_tm(gt, &tm) == 0) {
+ fprintf(stderr, "FAIL: test %i - ASN1_time_to_tm failed '%s'\n",
+ test_no, att->str);
+ goto done;
+ }
+
+ if (timegm(&tm) != att->time) {
+ /* things with crappy time_t should die in fire */
+ int64_t a = timegm(&tm);
+ int64_t b = att->time;
+ fprintf(stderr, "FAIL: test %i - times don't match, expected %lld got %lld\n",
+ test_no, b, a);
+ goto done;
+ }
+
if ((len = i2d_ASN1_GENERALIZEDTIME(gt, &p)) <= 0) {
fprintf(stderr, "FAIL: test %i - i2d_ASN1_GENERALIZEDTIME "
"failed\n", test_no);