cms encrypt, better OBJ_nid2obj() return check
authorJames Muir <james@openssl.org>
Sat, 14 Oct 2023 23:36:57 +0000 (19:36 -0400)
committerTomas Mraz <tomas@openssl.org>
Wed, 18 Oct 2023 14:51:00 +0000 (16:51 +0200)
commitddeb0d37dd28ffba1b94f5033c34e6581ab0f821
treec82d6cb949ca28e3fea3eca79098b61bf3c047cd
parent31dcd762ee6718238b433d752a632a2b2ea3f345
cms encrypt, better OBJ_nid2obj() return check

Fixes #22225

In OBJ_nid2obj(), if the NID does not have an OID, then a pointer to
the special "undefined" ASN1_OBJECT is returned.  Check for the
undefined-ASN1_OBJECT and return an error.  Also, add a test for this
in 80-test_cms.t.

Testing:

  #!/bin/bash -x

  shopt -s expand_aliases

  alias openssl="LD_LIBRARY_PATH=~/git/openssl ~/git/openssl/apps/openssl"

  echo "This is a confidential message.  It should be encrypted." > msg.txt

  ## this should fail b/c there is no OID for aes-256-ctr
  openssl cms -encrypt -in msg.txt -aes-256-ctr -out msg.txt.cms -recip demos/cms/signer.pem
  echo $?

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22392)

(cherry picked from commit bd160912dcc5e39bcdc925d9aa6538f20e37ad16)
crypto/cms/cms_enc.c
test/recipes/80-test_cms.t