summaryrefslogtreecommitdiffstats
path: root/crypto/pkcs7/pk7_lib.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/pkcs7/pk7_lib.c
parentTEST: Modify how the retrieved digest name for SM2 digestsign is checked (diff)
downloadopenssl-ad57a13bb86949a9e9adc7a2960e3f39e3e5b284.tar.xz
openssl-ad57a13bb86949a9e9adc7a2960e3f39e3e5b284.zip
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/pkcs7/pk7_lib.c')
-rw-r--r--crypto/pkcs7/pk7_lib.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c
index 6b941c53c4..bf959a28d2 100644
--- a/crypto/pkcs7/pk7_lib.c
+++ b/crypto/pkcs7/pk7_lib.c
@@ -187,7 +187,8 @@ int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other)
int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
{
- int i, j, nid;
+ int i, j;
+ ASN1_OBJECT *obj;
X509_ALGOR *alg;
STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
STACK_OF(X509_ALGOR) *md_sk;
@@ -207,27 +208,35 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
return 0;
}
- nid = OBJ_obj2nid(psi->digest_alg->algorithm);
-
+ obj = psi->digest_alg->algorithm;
/* If the digest is not currently listed, add it */
j = 0;
for (i = 0; i < sk_X509_ALGOR_num(md_sk); i++) {
alg = sk_X509_ALGOR_value(md_sk, i);
- if (OBJ_obj2nid(alg->algorithm) == nid) {
+ if (OBJ_cmp(obj, alg->algorithm) == 0) {
j = 1;
break;
}
}
if (!j) { /* we need to add another algorithm */
+ int nid;
+
if ((alg = X509_ALGOR_new()) == NULL
|| (alg->parameter = ASN1_TYPE_new()) == NULL) {
X509_ALGOR_free(alg);
ERR_raise(ERR_LIB_PKCS7, ERR_R_MALLOC_FAILURE);
return 0;
}
- alg->algorithm = OBJ_nid2obj(nid);
+ /*
+ * If there is a constant copy of the ASN1 OBJECT in libcrypto, then
+ * use that. Otherwise, use a dynamically duplicated copy
+ */
+ if ((nid = OBJ_obj2nid(obj)) != NID_undef)
+ alg->algorithm = OBJ_nid2obj(nid);
+ else
+ alg->algorithm = OBJ_dup(obj);
alg->parameter->type = V_ASN1_NULL;
- if (!sk_X509_ALGOR_push(md_sk, alg)) {
+ if (alg->algorithm == NULL || !sk_X509_ALGOR_push(md_sk, alg)) {
X509_ALGOR_free(alg);
return 0;
}