From 2b63d13b51dbcbb4817452fa7523918d166ddd55 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 19 Mar 2022 17:49:32 +0000 Subject: Provide t2i_ASN1_OBJECT_internal() and use it for OBJ_txt2obj() The current OBJ_txt2obj() implementation converts the text to ASN.1 object content octets, builds a full DER encoding from it, then feeds the entire thing back through the DER to ASN.1 object conversion. Rather than doing this crazy dance, provide an t2i_ASN1_OBJECT_internal() function that converts the text to ASN.1 object content octets, then creates a new ASN1_OBJECT and attaches the content octets to it. ok inoguchi@ tb@ --- src/lib/libcrypto/asn1/a_object.c | 39 +++++++++++++++++++++++++++++++++++++- src/lib/libcrypto/asn1/asn1_locl.h | 3 ++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'src/lib/libcrypto/asn1') diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 0061ccb880..56a08a3cb4 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_object.c,v 1.42 2022/03/19 17:35:52 jsing Exp $ */ +/* $OpenBSD: a_object.c,v 1.43 2022/03/19 17:49:32 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -475,6 +475,43 @@ i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *aobj) return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0); } +ASN1_OBJECT * +t2i_ASN1_OBJECT_internal(const char *oid) +{ + ASN1_OBJECT *aobj = NULL; + uint8_t *data = NULL; + size_t data_len; + CBB cbb; + CBS cbs; + + memset(&cbb, 0, sizeof(cbb)); + + CBS_init(&cbs, oid, strlen(oid)); + + if (!CBB_init(&cbb, 0)) + goto err; + if (!a2c_ASN1_OBJECT_internal(&cbb, &cbs)) + goto err; + if (!CBB_finish(&cbb, &data, &data_len)) + goto err; + + if (data_len > INT_MAX) + goto err; + + if ((aobj = ASN1_OBJECT_new()) == NULL) + goto err; + + aobj->data = data; + aobj->length = (int)data_len; + data = NULL; + + err: + CBB_cleanup(&cbb); + free(data); + + return aobj; +} + int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj) { diff --git a/src/lib/libcrypto/asn1/asn1_locl.h b/src/lib/libcrypto/asn1/asn1_locl.h index 9a29a2b13f..12f7eadfb3 100644 --- a/src/lib/libcrypto/asn1/asn1_locl.h +++ b/src/lib/libcrypto/asn1/asn1_locl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_locl.h,v 1.22 2022/03/13 14:58:14 jsing Exp $ */ +/* $OpenBSD: asn1_locl.h,v 1.23 2022/03/19 17:49:32 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -201,5 +201,6 @@ int asn1_tag2charwidth(int tag); int i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len, int no_name); +ASN1_OBJECT *t2i_ASN1_OBJECT_internal(const char *oid); __END_HIDDEN_DECLS -- cgit v1.2.3-55-g6feb