Prepare for 1.0.1l-dev
[openssl.git] / crypto / cms / cms_lib.c
index f2169e138b3ca1ec657373d0676676162e63eff7..ba08279a046196b77e8a86a0de40d73518718db6 100644 (file)
@@ -68,12 +68,6 @@ DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice)
 DECLARE_STACK_OF(CMS_CertificateChoices)
 DECLARE_STACK_OF(CMS_RevocationInfoChoice)
 
-#if 0
-IMPLEMENT_ASN1_ALLOC_FUNCTIONS(CMS_CertificateChoices)
-IMPLEMENT_ASN1_ALLOC_FUNCTIONS(CMS_RevocationInfoChoice)
-#endif
-
-
 const ASN1_OBJECT *CMS_get0_type(CMS_ContentInfo *cms)
        {
        return cms->contentType;
@@ -140,7 +134,11 @@ BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
 #endif
 
                case NID_pkcs7_encrypted:
-               cmsbio = BIO_new(BIO_f_cipher());
+               cmsbio = cms_EncryptedData_init_bio(cms);
+               break;
+
+               case NID_pkcs7_enveloped:
+               cmsbio = cms_EnvelopedData_init_bio(cms);
                break;
 
                default:
@@ -186,6 +184,8 @@ int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
                {
 
                case NID_pkcs7_data:
+               case NID_pkcs7_enveloped:
+               case NID_pkcs7_encrypted:
                case NID_id_smime_ct_compressedData:
                /* Nothing to do */
                return 1;
@@ -406,16 +406,17 @@ int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
                        return 0;
                        }
                BIO_get_md_ctx(chain, &mtmp);
-               if (EVP_MD_CTX_type(mtmp) == nid)
-                       {
-                       EVP_MD_CTX_copy_ex(mctx, mtmp);
-                       return 1;
-                       }
+               if (EVP_MD_CTX_type(mtmp) == nid
+               /* Workaround for broken implementations that use signature
+                * algorithm  OID instead of digest.
+                */
+                       || EVP_MD_pkey_type(EVP_MD_CTX_md(mtmp)) == nid)
+                       return EVP_MD_CTX_copy_ex(mctx, mtmp);
                chain = BIO_next(chain);
                }
        }
 
-STACK_OF(CMS_CertificateChoices) **cms_get0_certificate_choices(CMS_ContentInfo *cms)
+static STACK_OF(CMS_CertificateChoices) **cms_get0_certificate_choices(CMS_ContentInfo *cms)
        {
        switch (OBJ_obj2nid(cms->contentType))
                {
@@ -462,8 +463,6 @@ int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert)
        STACK_OF(CMS_CertificateChoices) **pcerts;
        int i;
        pcerts = cms_get0_certificate_choices(cms);
-       if (!pcerts)
-               return 0;
        if (!pcerts)
                return 0;
        for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++)
@@ -472,8 +471,11 @@ int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert)
                if (cch->type == CMS_CERTCHOICE_CERT)
                        {
                        if (!X509_cmp(cch->d.certificate, cert))
-                               return -1;
-                               
+                               {
+                               CMSerr(CMS_F_CMS_ADD0_CERT, 
+                                       CMS_R_CERTIFICATE_ALREADY_PRESENT);
+                               return 0;
+                               }
                        }
                }
        cch = CMS_add0_CertificateChoices(cms);
@@ -493,7 +495,7 @@ int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert)
        return r;
        }
 
-STACK_OF(CMS_RevocationInfoChoice) **cms_get0_revocation_choices(CMS_ContentInfo *cms)
+static STACK_OF(CMS_RevocationInfoChoice) **cms_get0_revocation_choices(CMS_ContentInfo *cms)
        {
        switch (OBJ_obj2nid(cms->contentType))
                {
@@ -545,6 +547,15 @@ int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl)
        return 1;
        }
 
+int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl)
+       {
+       int r;
+       r = CMS_add0_crl(cms, crl);
+       if (r > 0)
+               CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
+       return r;
+       }
+
 STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms)
        {
        STACK_OF(X509) *certs = NULL;