#include <openssl/err.h>
#include "pk7_local.h"
-DEFINE_STACK_OF(X509_ALGOR)
-DEFINE_STACK_OF(X509_ATTRIBUTE)
-DEFINE_STACK_OF(PKCS7_RECIP_INFO)
-DEFINE_STACK_OF(PKCS7_SIGNER_INFO)
-
static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
void *value);
static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
BIO *btmp;
const char *name;
EVP_MD *fetched = NULL;
+ const EVP_MD *md;
if ((btmp = BIO_new(BIO_f_md())) == NULL) {
PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, ERR_R_BIO_LIB);
}
name = OBJ_nid2sn(OBJ_obj2nid(alg->algorithm));
+
+ (void)ERR_set_mark();
fetched = EVP_MD_fetch(ctx->libctx, name, ctx->propq);
- if (fetched == NULL) {
+ if (fetched != NULL)
+ md = fetched;
+ else
+ md = EVP_get_digestbyname(name);
+
+ if (md == NULL) {
+ (void)ERR_clear_last_mark();
PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, PKCS7_R_UNKNOWN_DIGEST_TYPE);
goto err;
}
+ (void)ERR_pop_to_mark();
- BIO_set_md(btmp, fetched);
+ BIO_set_md(btmp, md);
EVP_MD_free(fetched);
if (*pbio == NULL)
*pbio = btmp;
BIO *out = NULL, *btmp = NULL;
X509_ALGOR *xa = NULL;
EVP_CIPHER *fetched_cipher = NULL;
+ const EVP_CIPHER *cipher;
const EVP_CIPHER *evp_cipher = NULL;
STACK_OF(X509_ALGOR) *md_sk = NULL;
STACK_OF(PKCS7_RECIP_INFO) *rsk = NULL;
if (RAND_bytes_ex(p7_ctx->libctx, iv, ivlen) <= 0)
goto err;
+ (void)ERR_set_mark();
fetched_cipher = EVP_CIPHER_fetch(p7_ctx->libctx,
EVP_CIPHER_name(evp_cipher),
p7_ctx->propq);
- if (fetched_cipher == NULL)
- goto err;
+ (void)ERR_pop_to_mark();
+ if (fetched_cipher != NULL)
+ cipher = fetched_cipher;
+ else
+ cipher = evp_cipher;
- if (EVP_CipherInit_ex(ctx, fetched_cipher, NULL, NULL, NULL, 1) <= 0)
+ if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, 1) <= 0)
goto err;
EVP_CIPHER_free(fetched_cipher);
X509_ALGOR *xa;
ASN1_OCTET_STRING *data_body = NULL;
EVP_MD *evp_md = NULL;
+ const EVP_MD *md;
EVP_CIPHER *evp_cipher = NULL;
+ const EVP_CIPHER *cipher = NULL;
EVP_CIPHER_CTX *evp_ctx = NULL;
X509_ALGOR *enc_alg = NULL;
STACK_OF(X509_ALGOR) *md_sk = NULL;
enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm;
name = OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm));
+
+ (void)ERR_set_mark();
evp_cipher = EVP_CIPHER_fetch(p7_ctx->libctx, name, p7_ctx->propq);
- if (evp_cipher == NULL) {
+ if (evp_cipher != NULL)
+ cipher = evp_cipher;
+ else
+ cipher = EVP_get_cipherbyname(name);
+
+ if (cipher == NULL) {
+ (void)ERR_clear_last_mark();
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
goto err;
}
+ (void)ERR_pop_to_mark();
break;
case NID_pkcs7_enveloped:
rsk = p7->d.enveloped->recipientinfo;
/* data_body is NULL if the optional EncryptedContent is missing. */
data_body = p7->d.enveloped->enc_data->enc_data;
name = OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm));
+
+ (void)ERR_set_mark();
evp_cipher = EVP_CIPHER_fetch(p7_ctx->libctx, name, p7_ctx->propq);
- if (evp_cipher == NULL) {
+ if (evp_cipher != NULL)
+ cipher = evp_cipher;
+ else
+ cipher = EVP_get_cipherbyname(name);
+
+ if (cipher == NULL) {
+ (void)ERR_clear_last_mark();
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
goto err;
}
+ (void)ERR_pop_to_mark();
break;
default:
PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
}
name = OBJ_nid2sn(OBJ_obj2nid(xa->algorithm));
+
+ (void)ERR_set_mark();
evp_md = EVP_MD_fetch(p7_ctx->libctx, name, p7_ctx->propq);
- if (evp_md == NULL) {
+ if (evp_md != NULL)
+ md = evp_md;
+ else
+ md = EVP_get_digestbyname(name);
+
+ if (md == NULL) {
+ (void)ERR_clear_last_mark();
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_UNKNOWN_DIGEST_TYPE);
goto err;
}
+ (void)ERR_pop_to_mark();
- BIO_set_md(btmp, evp_md);
+ BIO_set_md(btmp, md);
EVP_MD_free(evp_md);
if (out == NULL)
out = btmp;
}
}
- if (evp_cipher != NULL) {
+ if (cipher != NULL) {
if ((etmp = BIO_new(BIO_f_cipher())) == NULL) {
PKCS7err(PKCS7_F_PKCS7_DATADECODE, ERR_R_BIO_LIB);
goto err;
ri = sk_PKCS7_RECIP_INFO_value(rsk, i);
ri->ctx = p7_ctx;
if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey,
- EVP_CIPHER_key_length(evp_cipher)) < 0)
+ EVP_CIPHER_key_length(cipher)) < 0)
goto err;
ERR_clear_error();
}
evp_ctx = NULL;
BIO_get_cipher_ctx(etmp, &evp_ctx);
- if (EVP_CipherInit_ex(evp_ctx, evp_cipher, NULL, NULL, NULL, 0) <= 0)
+ if (EVP_CipherInit_ex(evp_ctx, cipher, NULL, NULL, NULL, 0) <= 0)
goto err;
if (EVP_CIPHER_asn1_to_param(evp_ctx, enc_alg->parameter) < 0)
goto err;
{
ASN1_OCTET_STRING *os;
EVP_MD_CTX *mdc_tmp, *mdc;
+ const EVP_MD *md;
EVP_MD *fetched_md = NULL;
int ret = 0, i;
int md_type;
goto err;
}
+ (void)ERR_set_mark();
fetched_md = EVP_MD_fetch(ctx->libctx, OBJ_nid2sn(md_type), ctx->propq);
- if (fetched_md == NULL || !EVP_VerifyInit_ex(mdc_tmp, fetched_md, NULL))
+
+ if (fetched_md != NULL)
+ md = fetched_md;
+ else
+ md = EVP_get_digestbynid(md_type);
+
+ if (md == NULL || !EVP_VerifyInit_ex(mdc_tmp, md, NULL)) {
+ (void)ERR_clear_last_mark();
goto err;
+ }
+ (void)ERR_pop_to_mark();
alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));