projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
RT4339: Fix handling of <internal/bn_conf.h>
[oweals/openssl.git]
/
crypto
/
cms
/
cms_sd.c
diff --git
a/crypto/cms/cms_sd.c
b/crypto/cms/cms_sd.c
index 50064e286c79523496395acd4af24efa26216f4d..2757aa939245dda90b57efb422f0e20344d8bc8a 100644
(file)
--- a/
crypto/cms/cms_sd.c
+++ b/
crypto/cms/cms_sd.c
@@
-1,4
+1,3
@@
-/* crypto/cms/cms_sd.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
@@
-61,6
+60,7
@@
#include <openssl/cms.h>
#include "cms_lcl.h"
#include "internal/asn1_int.h"
#include <openssl/cms.h>
#include "cms_lcl.h"
#include "internal/asn1_int.h"
+#include "internal/evp_int.h"
/* CMS SignedData Utilities */
/* CMS SignedData Utilities */
@@
-92,7
+92,7
@@
static CMS_SignedData *cms_signed_data_init(CMS_ContentInfo *cms)
return cms_get0_signed(cms);
}
return cms_get0_signed(cms);
}
-/* Just initiali
z
e SignedData e.g. for certs only structure */
+/* Just initiali
s
e SignedData e.g. for certs only structure */
int CMS_SignedData_init(CMS_ContentInfo *cms)
{
int CMS_SignedData_init(CMS_ContentInfo *cms)
{
@@
-280,6
+280,7
@@
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
si = M_ASN1_new_of(CMS_SignerInfo);
if (!si)
goto merr;
si = M_ASN1_new_of(CMS_SignerInfo);
if (!si)
goto merr;
+ /* Call for side-effect of computing hash and caching extensions */
X509_check_purpose(signer, -1, -1);
CRYPTO_add(&pk->references, 1, CRYPTO_LOCK_EVP_PKEY);
X509_check_purpose(signer, -1, -1);
CRYPTO_add(&pk->references, 1, CRYPTO_LOCK_EVP_PKEY);
@@
-287,9
+288,14
@@
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
si->pkey = pk;
si->signer = signer;
si->pkey = pk;
si->signer = signer;
-
EVP_MD_CTX_init(&si->mctx
);
+
si->mctx = EVP_MD_CTX_new(
);
si->pctx = NULL;
si->pctx = NULL;
+ if (si->mctx == NULL) {
+ CMSerr(CMS_F_CMS_ADD1_SIGNER, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
if (flags & CMS_USE_KEYID) {
si->version = 3;
if (sd->version < 3)
if (flags & CMS_USE_KEYID) {
si->version = 3;
if (sd->version < 3)
@@
-332,7
+338,7
@@
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) {
alg = X509_ALGOR_new();
if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) {
alg = X509_ALGOR_new();
- if (
!alg
)
+ if (
alg == NULL
)
goto merr;
X509_ALGOR_set_md(alg, md);
if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) {
goto merr;
X509_ALGOR_set_md(alg, md);
if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) {
@@
-345,7
+351,7
@@
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
goto err;
if (!(flags & CMS_NOATTR)) {
/*
goto err;
if (!(flags & CMS_NOATTR)) {
/*
- * Initiali
alize signed attributes strut
ucture so other attributes
+ * Initiali
ze signed attributes str
ucture so other attributes
* such as signing time etc are added later even if we add none here.
*/
if (!si->signedAttrs) {
* such as signing time etc are added later even if we add none here.
*/
if (!si->signedAttrs) {
@@
-381,13
+387,13
@@
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (flags & CMS_KEY_PARAM) {
if (flags & CMS_NOATTR) {
si->pctx = EVP_PKEY_CTX_new(si->pkey, NULL);
if (flags & CMS_KEY_PARAM) {
if (flags & CMS_NOATTR) {
si->pctx = EVP_PKEY_CTX_new(si->pkey, NULL);
- if (
!si->pctx
)
+ if (
si->pctx == NULL
)
goto err;
if (EVP_PKEY_sign_init(si->pctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0)
goto err;
goto err;
if (EVP_PKEY_sign_init(si->pctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0)
goto err;
- } else if (EVP_DigestSignInit(
&
si->mctx, &si->pctx, md, NULL, pk) <=
+ } else if (EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, pk) <=
0)
goto err;
}
0)
goto err;
}
@@
-444,7
+450,7
@@
EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si)
EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si)
{
EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si)
{
- return
&
si->mctx;
+ return si->mctx;
}
STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms)
}
STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms)
@@
-571,19
+577,23
@@
ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si)
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
CMS_SignerInfo *si, BIO *chain)
{
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
CMS_SignerInfo *si, BIO *chain)
{
- EVP_MD_CTX
mctx
;
+ EVP_MD_CTX
*mctx = EVP_MD_CTX_new()
;
int r = 0;
EVP_PKEY_CTX *pctx = NULL;
int r = 0;
EVP_PKEY_CTX *pctx = NULL;
- EVP_MD_CTX_init(&mctx);
+
+ if (mctx == NULL) {
+ CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
if (!si->pkey) {
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, CMS_R_NO_PRIVATE_KEY);
return 0;
}
if (!si->pkey) {
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, CMS_R_NO_PRIVATE_KEY);
return 0;
}
- if (!cms_DigestAlgorithm_find_ctx(
&
mctx, chain, si->digestAlgorithm))
+ if (!cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
goto err;
goto err;
- /* Set SignerInfo algor
tihm details if we used custom paramets
r */
+ /* Set SignerInfo algor
ithm details if we used custom paramete
r */
if (si->pctx && !cms_sd_asn1_ctrl(si, 0))
goto err;
if (si->pctx && !cms_sd_asn1_ctrl(si, 0))
goto err;
@@
-596,7
+606,7
@@
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
cms->d.signedData->encapContentInfo->eContentType;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
cms->d.signedData->encapContentInfo->eContentType;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
- if (!EVP_DigestFinal_ex(
&
mctx, md, &mdlen))
+ if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
goto err;
if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest,
V_ASN1_OCTET_STRING, md, mdlen))
goto err;
if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest,
V_ASN1_OCTET_STRING, md, mdlen))
@@
-613,11
+623,11
@@
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
pctx = si->pctx;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
pctx = si->pctx;
- if (!EVP_DigestFinal_ex(
&
mctx, md, &mdlen))
+ if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
goto err;
siglen = EVP_PKEY_size(si->pkey);
sig = OPENSSL_malloc(siglen);
goto err;
siglen = EVP_PKEY_size(si->pkey);
sig = OPENSSL_malloc(siglen);
- if (
!sig
) {
+ if (
sig == NULL
) {
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
@@
-630,11
+640,11
@@
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
unsigned char *sig;
unsigned int siglen;
sig = OPENSSL_malloc(EVP_PKEY_size(si->pkey));
unsigned char *sig;
unsigned int siglen;
sig = OPENSSL_malloc(EVP_PKEY_size(si->pkey));
- if (
!sig
) {
+ if (
sig == NULL
) {
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!EVP_SignFinal(
&
mctx, sig, &siglen, si->pkey)) {
+ if (!EVP_SignFinal(mctx, sig, &siglen, si->pkey)) {
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, CMS_R_SIGNFINAL_ERROR);
OPENSSL_free(sig);
goto err;
CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, CMS_R_SIGNFINAL_ERROR);
OPENSSL_free(sig);
goto err;
@@
-645,7
+655,7
@@
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
r = 1;
err:
r = 1;
err:
- EVP_MD_CTX_
cleanup(&
mctx);
+ EVP_MD_CTX_
free(
mctx);
EVP_PKEY_CTX_free(pctx);
return r;
EVP_PKEY_CTX_free(pctx);
return r;
@@
-668,7
+678,7
@@
int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain)
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
{
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
{
- EVP_MD_CTX *mctx =
&
si->mctx;
+ EVP_MD_CTX *mctx = si->mctx;
EVP_PKEY_CTX *pctx;
unsigned char *abuf = NULL;
int alen;
EVP_PKEY_CTX *pctx;
unsigned char *abuf = NULL;
int alen;
@@
-687,7
+697,7
@@
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
if (si->pctx)
pctx = si->pctx;
else {
if (si->pctx)
pctx = si->pctx;
else {
- EVP_MD_CTX_
ini
t(mctx);
+ EVP_MD_CTX_
rese
t(mctx);
if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
goto err;
}
if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
goto err;
}
@@
-708,7
+718,7
@@
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
goto err;
OPENSSL_free(abuf);
abuf = OPENSSL_malloc(siglen);
goto err;
OPENSSL_free(abuf);
abuf = OPENSSL_malloc(siglen);
- if (
!abuf
)
+ if (
abuf == NULL
)
goto err;
if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0)
goto err;
goto err;
if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0)
goto err;
@@
-719,7
+729,7
@@
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
goto err;
}
goto err;
}
- EVP_MD_CTX_
cleanup
(mctx);
+ EVP_MD_CTX_
reset
(mctx);
ASN1_STRING_set0(si->signature, abuf, siglen);
ASN1_STRING_set0(si->signature, abuf, siglen);
@@
-727,14
+737,14
@@
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
err:
OPENSSL_free(abuf);
err:
OPENSSL_free(abuf);
- EVP_MD_CTX_
cleanup
(mctx);
+ EVP_MD_CTX_
reset
(mctx);
return 0;
}
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
{
return 0;
}
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
{
- EVP_MD_CTX *mctx =
&si->mctx
;
+ EVP_MD_CTX *mctx =
NULL
;
unsigned char *abuf = NULL;
int alen, r = -1;
const EVP_MD *md = NULL;
unsigned char *abuf = NULL;
int alen, r = -1;
const EVP_MD *md = NULL;
@@
-747,7
+757,9
@@
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
if (md == NULL)
return -1;
md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
if (md == NULL)
return -1;
- EVP_MD_CTX_init(mctx);
+ if (si->mctx == NULL)
+ si->mctx = EVP_MD_CTX_new();
+ mctx = si->mctx;
if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0)
goto err;
if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0)
goto err;
@@
-769,7
+781,7
@@
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
if (r <= 0)
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, CMS_R_VERIFICATION_FAILURE);
err:
if (r <= 0)
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, CMS_R_VERIFICATION_FAILURE);
err:
- EVP_MD_CTX_
cleanup
(mctx);
+ EVP_MD_CTX_
reset
(mctx);
return r;
}
return r;
}
@@
-806,12
+818,16
@@
BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms)
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
{
ASN1_OCTET_STRING *os = NULL;
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
{
ASN1_OCTET_STRING *os = NULL;
- EVP_MD_CTX
mctx
;
+ EVP_MD_CTX
*mctx = EVP_MD_CTX_new()
;
EVP_PKEY_CTX *pkctx = NULL;
int r = -1;
unsigned char mval[EVP_MAX_MD_SIZE];
unsigned int mlen;
EVP_PKEY_CTX *pkctx = NULL;
int r = -1;
unsigned char mval[EVP_MAX_MD_SIZE];
unsigned int mlen;
- EVP_MD_CTX_init(&mctx);
+
+ if (mctx == NULL) {
+ CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
/* If we have any signed attributes look for messageDigest value */
if (CMS_signed_get_attr_count(si) >= 0) {
os = CMS_signed_get0_data_by_OBJ(si,
/* If we have any signed attributes look for messageDigest value */
if (CMS_signed_get_attr_count(si) >= 0) {
os = CMS_signed_get0_data_by_OBJ(si,
@@
-824,10
+840,10
@@
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
}
}
}
}
- if (!cms_DigestAlgorithm_find_ctx(
&
mctx, chain, si->digestAlgorithm))
+ if (!cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
goto err;
goto err;
- if (EVP_DigestFinal_ex(
&
mctx, mval, &mlen) <= 0) {
+ if (EVP_DigestFinal_ex(mctx, mval, &mlen) <= 0) {
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT,
CMS_R_UNABLE_TO_FINALIZE_CONTEXT);
goto err;
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT,
CMS_R_UNABLE_TO_FINALIZE_CONTEXT);
goto err;
@@
-849,8
+865,10
@@
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
} else
r = 1;
} else {
} else
r = 1;
} else {
- const EVP_MD *md = EVP_MD_CTX_md(
&
mctx);
+ const EVP_MD *md = EVP_MD_CTX_md(mctx);
pkctx = EVP_PKEY_CTX_new(si->pkey, NULL);
pkctx = EVP_PKEY_CTX_new(si->pkey, NULL);
+ if (pkctx == NULL)
+ goto err;
if (EVP_PKEY_verify_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0)
if (EVP_PKEY_verify_init(pkctx) <= 0)
goto err;
if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0)
@@
-869,7
+887,7
@@
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
err:
EVP_PKEY_CTX_free(pkctx);
err:
EVP_PKEY_CTX_free(pkctx);
- EVP_MD_CTX_
cleanup(&
mctx);
+ EVP_MD_CTX_
free(
mctx);
return r;
}
return r;
}
@@
-894,20
+912,20
@@
int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
ASN1_INTEGER *key = NULL;
if (keysize > 0) {
key = ASN1_INTEGER_new();
ASN1_INTEGER *key = NULL;
if (keysize > 0) {
key = ASN1_INTEGER_new();
- if (
!key
|| !ASN1_INTEGER_set(key, keysize))
+ if (
key == NULL
|| !ASN1_INTEGER_set(key, keysize))
return 0;
}
alg = X509_ALGOR_new();
return 0;
}
alg = X509_ALGOR_new();
- if (
!alg
) {
+ if (
alg == NULL
) {
ASN1_INTEGER_free(key);
return 0;
}
X509_ALGOR_set0(alg, OBJ_nid2obj(algnid),
key ? V_ASN1_INTEGER : V_ASN1_UNDEF, key);
ASN1_INTEGER_free(key);
return 0;
}
X509_ALGOR_set0(alg, OBJ_nid2obj(algnid),
key ? V_ASN1_INTEGER : V_ASN1_UNDEF, key);
- if (
!*algs
)
+ if (
*algs == NULL
)
*algs = sk_X509_ALGOR_new_null();
*algs = sk_X509_ALGOR_new_null();
- if (
!*algs
|| !sk_X509_ALGOR_push(*algs, alg)) {
+ if (
*algs == NULL
|| !sk_X509_ALGOR_push(*algs, alg)) {
X509_ALGOR_free(alg);
return 0;
}
X509_ALGOR_free(alg);
return 0;
}