diff options
Diffstat (limited to '')
-rw-r--r-- | src/regress/lib/libcrypto/x509/Makefile | 10 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/x509/x509_name_test.c | 123 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/x509/x509name.c | 62 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/x509/x509name.expected | 3 |
4 files changed, 125 insertions, 73 deletions
diff --git a/src/regress/lib/libcrypto/x509/Makefile b/src/regress/lib/libcrypto/x509/Makefile index 19e65efddd..94e9e476a0 100644 --- a/src/regress/lib/libcrypto/x509/Makefile +++ b/src/regress/lib/libcrypto/x509/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # $OpenBSD: Makefile,v 1.24 2025/03/15 06:37:49 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.25 2025/05/05 06:33:34 tb Exp $ |
2 | 2 | ||
3 | PROGS = constraints verify x509attribute x509name x509req_ext callback | 3 | PROGS = constraints verify x509attribute x509req_ext callback |
4 | PROGS += expirecallback callbackfailures x509_asn1 x509_extensions_test | 4 | PROGS += expirecallback callbackfailures x509_asn1 x509_extensions_test |
5 | PROGS += x509_name_test | 5 | PROGS += x509_name_test |
6 | LDADD = -lcrypto | 6 | LDADD = -lcrypto |
@@ -16,7 +16,7 @@ CFLAGS += -I${.CURDIR}/../../../../lib/libcrypto/bytestring | |||
16 | 16 | ||
17 | SUBDIR += bettertls policy rfc3779 | 17 | SUBDIR += bettertls policy rfc3779 |
18 | 18 | ||
19 | CLEANFILES += x509name.result callback.out | 19 | CLEANFILES += callback.out |
20 | 20 | ||
21 | .if make(clean) || make(cleandir) | 21 | .if make(clean) || make(cleandir) |
22 | . if ${.OBJDIR} != ${.CURDIR} | 22 | . if ${.OBJDIR} != ${.CURDIR} |
@@ -29,10 +29,6 @@ run-regress-verify: verify | |||
29 | perl ${.CURDIR}/make-dir-roots.pl ${.CURDIR}/../certs . | 29 | perl ${.CURDIR}/make-dir-roots.pl ${.CURDIR}/../certs . |
30 | ./verify ${.CURDIR}/../certs | 30 | ./verify ${.CURDIR}/../certs |
31 | 31 | ||
32 | run-regress-x509name: x509name | ||
33 | ./x509name > x509name.result | ||
34 | diff -u ${.CURDIR}/x509name.expected x509name.result | ||
35 | |||
36 | run-regress-callback: callback | 32 | run-regress-callback: callback |
37 | ./callback ${.CURDIR}/../certs | 33 | ./callback ${.CURDIR}/../certs |
38 | perl ${.CURDIR}/callback.pl callback.out | 34 | perl ${.CURDIR}/callback.pl callback.out |
diff --git a/src/regress/lib/libcrypto/x509/x509_name_test.c b/src/regress/lib/libcrypto/x509/x509_name_test.c index eaf7076d74..24e62cc766 100644 --- a/src/regress/lib/libcrypto/x509/x509_name_test.c +++ b/src/regress/lib/libcrypto/x509/x509_name_test.c | |||
@@ -1,7 +1,9 @@ | |||
1 | /* $OpenBSD: x509_name_test.c,v 1.2 2025/03/19 11:19:17 tb Exp $ */ | 1 | /* $OpenBSD: x509_name_test.c,v 1.3 2025/05/05 06:33:34 tb Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2025 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2025 Theo Buehler <tb@openbsd.org> |
5 | * Copyright (c) 2025 Kenjiro Nakayama <nakayamakenjiro@gmail.com> | ||
6 | * Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> | ||
5 | * | 7 | * |
6 | * Permission to use, copy, modify, and distribute this software for any | 8 | * Permission to use, copy, modify, and distribute this software for any |
7 | * purpose with or without fee is hereby granted, provided that the above | 9 | * purpose with or without fee is hereby granted, provided that the above |
@@ -288,12 +290,131 @@ x509_name_compat_test(void) | |||
288 | return failed; | 290 | return failed; |
289 | } | 291 | } |
290 | 292 | ||
293 | static const struct x509_name_entry_test { | ||
294 | const char *field; | ||
295 | const char *value; | ||
296 | int loc; | ||
297 | int set; | ||
298 | const char *expected_str; | ||
299 | const int expected_set[4]; | ||
300 | const int expected_count; | ||
301 | } entry_tests[] = { | ||
302 | { | ||
303 | .field = "ST", | ||
304 | .value = "BaWue", | ||
305 | .loc = -1, | ||
306 | .set = 0, | ||
307 | .expected_str = "ST=BaWue", | ||
308 | .expected_set = { 0 }, | ||
309 | .expected_count = 1, | ||
310 | }, | ||
311 | { | ||
312 | .field = "O", | ||
313 | .value = "KIT", | ||
314 | .loc = -1, | ||
315 | .set = 0, | ||
316 | .expected_str = "ST=BaWue, O=KIT", | ||
317 | .expected_set = { 0, 1 }, | ||
318 | .expected_count = 2, | ||
319 | }, | ||
320 | { | ||
321 | .field = "L", | ||
322 | .value = "Karlsruhe", | ||
323 | .loc = 1, | ||
324 | .set = 0, | ||
325 | .expected_str = "ST=BaWue, L=Karlsruhe, O=KIT", | ||
326 | .expected_set = { 0, 1, 2 }, | ||
327 | .expected_count = 3, | ||
328 | }, | ||
329 | { | ||
330 | .field = "C", | ||
331 | .value = "DE", | ||
332 | .loc = 0, | ||
333 | .set = 1, | ||
334 | .expected_str = "C=DE + ST=BaWue, L=Karlsruhe, O=KIT", | ||
335 | .expected_set = { 0, 0, 1, 2 }, | ||
336 | .expected_count = 4, | ||
337 | }, | ||
338 | }; | ||
339 | |||
340 | #define N_ENTRY_TESTS (sizeof(entry_tests) / sizeof(entry_tests[0])) | ||
341 | |||
342 | static int | ||
343 | verify_x509_name_output(X509_NAME *name, const struct x509_name_entry_test *tc) | ||
344 | { | ||
345 | BIO *bio; | ||
346 | char *got; | ||
347 | long got_len; | ||
348 | int loc, ret; | ||
349 | int failed = 1; | ||
350 | |||
351 | if ((bio = BIO_new(BIO_s_mem())) == NULL) | ||
352 | goto fail; | ||
353 | |||
354 | if ((ret = X509_NAME_print_ex(bio, name, 0, XN_FLAG_SEP_CPLUS_SPC)) == -1) | ||
355 | goto fail; | ||
356 | |||
357 | if ((got_len = BIO_get_mem_data(bio, &got)) < 0) | ||
358 | goto fail; | ||
359 | |||
360 | if (ret != got_len || strlen(tc->expected_str) != (size_t)ret) | ||
361 | goto fail; | ||
362 | |||
363 | if (strncmp(tc->expected_str, got, got_len) != 0) | ||
364 | goto fail; | ||
365 | |||
366 | if (X509_NAME_entry_count(name) != tc->expected_count) | ||
367 | goto fail; | ||
368 | |||
369 | for (loc = 0; loc < X509_NAME_entry_count(name); loc++) { | ||
370 | X509_NAME_ENTRY *e = X509_NAME_get_entry(name, loc); | ||
371 | if (e == NULL || X509_NAME_ENTRY_set(e) != tc->expected_set[loc]) | ||
372 | goto fail; | ||
373 | } | ||
374 | |||
375 | failed = 0; | ||
376 | |||
377 | fail: | ||
378 | BIO_free(bio); | ||
379 | |||
380 | return failed; | ||
381 | } | ||
382 | |||
383 | static int | ||
384 | x509_name_add_entry_test(void) | ||
385 | { | ||
386 | X509_NAME *name; | ||
387 | int failed = 1; | ||
388 | |||
389 | if ((name = X509_NAME_new()) == NULL) | ||
390 | goto done; | ||
391 | |||
392 | for (size_t i = 0; i < N_ENTRY_TESTS; i++) { | ||
393 | const struct x509_name_entry_test *t = &entry_tests[i]; | ||
394 | |||
395 | if (!X509_NAME_add_entry_by_txt(name, t->field, MBSTRING_ASC, | ||
396 | (const unsigned char *)t->value, -1, t->loc, t->set)) | ||
397 | goto done; | ||
398 | |||
399 | if (verify_x509_name_output(name, t)) | ||
400 | goto done; | ||
401 | } | ||
402 | |||
403 | failed = 0; | ||
404 | |||
405 | done: | ||
406 | X509_NAME_free(name); | ||
407 | |||
408 | return failed; | ||
409 | } | ||
410 | |||
291 | int | 411 | int |
292 | main(void) | 412 | main(void) |
293 | { | 413 | { |
294 | int failed = 0; | 414 | int failed = 0; |
295 | 415 | ||
296 | failed |= x509_name_compat_test(); | 416 | failed |= x509_name_compat_test(); |
417 | failed |= x509_name_add_entry_test(); | ||
297 | 418 | ||
298 | return failed; | 419 | return failed; |
299 | } | 420 | } |
diff --git a/src/regress/lib/libcrypto/x509/x509name.c b/src/regress/lib/libcrypto/x509/x509name.c deleted file mode 100644 index 9deeeb2986..0000000000 --- a/src/regress/lib/libcrypto/x509/x509name.c +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* $OpenBSD: x509name.c,v 1.3 2021/10/31 08:27:15 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <stdio.h> | ||
20 | |||
21 | #include <openssl/x509.h> | ||
22 | |||
23 | static void debug_print(X509_NAME *); | ||
24 | |||
25 | static void | ||
26 | debug_print(X509_NAME *name) | ||
27 | { | ||
28 | int loc; | ||
29 | |||
30 | for (loc = 0; loc < X509_NAME_entry_count(name); loc++) | ||
31 | printf("%d:", | ||
32 | X509_NAME_ENTRY_set(X509_NAME_get_entry(name, loc))); | ||
33 | putchar(' '); | ||
34 | X509_NAME_print_ex_fp(stdout, name, 0, XN_FLAG_SEP_CPLUS_SPC); | ||
35 | putchar('\n'); | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(void) | ||
40 | { | ||
41 | X509_NAME *name; | ||
42 | |||
43 | if ((name = X509_NAME_new()) == NULL) | ||
44 | err(1, NULL); | ||
45 | X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, | ||
46 | "BaWue", -1, -1, 0); | ||
47 | X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, | ||
48 | "KIT", -1, -1, 0); | ||
49 | debug_print(name); | ||
50 | |||
51 | X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, | ||
52 | "Karlsruhe", -1, 1, 0); | ||
53 | debug_print(name); | ||
54 | |||
55 | X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, | ||
56 | "DE", -1, 0, 1); | ||
57 | debug_print(name); | ||
58 | |||
59 | X509_NAME_free(name); | ||
60 | |||
61 | return 0; | ||
62 | } | ||
diff --git a/src/regress/lib/libcrypto/x509/x509name.expected b/src/regress/lib/libcrypto/x509/x509name.expected deleted file mode 100644 index 6cee7cc435..0000000000 --- a/src/regress/lib/libcrypto/x509/x509name.expected +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | 0:1: ST=BaWue, O=KIT | ||
2 | 0:1:2: ST=BaWue, L=Karlsruhe, O=KIT | ||
3 | 0:0:1:2: C=DE + ST=BaWue, L=Karlsruhe, O=KIT | ||