diff options
author | Richard Levitte <levitte@openssl.org> | 2022-12-09 16:57:28 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2022-12-13 15:40:16 +0100 |
commit | b79da97cf8751d7b196a87cc8bced0bb3334a0d3 (patch) | |
tree | 3e74383d27e4d29e7091f911a4d087c2ff73606d /crypto/objects | |
parent | 97b8db1af2f71059ecea986e4d12fc6a23699a74 (diff) |
Allow OBJ_create() to create an OBJ and NID with a NULL OID
We already permit this in crypto/objects/objects.txt, but not programatically,
although being able to do so programatically would be beneficial.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19876)
Diffstat (limited to 'crypto/objects')
-rw-r--r-- | crypto/objects/obj_dat.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index ea5d57a77e..ad476136ae 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -729,6 +729,12 @@ int OBJ_create(const char *oid, const char *sn, const char *ln) ASN1_OBJECT *tmpoid = NULL; int ok = 0; + /* With no arguments at all, nothing can be done */ + if (oid == NULL && sn == NULL && ln == NULL) { + ERR_raise(ERR_LIB_OBJ, ERR_R_PASSED_INVALID_ARGUMENT); + return 0; + } + /* Check to see if short or long name already present */ if ((sn != NULL && OBJ_sn2nid(sn) != NID_undef) || (ln != NULL && OBJ_ln2nid(ln) != NID_undef)) { @@ -736,10 +742,15 @@ int OBJ_create(const char *oid, const char *sn, const char *ln) return 0; } - /* Convert numerical OID string to an ASN1_OBJECT structure */ - tmpoid = OBJ_txt2obj(oid, 1); - if (tmpoid == NULL) - return 0; + if (oid != NULL) { + /* Convert numerical OID string to an ASN1_OBJECT structure */ + tmpoid = OBJ_txt2obj(oid, 1); + if (tmpoid == NULL) + return 0; + } else { + /* Create a no-OID ASN1_OBJECT */ + tmpoid = ASN1_OBJECT_new(); + } if (!ossl_obj_write_lock(1)) { ERR_raise(ERR_LIB_OBJ, ERR_R_UNABLE_TO_GET_WRITE_LOCK); @@ -748,7 +759,8 @@ int OBJ_create(const char *oid, const char *sn, const char *ln) } /* If NID is not NID_undef then object already exists */ - if (ossl_obj_obj2nid(tmpoid, 0) != NID_undef) { + if (oid != NULL + && ossl_obj_obj2nid(tmpoid, 0) != NID_undef) { ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS); goto err; } |