diff options
author | jsing <> | 2022-03-19 17:49:32 +0000 |
---|---|---|
committer | jsing <> | 2022-03-19 17:49:32 +0000 |
commit | d46a632ca35d3f62b29f97c14868a75a30a0ea74 (patch) | |
tree | d6cf88609bfc19f0101b68dd40457a903ba5c53a /src | |
parent | ee5ce96399d588340c4f57044a36ddb289fe2a7a (diff) | |
download | openbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.tar.gz openbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.tar.bz2 openbsd-d46a632ca35d3f62b29f97c14868a75a30a0ea74.zip |
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@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 39 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_locl.h | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 33 |
3 files changed, 43 insertions, 32 deletions
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 @@ | |||
1 | /* $OpenBSD: a_object.c,v 1.42 2022/03/19 17:35:52 jsing Exp $ */ | 1 | /* $OpenBSD: a_object.c,v 1.43 2022/03/19 17:49:32 jsing 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 | * |
@@ -475,6 +475,43 @@ i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *aobj) | |||
475 | return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0); | 475 | return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0); |
476 | } | 476 | } |
477 | 477 | ||
478 | ASN1_OBJECT * | ||
479 | t2i_ASN1_OBJECT_internal(const char *oid) | ||
480 | { | ||
481 | ASN1_OBJECT *aobj = NULL; | ||
482 | uint8_t *data = NULL; | ||
483 | size_t data_len; | ||
484 | CBB cbb; | ||
485 | CBS cbs; | ||
486 | |||
487 | memset(&cbb, 0, sizeof(cbb)); | ||
488 | |||
489 | CBS_init(&cbs, oid, strlen(oid)); | ||
490 | |||
491 | if (!CBB_init(&cbb, 0)) | ||
492 | goto err; | ||
493 | if (!a2c_ASN1_OBJECT_internal(&cbb, &cbs)) | ||
494 | goto err; | ||
495 | if (!CBB_finish(&cbb, &data, &data_len)) | ||
496 | goto err; | ||
497 | |||
498 | if (data_len > INT_MAX) | ||
499 | goto err; | ||
500 | |||
501 | if ((aobj = ASN1_OBJECT_new()) == NULL) | ||
502 | goto err; | ||
503 | |||
504 | aobj->data = data; | ||
505 | aobj->length = (int)data_len; | ||
506 | data = NULL; | ||
507 | |||
508 | err: | ||
509 | CBB_cleanup(&cbb); | ||
510 | free(data); | ||
511 | |||
512 | return aobj; | ||
513 | } | ||
514 | |||
478 | int | 515 | int |
479 | i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj) | 516 | i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj) |
480 | { | 517 | { |
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 @@ | |||
1 | /* $OpenBSD: asn1_locl.h,v 1.22 2022/03/13 14:58:14 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_locl.h,v 1.23 2022/03/19 17:49:32 jsing 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 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -201,5 +201,6 @@ int asn1_tag2charwidth(int tag); | |||
201 | 201 | ||
202 | int i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len, | 202 | int i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len, |
203 | int no_name); | 203 | int no_name); |
204 | ASN1_OBJECT *t2i_ASN1_OBJECT_internal(const char *oid); | ||
204 | 205 | ||
205 | __END_HIDDEN_DECLS | 206 | __END_HIDDEN_DECLS |
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 786bed6c7a..bcb7ee2dbb 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_dat.c,v 1.48 2022/03/02 11:28:00 jsing Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.49 2022/03/19 17:49:32 jsing 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 | * |
@@ -485,12 +485,7 @@ OBJ_obj2nid(const ASN1_OBJECT *a) | |||
485 | ASN1_OBJECT * | 485 | ASN1_OBJECT * |
486 | OBJ_txt2obj(const char *s, int no_name) | 486 | OBJ_txt2obj(const char *s, int no_name) |
487 | { | 487 | { |
488 | int nid = NID_undef; | 488 | int nid; |
489 | ASN1_OBJECT *op = NULL; | ||
490 | unsigned char *buf; | ||
491 | unsigned char *p; | ||
492 | const unsigned char *cp; | ||
493 | int i, j; | ||
494 | 489 | ||
495 | if (!no_name) { | 490 | if (!no_name) { |
496 | if (((nid = OBJ_sn2nid(s)) != NID_undef) || | 491 | if (((nid = OBJ_sn2nid(s)) != NID_undef) || |
@@ -498,29 +493,7 @@ OBJ_txt2obj(const char *s, int no_name) | |||
498 | return OBJ_nid2obj(nid); | 493 | return OBJ_nid2obj(nid); |
499 | } | 494 | } |
500 | 495 | ||
501 | /* Work out size of content octets */ | 496 | return t2i_ASN1_OBJECT_internal(s); |
502 | i = a2d_ASN1_OBJECT(NULL, 0, s, -1); | ||
503 | if (i <= 0) { | ||
504 | /* Don't clear the error */ | ||
505 | /*ERR_clear_error();*/ | ||
506 | return NULL; | ||
507 | } | ||
508 | /* Work out total size */ | ||
509 | j = ASN1_object_size(0, i, V_ASN1_OBJECT); | ||
510 | |||
511 | if ((buf = malloc(j)) == NULL) | ||
512 | return NULL; | ||
513 | |||
514 | p = buf; | ||
515 | /* Write out tag+length */ | ||
516 | ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); | ||
517 | /* Write out contents */ | ||
518 | a2d_ASN1_OBJECT(p, i, s, -1); | ||
519 | |||
520 | cp = buf; | ||
521 | op = d2i_ASN1_OBJECT(NULL, &cp, j); | ||
522 | free(buf); | ||
523 | return op; | ||
524 | } | 497 | } |
525 | 498 | ||
526 | int | 499 | int |