diff options
author | tb <> | 2025-02-08 03:41:36 +0000 |
---|---|---|
committer | tb <> | 2025-02-08 03:41:36 +0000 |
commit | e5c3598995f7ea0447aa4041ff08a6e099042a22 (patch) | |
tree | e78e83e8e98c42394460b54f4b18e5acf47272ef | |
parent | 5e6e46092b1b16ca7be107711e67259b335c8de6 (diff) | |
download | openbsd-e5c3598995f7ea0447aa4041ff08a6e099042a22.tar.gz openbsd-e5c3598995f7ea0447aa4041ff08a6e099042a22.tar.bz2 openbsd-e5c3598995f7ea0447aa4041ff08a6e099042a22.zip |
Move X509_NAME_print() next to its only internal caller
Fix includes while there
-rw-r--r-- | src/lib/libcrypto/asn1/a_strex.c | 86 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/t_x509.c | 98 |
2 files changed, 91 insertions, 93 deletions
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index 4ca0a092ee..a9ee0dd9c9 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_strex.c,v 1.35 2024/04/09 13:55:02 beck Exp $ */ | 1 | /* $OpenBSD: a_strex.c,v 1.36 2025/02/08 03:41:36 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -56,14 +56,19 @@ | |||
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdint.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
60 | #include <string.h> | 62 | #include <string.h> |
61 | 63 | ||
62 | #include <openssl/asn1.h> | 64 | #include <openssl/asn1.h> |
63 | #include <openssl/crypto.h> | 65 | #include <openssl/bio.h> |
66 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | 67 | #include <openssl/x509.h> |
65 | 68 | ||
66 | #include "asn1_local.h" | 69 | #include "asn1_local.h" |
70 | #include "bytestring.h" | ||
71 | #include "x509_local.h" | ||
67 | 72 | ||
68 | #include "charmap.h" | 73 | #include "charmap.h" |
69 | 74 | ||
@@ -560,6 +565,83 @@ do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent, | |||
560 | return outlen; | 565 | return outlen; |
561 | } | 566 | } |
562 | 567 | ||
568 | /* NID with SN of 1-2 letters, which X509_NAME_print() historically included. */ | ||
569 | static int | ||
570 | x509_name_entry_include(const X509_NAME_ENTRY *ne) | ||
571 | { | ||
572 | int nid; | ||
573 | |||
574 | if ((nid = OBJ_obj2nid(ne->object)) == NID_undef) | ||
575 | return 0; | ||
576 | |||
577 | switch (nid) { | ||
578 | case NID_commonName: | ||
579 | case NID_surname: | ||
580 | case NID_countryName: | ||
581 | case NID_localityName: | ||
582 | case NID_stateOrProvinceName: | ||
583 | case NID_organizationName: | ||
584 | case NID_organizationalUnitName: | ||
585 | case NID_givenName: | ||
586 | case NID_domainComponent: /* XXX - doesn't really belong here */ | ||
587 | return 1; | ||
588 | } | ||
589 | |||
590 | return 0; | ||
591 | } | ||
592 | |||
593 | int | ||
594 | X509_NAME_print(BIO *bio, const X509_NAME *name, int obase) | ||
595 | { | ||
596 | CBB cbb; | ||
597 | uint8_t *buf = NULL; | ||
598 | size_t buf_len; | ||
599 | const X509_NAME_ENTRY *ne; | ||
600 | int i; | ||
601 | int started = 0; | ||
602 | int ret = 0; | ||
603 | |||
604 | if (!CBB_init(&cbb, 0)) | ||
605 | goto err; | ||
606 | |||
607 | for (i = 0; i < sk_X509_NAME_ENTRY_num(name->entries); i++) { | ||
608 | ne = sk_X509_NAME_ENTRY_value(name->entries, i); | ||
609 | |||
610 | if (!x509_name_entry_include(ne)) | ||
611 | continue; | ||
612 | |||
613 | if (started) { | ||
614 | if (!CBB_add_u8(&cbb, ',')) | ||
615 | goto err; | ||
616 | if (!CBB_add_u8(&cbb, ' ')) | ||
617 | goto err; | ||
618 | } | ||
619 | |||
620 | if (!X509_NAME_ENTRY_add_cbb(&cbb, ne)) | ||
621 | goto err; | ||
622 | |||
623 | started = 1; | ||
624 | } | ||
625 | |||
626 | if (!CBB_add_u8(&cbb, '\0')) | ||
627 | goto err; | ||
628 | |||
629 | if (!CBB_finish(&cbb, &buf, &buf_len)) | ||
630 | goto err; | ||
631 | |||
632 | if (BIO_printf(bio, "%s", buf) < 0) | ||
633 | goto err; | ||
634 | |||
635 | ret = 1; | ||
636 | |||
637 | err: | ||
638 | CBB_cleanup(&cbb); | ||
639 | free(buf); | ||
640 | |||
641 | return ret; | ||
642 | } | ||
643 | LCRYPTO_ALIAS(X509_NAME_print); | ||
644 | |||
563 | /* Wrappers round the main functions */ | 645 | /* Wrappers round the main functions */ |
564 | 646 | ||
565 | int | 647 | int |
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index 3181dd2907..7cf4557314 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t_x509.c,v 1.50 2025/01/27 10:29:41 tb Exp $ */ | 1 | /* $OpenBSD: t_x509.c,v 1.51 2025/02/08 03:41:36 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -57,28 +57,21 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <limits.h> | 59 | #include <limits.h> |
60 | #include <stdint.h> | ||
60 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | #include <stdlib.h> | ||
61 | 63 | ||
62 | #include <openssl/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
63 | 65 | ||
64 | #include <openssl/bn.h> | 66 | #include <openssl/asn1.h> |
65 | #include <openssl/buffer.h> | 67 | #include <openssl/bio.h> |
66 | #include <openssl/err.h> | 68 | #include <openssl/err.h> |
69 | #include <openssl/evp.h> | ||
67 | #include <openssl/objects.h> | 70 | #include <openssl/objects.h> |
71 | #include <openssl/sha.h> | ||
68 | #include <openssl/x509.h> | 72 | #include <openssl/x509.h> |
69 | #include <openssl/x509v3.h> | 73 | #include <openssl/x509v3.h> |
70 | 74 | ||
71 | #ifndef OPENSSL_NO_DSA | ||
72 | #include <openssl/dsa.h> | ||
73 | #endif | ||
74 | #ifndef OPENSSL_NO_EC | ||
75 | #include <openssl/ec.h> | ||
76 | #endif | ||
77 | #ifndef OPENSSL_NO_RSA | ||
78 | #include <openssl/rsa.h> | ||
79 | #endif | ||
80 | |||
81 | #include "bytestring.h" | ||
82 | #include "evp_local.h" | 75 | #include "evp_local.h" |
83 | #include "x509_local.h" | 76 | #include "x509_local.h" |
84 | 77 | ||
@@ -490,80 +483,3 @@ ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | |||
490 | return (0); | 483 | return (0); |
491 | } | 484 | } |
492 | LCRYPTO_ALIAS(ASN1_UTCTIME_print); | 485 | LCRYPTO_ALIAS(ASN1_UTCTIME_print); |
493 | |||
494 | /* NID with SN of 1-2 letters, which X509_NAME_print() historically included. */ | ||
495 | static int | ||
496 | x509_name_entry_include(const X509_NAME_ENTRY *ne) | ||
497 | { | ||
498 | int nid; | ||
499 | |||
500 | if ((nid = OBJ_obj2nid(ne->object)) == NID_undef) | ||
501 | return 0; | ||
502 | |||
503 | switch (nid) { | ||
504 | case NID_commonName: | ||
505 | case NID_surname: | ||
506 | case NID_countryName: | ||
507 | case NID_localityName: | ||
508 | case NID_stateOrProvinceName: | ||
509 | case NID_organizationName: | ||
510 | case NID_organizationalUnitName: | ||
511 | case NID_givenName: | ||
512 | case NID_domainComponent: /* XXX - doesn't really belong here */ | ||
513 | return 1; | ||
514 | } | ||
515 | |||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | int | ||
520 | X509_NAME_print(BIO *bio, const X509_NAME *name, int obase) | ||
521 | { | ||
522 | CBB cbb; | ||
523 | uint8_t *buf = NULL; | ||
524 | size_t buf_len; | ||
525 | const X509_NAME_ENTRY *ne; | ||
526 | int i; | ||
527 | int started = 0; | ||
528 | int ret = 0; | ||
529 | |||
530 | if (!CBB_init(&cbb, 0)) | ||
531 | goto err; | ||
532 | |||
533 | for (i = 0; i < sk_X509_NAME_ENTRY_num(name->entries); i++) { | ||
534 | ne = sk_X509_NAME_ENTRY_value(name->entries, i); | ||
535 | |||
536 | if (!x509_name_entry_include(ne)) | ||
537 | continue; | ||
538 | |||
539 | if (started) { | ||
540 | if (!CBB_add_u8(&cbb, ',')) | ||
541 | goto err; | ||
542 | if (!CBB_add_u8(&cbb, ' ')) | ||
543 | goto err; | ||
544 | } | ||
545 | |||
546 | if (!X509_NAME_ENTRY_add_cbb(&cbb, ne)) | ||
547 | goto err; | ||
548 | |||
549 | started = 1; | ||
550 | } | ||
551 | |||
552 | if (!CBB_add_u8(&cbb, '\0')) | ||
553 | goto err; | ||
554 | |||
555 | if (!CBB_finish(&cbb, &buf, &buf_len)) | ||
556 | goto err; | ||
557 | |||
558 | if (BIO_printf(bio, "%s", buf) < 0) | ||
559 | goto err; | ||
560 | |||
561 | ret = 1; | ||
562 | |||
563 | err: | ||
564 | CBB_cleanup(&cbb); | ||
565 | free(buf); | ||
566 | |||
567 | return ret; | ||
568 | } | ||
569 | LCRYPTO_ALIAS(X509_NAME_print); | ||