X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fpkcs7%2Fpk7_lib.c;h=45973fe8507cc3d08be0efeebea9446697873ac3;hb=a1b15ac21fc605aa80305807b701925667665e75;hp=a3f554f7c2fee849b99bc6f6f1460f2e5d23503d;hpb=6b691a5c85ddc4e407e32781841fee5c029506cd;p=oweals%2Fopenssl.git diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index a3f554f7c2..45973fe850 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -58,8 +58,8 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "x509.h" +#include +#include long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) { @@ -123,7 +123,7 @@ int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data) { case NID_pkcs7_signed: if (p7->d.sign->contents != NULL) - PKCS7_content_free(p7->d.sign->contents); + PKCS7_free(p7->d.sign->contents); p7->d.sign->contents=p7_data; break; case NID_pkcs7_digest: @@ -157,7 +157,7 @@ int PKCS7_set_type(PKCS7 *p7, int type) break; case NID_pkcs7_data: p7->type=obj; - if ((p7->d.data=ASN1_OCTET_STRING_new()) == NULL) + if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL) goto err; break; case NID_pkcs7_signedAndEnveloped: @@ -165,9 +165,6 @@ int PKCS7_set_type(PKCS7 *p7, int type) if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) == NULL) goto err; ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1); -/* p7->d.signed_and_enveloped->enc_data->content_type= - OBJ_nid2obj(NID_pkcs7_encrypted);*/ - break; case NID_pkcs7_enveloped: p7->type=obj; @@ -175,8 +172,14 @@ int PKCS7_set_type(PKCS7 *p7, int type) == NULL) goto err; ASN1_INTEGER_set(p7->d.enveloped->version,0); break; - case NID_pkcs7_digest: case NID_pkcs7_encrypted: + p7->type=obj; + if ((p7->d.encrypted=PKCS7_ENCRYPT_new()) + == NULL) goto err; + ASN1_INTEGER_set(p7->d.encrypted->version,0); + break; + + case NID_pkcs7_digest: default: PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); goto err; @@ -190,8 +193,8 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) { int i,j,nid; X509_ALGOR *alg; - STACK *signer_sk; - STACK *md_sk; + STACK_OF(PKCS7_SIGNER_INFO) *signer_sk; + STACK_OF(X509_ALGOR) *md_sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -213,9 +216,9 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) /* If the digest is not currently listed, add it */ j=0; - for (i=0; ialgorithm) == nid) { j=1; @@ -224,12 +227,17 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) } if (!j) /* we need to add another algorithm */ { - alg=X509_ALGOR_new(); + if(!(alg=X509_ALGOR_new()) + || !(alg->parameter = ASN1_TYPE_new())) { + PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE); + return(0); + } alg->algorithm=OBJ_nid2obj(nid); - sk_push(md_sk,(char *)alg); + alg->parameter->type = V_ASN1_NULL; + sk_X509_ALGOR_push(md_sk,alg); } - sk_push(signer_sk,(char *)psi); + sk_PKCS7_SIGNER_INFO_push(signer_sk,psi); return(1); } @@ -262,7 +270,7 @@ int PKCS7_add_certificate(PKCS7 *p7, X509 *x509) int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl) { int i; - STACK **sk; + STACK_OF(X509_CRL) **sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -279,16 +287,19 @@ int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl) } if (*sk == NULL) - *sk=sk_new_null(); + *sk=sk_X509_CRL_new_null(); CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); - sk_push(*sk,(char *)crl); + sk_X509_CRL_push(*sk,crl); return(1); } int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, EVP_MD *dgst) { + char is_dsa; + if (pkey->type == EVP_PKEY_DSA) is_dsa = 1; + else is_dsa = 0; /* We now need to add another PKCS7_SIGNER_INFO entry */ ASN1_INTEGER_set(p7i->version,1); X509_NAME_set(&p7i->issuer_and_serial->issuer, @@ -296,28 +307,35 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, /* because ASN1_INTEGER_set is used to set a 'long' we will do * things the ugly way. */ - ASN1_INTEGER_free(p7i->issuer_and_serial->serial); + M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial); p7i->issuer_and_serial->serial= - ASN1_INTEGER_dup(X509_get_serialNumber(x509)); + M_ASN1_INTEGER_dup(X509_get_serialNumber(x509)); /* lets keep the pkey around for a while */ CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); p7i->pkey=pkey; /* Set the algorithms */ - if (pkey->type == EVP_PKEY_DSA) - p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1); + if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1); else p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); - p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_MD_pkey_type(dgst)); -#if 1 + if (p7i->digest_alg->parameter != NULL) + ASN1_TYPE_free(p7i->digest_alg->parameter); + if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL) + goto err; + p7i->digest_alg->parameter->type=V_ASN1_NULL; + + p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type)); + if (p7i->digest_enc_alg->parameter != NULL) ASN1_TYPE_free(p7i->digest_enc_alg->parameter); - if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL) - goto err; - p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; -#endif + if(is_dsa) p7i->digest_enc_alg->parameter = NULL; + else { + if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new())) + goto err; + p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; + } return(1); err: @@ -337,7 +355,7 @@ err: return(NULL); } -STACK *PKCS7_get_signer_info(PKCS7 *p7) +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7) { if (PKCS7_type_is_signed(p7)) { @@ -366,7 +384,7 @@ err: int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri) { int i; - STACK *sk; + STACK_OF(PKCS7_RECIP_INFO) *sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -382,7 +400,7 @@ int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri) return(0); } - sk_push(sk,(char *)ri); + sk_PKCS7_RECIP_INFO_push(sk,ri); return(1); } @@ -392,9 +410,9 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509) X509_NAME_set(&p7i->issuer_and_serial->issuer, X509_get_issuer_name(x509)); - ASN1_INTEGER_free(p7i->issuer_and_serial->serial); + M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial); p7i->issuer_and_serial->serial= - ASN1_INTEGER_dup(X509_get_serialNumber(x509)); + M_ASN1_INTEGER_dup(X509_get_serialNumber(x509)); X509_ALGOR_free(p7i->key_enc_algor); p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR, @@ -417,9 +435,10 @@ X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si) return(NULL); } -int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher) +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher) { int i; + ASN1_OBJECT *objtmp; PKCS7_ENC_CONTENT *ec; i=OBJ_obj2nid(p7->type); @@ -436,7 +455,15 @@ int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher) return(0); } - ec->algorithm->algorithm=OBJ_nid2obj(EVP_CIPHER_nid(cipher)); - return(ec->algorithm->algorithm != NULL); + /* Check cipher OID exists and has data in it*/ + i = EVP_CIPHER_type(cipher); + if(i == NID_undef) { + PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER); + return(0); + } + objtmp = OBJ_nid2obj(i); + + ec->cipher = cipher; + return 1; }