add CVE-2010-0742 and CVS-2010-1633 fixes
[openssl.git] / crypto / cms / cms_asn1.c
index 60ea339aeaa58cba89f70bd86e8a4c392fb37adc..cfe67fb6c1835d9cfea21f754da91a8de97bd12b 100644 (file)
@@ -53,6 +53,7 @@
 
 #include <openssl/asn1t.h>
 #include <openssl/pem.h>
+#include <openssl/x509v3.h>
 #include "cms.h"
 #include "cms_lcl.h"
 
@@ -85,19 +86,20 @@ ASN1_NDEF_SEQUENCE(CMS_EncapsulatedContentInfo) = {
        ASN1_NDEF_EXP_OPT(CMS_EncapsulatedContentInfo, eContent, ASN1_OCTET_STRING_NDEF, 0)
 } ASN1_NDEF_SEQUENCE_END(CMS_EncapsulatedContentInfo)
 
-/* Minor tweak to operation: free up EVP_PKEY */
+/* Minor tweak to operation: free up signer key, cert */
 static int cms_si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
                                                        void *exarg)
-{
-       if(operation == ASN1_OP_FREE_POST) {
+       {
+       if(operation == ASN1_OP_FREE_POST)
+               {
                CMS_SignerInfo *si = (CMS_SignerInfo *)*pval;
                if (si->pkey)
                        EVP_PKEY_free(si->pkey);
                if (si->signer)
                        X509_free(si->signer);
-       }
+               }
        return 1;
-}
+       }
 
 ASN1_SEQUENCE_cb(CMS_SignerInfo, cms_si_cb) = {
        ASN1_SIMPLE(CMS_SignerInfo, version, LONG),
@@ -129,8 +131,8 @@ ASN1_NDEF_SEQUENCE(CMS_SignedData) = {
 } ASN1_NDEF_SEQUENCE_END(CMS_SignedData)
 
 ASN1_SEQUENCE(CMS_OriginatorInfo) = {
-       ASN1_IMP_SET_OF_OPT(CMS_SignedData, certificates, CMS_CertificateChoices, 0),
-       ASN1_IMP_SET_OF_OPT(CMS_SignedData, crls, CMS_RevocationInfoChoice, 1)
+       ASN1_IMP_SET_OF_OPT(CMS_OriginatorInfo, certificates, CMS_CertificateChoices, 0),
+       ASN1_IMP_SET_OF_OPT(CMS_OriginatorInfo, crls, CMS_RevocationInfoChoice, 1)
 } ASN1_SEQUENCE_END(CMS_OriginatorInfo)
 
 ASN1_NDEF_SEQUENCE(CMS_EncryptedContentInfo) = {
@@ -211,13 +213,50 @@ ASN1_SEQUENCE(CMS_OtherRecipientInfo) = {
   ASN1_OPT(CMS_OtherRecipientInfo, oriValue, ASN1_ANY)
 } ASN1_SEQUENCE_END(CMS_OtherRecipientInfo)
 
-ASN1_CHOICE(CMS_RecipientInfo) = {
+/* Free up RecipientInfo additional data */
+static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
+                                                       void *exarg)
+       {
+       if(operation == ASN1_OP_FREE_PRE)
+               {
+               CMS_RecipientInfo *ri = (CMS_RecipientInfo *)*pval;
+               if (ri->type == CMS_RECIPINFO_TRANS)
+                       {
+                       CMS_KeyTransRecipientInfo *ktri = ri->d.ktri;
+                       if (ktri->pkey)
+                               EVP_PKEY_free(ktri->pkey);
+                       if (ktri->recip)
+                               X509_free(ktri->recip);
+                       }
+               else if (ri->type == CMS_RECIPINFO_KEK)
+                       {
+                       CMS_KEKRecipientInfo *kekri = ri->d.kekri;
+                       if (kekri->key)
+                               {
+                               OPENSSL_cleanse(kekri->key, kekri->keylen);
+                               OPENSSL_free(kekri->key);
+                               }
+                       }
+               else if (ri->type == CMS_RECIPINFO_PASS)
+                       {
+                       CMS_PasswordRecipientInfo *pwri = ri->d.pwri;
+                       if (pwri->pass)
+                               {
+                               OPENSSL_cleanse(pwri->pass, pwri->passlen);
+                               OPENSSL_free(pwri->pass);
+                               }
+                       }
+               }
+       return 1;
+       }
+
+ASN1_CHOICE_cb(CMS_RecipientInfo, cms_ri_cb) = {
        ASN1_SIMPLE(CMS_RecipientInfo, d.ktri, CMS_KeyTransRecipientInfo),
        ASN1_IMP(CMS_RecipientInfo, d.kari, CMS_KeyAgreeRecipientInfo, 1),
        ASN1_IMP(CMS_RecipientInfo, d.kekri, CMS_KEKRecipientInfo, 2),
        ASN1_IMP(CMS_RecipientInfo, d.pwri, CMS_PasswordRecipientInfo, 3),
        ASN1_IMP(CMS_RecipientInfo, d.ori, CMS_OtherRecipientInfo, 4)
-} ASN1_CHOICE_END(CMS_RecipientInfo)
+} ASN1_CHOICE_END_cb(CMS_RecipientInfo, CMS_RecipientInfo, type)
 
 ASN1_NDEF_SEQUENCE(CMS_EnvelopedData) = {
        ASN1_SIMPLE(CMS_EnvelopedData, version, LONG),
@@ -275,11 +314,13 @@ ASN1_ADB(CMS_ContentInfo) = {
 /* CMS streaming support */
 static int cms_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
                                                        void *exarg)
-{
+       {
        ASN1_STREAM_ARG *sarg = exarg;
-       CMS_ContentInfo *cms;
+       CMS_ContentInfo *cms = NULL;
        if (pval)
                cms = (CMS_ContentInfo *)*pval;
+       else
+               return 1;
        switch(operation)
                {
 
@@ -300,7 +341,7 @@ static int cms_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
 
                }
        return 1;
-}
+       }
 
 ASN1_NDEF_SEQUENCE_cb(CMS_ContentInfo, cms_cb) = {
        ASN1_SIMPLE(CMS_ContentInfo, contentType, ASN1_OBJECT),
@@ -326,3 +367,23 @@ ASN1_ITEM_TEMPLATE(CMS_Attributes_Verify) =
                                V_ASN1_SET, CMS_ATTRIBUTES, X509_ATTRIBUTE)
 ASN1_ITEM_TEMPLATE_END(CMS_Attributes_Verify)
 
+
+
+ASN1_CHOICE(CMS_ReceiptsFrom) = {
+  ASN1_IMP(CMS_ReceiptsFrom, d.allOrFirstTier, LONG, 0),
+  ASN1_IMP_SEQUENCE_OF(CMS_ReceiptsFrom, d.receiptList, GENERAL_NAMES, 1)
+} ASN1_CHOICE_END(CMS_ReceiptsFrom)
+
+ASN1_SEQUENCE(CMS_ReceiptRequest) = {
+  ASN1_SIMPLE(CMS_ReceiptRequest, signedContentIdentifier, ASN1_OCTET_STRING),
+  ASN1_SIMPLE(CMS_ReceiptRequest, receiptsFrom, CMS_ReceiptsFrom),
+  ASN1_SEQUENCE_OF(CMS_ReceiptRequest, receiptsTo, GENERAL_NAMES)
+} ASN1_SEQUENCE_END(CMS_ReceiptRequest)
+
+ASN1_SEQUENCE(CMS_Receipt) = {
+  ASN1_SIMPLE(CMS_Receipt, version, LONG),
+  ASN1_SIMPLE(CMS_Receipt, contentType, ASN1_OBJECT),
+  ASN1_SIMPLE(CMS_Receipt, signedContentIdentifier, ASN1_OCTET_STRING),
+  ASN1_SIMPLE(CMS_Receipt, originatorSignatureValue, ASN1_OCTET_STRING)
+} ASN1_SEQUENCE_END(CMS_Receipt)
+