summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2022-02-12 12:42:19 +0000
committerjsing <>2022-02-12 12:42:19 +0000
commit6f9eb565f453fa9044079a79dec3faa21c640811 (patch)
tree0b13562f44700224dbde183b88260a7fd00a27b5 /src
parented44c785483d961996be1105c8471657b251bf1d (diff)
downloadopenbsd-6f9eb565f453fa9044079a79dec3faa21c640811.tar.gz
openbsd-6f9eb565f453fa9044079a79dec3faa21c640811.tar.bz2
openbsd-6f9eb565f453fa9044079a79dec3faa21c640811.zip
Add test coverage for OBJ_txt2obj()/OBJ_obj2txt() with no_name == 0.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/objects/objectstest.c103
1 files changed, 99 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/objects/objectstest.c b/src/regress/lib/libcrypto/objects/objectstest.c
index 18b57436c8..9f28b6329a 100644
--- a/src/regress/lib/libcrypto/objects/objectstest.c
+++ b/src/regress/lib/libcrypto/objects/objectstest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: objectstest.c,v 1.3 2022/02/12 03:02:47 jsing Exp $ */ 1/* $OpenBSD: objectstest.c,v 1.4 2022/02/12 12:42:19 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017, 2022 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2017, 2022 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -93,6 +93,15 @@ struct obj_test obj_tests[] = {
93 .data_len = 3, 93 .data_len = 3,
94 }, 94 },
95 { 95 {
96 .oid = "2.23.43.1",
97 .sn = "wap-wsg",
98 .nid = NID_wap_wsg,
99 .data = {
100 0x67, 0x2b, 0x01,
101 },
102 .data_len = 3,
103 },
104 {
96 .oid = "1.3.6.1.4.1.11129.2.4.5", 105 .oid = "1.3.6.1.4.1.11129.2.4.5",
97 .sn = "ct_cert_scts", 106 .sn = "ct_cert_scts",
98 .ln = "CT Certificate SCTs", 107 .ln = "CT Certificate SCTs",
@@ -256,9 +265,7 @@ obj_oid_test(struct obj_test *ot)
256 if (ot->oid == NULL) 265 if (ot->oid == NULL)
257 return 0; 266 return 0;
258 267
259 /* XXX - need to also test with no_name == 0. */ 268 if ((obj = OBJ_txt2obj(ot->oid, 0)) == NULL) {
260
261 if ((obj = OBJ_txt2obj(ot->oid, 1)) == NULL) {
262 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s'\n", ot->oid); 269 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s'\n", ot->oid);
263 goto failed; 270 goto failed;
264 } 271 }
@@ -303,6 +310,93 @@ obj_oid_tests(void)
303 return failed; 310 return failed;
304} 311}
305 312
313static int
314obj_txt_test(struct obj_test *ot)
315{
316 ASN1_OBJECT *obj = NULL;
317 const char *want;
318 char buf[1024];
319 int len, nid;
320 int failed = 1;
321
322 if (ot->oid == NULL)
323 return 0;
324
325 if (ot->sn != NULL) {
326 if ((obj = OBJ_txt2obj(ot->sn, 0)) == NULL) {
327 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s'\n",
328 ot->sn);
329 goto failed;
330 }
331 if ((nid = OBJ_obj2nid(obj)) != ot->nid) {
332 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s', "
333 "got nid %d want %d\n", ot->sn, nid, ot->nid);
334 goto failed;
335 }
336 ASN1_OBJECT_free(obj);
337 obj = NULL;
338 }
339 if (ot->ln != NULL) {
340 if ((obj = OBJ_txt2obj(ot->ln, 0)) == NULL) {
341 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s'\n",
342 ot->ln);
343 goto failed;
344 }
345 if ((nid = OBJ_obj2nid(obj)) != ot->nid) {
346 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s', "
347 "got nid %d want %d\n", ot->ln, nid, ot->nid);
348 goto failed;
349 }
350 ASN1_OBJECT_free(obj);
351 obj = NULL;
352 }
353
354 if ((obj = OBJ_txt2obj(ot->oid, 0)) == NULL) {
355 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s'\n", ot->oid);
356 goto failed;
357 }
358 if ((nid = OBJ_obj2nid(obj)) != ot->nid) {
359 fprintf(stderr, "FAIL: OBJ_txt2obj() failed for '%s', "
360 "got nid %d want %d\n", ot->oid, nid, ot->nid);
361 goto failed;
362 }
363
364 len = OBJ_obj2txt(buf, sizeof(buf), obj, 0);
365 if (len <= 0 || (size_t)len >= sizeof(buf)) {
366 fprintf(stderr, "FAIL: OBJ_obj2txt() failed for '%s'\n", ot->oid);
367 goto failed;
368 }
369 want = ot->ln;
370 if (want == NULL)
371 want = ot->sn;
372 if (want == NULL)
373 want = ot->oid;
374 if (strcmp(buf, want) != 0) {
375 fprintf(stderr, "FAIL: OBJ_obj2txt() returned '%s', want '%s'\n",
376 buf, want);
377 goto failed;
378 }
379
380 failed = 0;
381
382 failed:
383 ASN1_OBJECT_free(obj);
384
385 return failed;
386}
387
388static int
389obj_txt_tests(void)
390{
391 int failed = 0;
392 size_t i;
393
394 for (i = 0; i < N_OBJ_TESTS; i++)
395 failed |= obj_txt_test(&obj_tests[i]);
396
397 return failed;
398}
399
306/* OID 1.3.18446744073709551615 (64 bits). */ 400/* OID 1.3.18446744073709551615 (64 bits). */
307const uint8_t asn1_large_oid1[] = { 401const uint8_t asn1_large_oid1[] = {
308 0x06, 0x0b, 402 0x06, 0x0b,
@@ -432,6 +526,7 @@ main(int argc, char **argv)
432 failed |= obj_name_tests(); 526 failed |= obj_name_tests();
433 failed |= obj_nid_tests(); 527 failed |= obj_nid_tests();
434 failed |= obj_oid_tests(); 528 failed |= obj_oid_tests();
529 failed |= obj_txt_tests();
435 failed |= obj_oid_large_tests(); 530 failed |= obj_oid_large_tests();
436 531
437 return (failed); 532 return (failed);