summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbeck <>2022-06-30 08:32:26 +0000
committerbeck <>2022-06-30 08:32:26 +0000
commite739e7135a34bf40c24a1e1e30017dc20fabd066 (patch)
tree915044bb941a94e211bf49a3546395783da79f99 /src
parent1a5596563dedb8ac504b1b0982688c2079b13486 (diff)
downloadopenbsd-e739e7135a34bf40c24a1e1e30017dc20fabd066.tar.gz
openbsd-e739e7135a34bf40c24a1e1e30017dc20fabd066.tar.bz2
openbsd-e739e7135a34bf40c24a1e1e30017dc20fabd066.zip
Add tests for times missing seconds, and to be able to test
invalid generalized times specifically
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1time.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1time.c b/src/regress/lib/libcrypto/asn1/asn1time.c
index d3927929ca..2bcf3d69ca 100644
--- a/src/regress/lib/libcrypto/asn1/asn1time.c
+++ b/src/regress/lib/libcrypto/asn1/asn1time.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1time.c,v 1.10 2022/06/27 13:54:58 beck Exp $ */ 1/* $OpenBSD: asn1time.c,v 1.11 2022/06/30 08:32:26 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -66,6 +66,32 @@ struct asn1_time_test asn1_invtime_tests[] = {
66 { 66 {
67 .str = "aaaaaaaaaaaaaaZ", 67 .str = "aaaaaaaaaaaaaaZ",
68 }, 68 },
69 /* utc time with omitted seconds, should fail */
70 {
71 .str = "1609082343Z",
72 },
73};
74
75struct asn1_time_test asn1_invgentime_tests[] = {
76 /* Generalized time with omitted seconds, should fail */
77 {
78 .str = "201612081934Z",
79 },
80};
81
82struct asn1_time_test asn1_goodtime_tests[] = {
83 {
84 .str = "99990908234339Z",
85 .time = 1,
86 },
87 {
88 .str = "201612081934Z",
89 .time = 1,
90 },
91 {
92 .str = "1609082343Z",
93 .time = 0,
94 },
69}; 95};
70 96
71struct asn1_time_test asn1_gentime_tests[] = { 97struct asn1_time_test asn1_gentime_tests[] = {
@@ -132,6 +158,8 @@ struct asn1_time_test asn1_utctime_tests[] = {
132 158
133#define N_INVTIME_TESTS \ 159#define N_INVTIME_TESTS \
134 (sizeof(asn1_invtime_tests) / sizeof(*asn1_invtime_tests)) 160 (sizeof(asn1_invtime_tests) / sizeof(*asn1_invtime_tests))
161#define N_INVGENTIME_TESTS \
162 (sizeof(asn1_invgentime_tests) / sizeof(*asn1_invgentime_tests))
135#define N_GENTIME_TESTS \ 163#define N_GENTIME_TESTS \
136 (sizeof(asn1_gentime_tests) / sizeof(*asn1_gentime_tests)) 164 (sizeof(asn1_gentime_tests) / sizeof(*asn1_gentime_tests))
137#define N_UTCTIME_TESTS \ 165#define N_UTCTIME_TESTS \
@@ -188,7 +216,7 @@ asn1_compare_str(int test_no, struct asn1_string_st *asn1str, const char *str)
188} 216}
189 217
190static int 218static int
191asn1_invtime_test(int test_no, struct asn1_time_test *att) 219asn1_invtime_test(int test_no, struct asn1_time_test *att, int gen)
192{ 220{
193 ASN1_GENERALIZEDTIME *gt = NULL; 221 ASN1_GENERALIZEDTIME *gt = NULL;
194 ASN1_UTCTIME *ut = NULL; 222 ASN1_UTCTIME *ut = NULL;
@@ -207,6 +235,12 @@ asn1_invtime_test(int test_no, struct asn1_time_test *att)
207 "GENERALIZEDTIME string '%s'\n", test_no, att->str); 235 "GENERALIZEDTIME string '%s'\n", test_no, att->str);
208 goto done; 236 goto done;
209 } 237 }
238
239 if (gen) {
240 failure = 0;
241 goto done;
242 }
243
210 if (ASN1_UTCTIME_set_string(ut, att->str) != 0) { 244 if (ASN1_UTCTIME_set_string(ut, att->str) != 0) {
211 fprintf(stderr, "FAIL: test %i - successfully set UTCTIME " 245 fprintf(stderr, "FAIL: test %i - successfully set UTCTIME "
212 "string '%s'\n", test_no, att->str); 246 "string '%s'\n", test_no, att->str);
@@ -433,7 +467,13 @@ main(int argc, char **argv)
433 fprintf(stderr, "Invalid time tests...\n"); 467 fprintf(stderr, "Invalid time tests...\n");
434 for (i = 0; i < N_INVTIME_TESTS; i++) { 468 for (i = 0; i < N_INVTIME_TESTS; i++) {
435 att = &asn1_invtime_tests[i]; 469 att = &asn1_invtime_tests[i];
436 failed |= asn1_invtime_test(i, att); 470 failed |= asn1_invtime_test(i, att, 0);
471 }
472
473 fprintf(stderr, "Invalid generalized time tests...\n");
474 for (i = 0; i < N_INVGENTIME_TESTS; i++) {
475 att = &asn1_invgentime_tests[i];
476 failed |= asn1_invtime_test(i, att, 0);
437 } 477 }
438 478
439 fprintf(stderr, "GENERALIZEDTIME tests...\n"); 479 fprintf(stderr, "GENERALIZEDTIME tests...\n");