From e5c3598995f7ea0447aa4041ff08a6e099042a22 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sat, 8 Feb 2025 03:41:36 +0000 Subject: Move X509_NAME_print() next to its only internal caller Fix includes while there --- src/lib/libcrypto/asn1/a_strex.c | 86 ++++++++++++++++++++++++++++++++++- 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 @@ -/* $OpenBSD: a_strex.c,v 1.35 2024/04/09 13:55:02 beck Exp $ */ +/* $OpenBSD: a_strex.c,v 1.36 2025/02/08 03:41:36 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -56,14 +56,19 @@ * */ +#include #include +#include #include #include -#include +#include +#include #include #include "asn1_local.h" +#include "bytestring.h" +#include "x509_local.h" #include "charmap.h" @@ -560,6 +565,83 @@ do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent, return outlen; } +/* NID with SN of 1-2 letters, which X509_NAME_print() historically included. */ +static int +x509_name_entry_include(const X509_NAME_ENTRY *ne) +{ + int nid; + + if ((nid = OBJ_obj2nid(ne->object)) == NID_undef) + return 0; + + switch (nid) { + case NID_commonName: + case NID_surname: + case NID_countryName: + case NID_localityName: + case NID_stateOrProvinceName: + case NID_organizationName: + case NID_organizationalUnitName: + case NID_givenName: + case NID_domainComponent: /* XXX - doesn't really belong here */ + return 1; + } + + return 0; +} + +int +X509_NAME_print(BIO *bio, const X509_NAME *name, int obase) +{ + CBB cbb; + uint8_t *buf = NULL; + size_t buf_len; + const X509_NAME_ENTRY *ne; + int i; + int started = 0; + int ret = 0; + + if (!CBB_init(&cbb, 0)) + goto err; + + for (i = 0; i < sk_X509_NAME_ENTRY_num(name->entries); i++) { + ne = sk_X509_NAME_ENTRY_value(name->entries, i); + + if (!x509_name_entry_include(ne)) + continue; + + if (started) { + if (!CBB_add_u8(&cbb, ',')) + goto err; + if (!CBB_add_u8(&cbb, ' ')) + goto err; + } + + if (!X509_NAME_ENTRY_add_cbb(&cbb, ne)) + goto err; + + started = 1; + } + + if (!CBB_add_u8(&cbb, '\0')) + goto err; + + if (!CBB_finish(&cbb, &buf, &buf_len)) + goto err; + + if (BIO_printf(bio, "%s", buf) < 0) + goto err; + + ret = 1; + + err: + CBB_cleanup(&cbb); + free(buf); + + return ret; +} +LCRYPTO_ALIAS(X509_NAME_print); + /* Wrappers round the main functions */ 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 @@ -/* $OpenBSD: t_x509.c,v 1.50 2025/01/27 10:29:41 tb Exp $ */ +/* $OpenBSD: t_x509.c,v 1.51 2025/02/08 03:41:36 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -57,28 +57,21 @@ */ #include +#include #include +#include #include -#include -#include +#include +#include #include +#include #include +#include #include #include -#ifndef OPENSSL_NO_DSA -#include -#endif -#ifndef OPENSSL_NO_EC -#include -#endif -#ifndef OPENSSL_NO_RSA -#include -#endif - -#include "bytestring.h" #include "evp_local.h" #include "x509_local.h" @@ -490,80 +483,3 @@ ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) return (0); } LCRYPTO_ALIAS(ASN1_UTCTIME_print); - -/* NID with SN of 1-2 letters, which X509_NAME_print() historically included. */ -static int -x509_name_entry_include(const X509_NAME_ENTRY *ne) -{ - int nid; - - if ((nid = OBJ_obj2nid(ne->object)) == NID_undef) - return 0; - - switch (nid) { - case NID_commonName: - case NID_surname: - case NID_countryName: - case NID_localityName: - case NID_stateOrProvinceName: - case NID_organizationName: - case NID_organizationalUnitName: - case NID_givenName: - case NID_domainComponent: /* XXX - doesn't really belong here */ - return 1; - } - - return 0; -} - -int -X509_NAME_print(BIO *bio, const X509_NAME *name, int obase) -{ - CBB cbb; - uint8_t *buf = NULL; - size_t buf_len; - const X509_NAME_ENTRY *ne; - int i; - int started = 0; - int ret = 0; - - if (!CBB_init(&cbb, 0)) - goto err; - - for (i = 0; i < sk_X509_NAME_ENTRY_num(name->entries); i++) { - ne = sk_X509_NAME_ENTRY_value(name->entries, i); - - if (!x509_name_entry_include(ne)) - continue; - - if (started) { - if (!CBB_add_u8(&cbb, ',')) - goto err; - if (!CBB_add_u8(&cbb, ' ')) - goto err; - } - - if (!X509_NAME_ENTRY_add_cbb(&cbb, ne)) - goto err; - - started = 1; - } - - if (!CBB_add_u8(&cbb, '\0')) - goto err; - - if (!CBB_finish(&cbb, &buf, &buf_len)) - goto err; - - if (BIO_printf(bio, "%s", buf) < 0) - goto err; - - ret = 1; - - err: - CBB_cleanup(&cbb); - free(buf); - - return ret; -} -LCRYPTO_ALIAS(X509_NAME_print); -- cgit v1.2.3-55-g6feb