aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/cms/cms_sd.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-03-10 12:58:53 +0100
committerRichard Levitte <levitte@openssl.org>2021-04-18 10:10:24 +0200
commitad57a13bb86949a9e9adc7a2960e3f39e3e5b284 (patch)
tree67bfce29a5498715b5979c7b8f19baa3f313ddd8 /crypto/cms/cms_sd.c
parent42423ac9611e0cbb02c93b3c5661328f324f9d08 (diff)
downloadopenssl-ad57a13bb86949a9e9adc7a2960e3f39e3e5b284.tar.gz
Modify OBJ_nid2sn(OBJ_obj2nid(...)) occurences to use OBJ_obj2txt()
The intention is to allow for OIDs for which libcrypto has no information, but are still fetchable for OSSL_ALGORITHM implementations that specify an OID amongst their names. Fixes #14278 Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14498)
Diffstat (limited to 'crypto/cms/cms_sd.c')
-rw-r--r--crypto/cms/cms_sd.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c
index 2b232aa700..898916d548 100644
--- a/crypto/cms/cms_sd.c
+++ b/crypto/cms/cms_sd.c
@@ -15,12 +15,13 @@
#include <openssl/err.h>
#include <openssl/cms.h>
#include <openssl/ess.h>
-#include "cms_local.h"
+#include "internal/sizes.h"
#include "crypto/asn1.h"
#include "crypto/evp.h"
#include "crypto/cms.h"
#include "crypto/ess.h"
#include "crypto/x509.h" /* for ossl_x509_add_cert_new() */
+#include "cms_local.h"
/* CMS SignedData Utilities */
@@ -328,9 +329,12 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
/* See if digest is present in digestAlgorithms */
for (i = 0; i < sk_X509_ALGOR_num(sd->digestAlgorithms); i++) {
const ASN1_OBJECT *aoid;
+ char name[OSSL_MAX_NAME_SIZE];
+
alg = sk_X509_ALGOR_value(sd->digestAlgorithms, i);
X509_ALGOR_get0(&aoid, NULL, NULL, alg);
- if (OBJ_obj2nid(aoid) == EVP_MD_type(md))
+ OBJ_obj2txt(name, sizeof(name), aoid, 0);
+ if (EVP_MD_is_a(md, name))
break;
}
@@ -724,9 +728,10 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
int alen;
size_t siglen;
const CMS_CTX *ctx = si->cms_ctx;
- const char *md_name = OBJ_nid2sn(OBJ_obj2nid(si->digestAlgorithm->algorithm));
+ char md_name[OSSL_MAX_NAME_SIZE];
- if (md_name == NULL)
+ if (!OBJ_obj2txt(md_name, sizeof(md_name),
+ si->digestAlgorithm->algorithm, 0))
return 0;
if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) {
@@ -781,7 +786,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
EVP_MD_CTX *mctx = NULL;
unsigned char *abuf = NULL;
int alen, r = -1;
- const char *name;
+ char name[OSSL_MAX_NAME_SIZE];
const EVP_MD *md;
EVP_MD *fetched_md = NULL;
const CMS_CTX *ctx = si->cms_ctx;
@@ -796,7 +801,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
if (!ossl_cms_si_check_attributes(si))
return -1;
- name = OBJ_nid2sn(OBJ_obj2nid(si->digestAlgorithm->algorithm));
+ OBJ_obj2txt(name, sizeof(name), si->digestAlgorithm->algorithm, 0);
(void)ERR_set_mark();
fetched_md = EVP_MD_fetch(libctx, name, propq);