]> git.saurik.com Git - apple/security.git/blobdiff - libsecurity_smime/lib/cmsencdata.c
Security-58286.41.2.tar.gz
[apple/security.git] / libsecurity_smime / lib / cmsencdata.c
index 895b5085dc38f47097cd4f18e911e86f98217258..4a2e4d1428f6fc6c079ff09874b131abfed0e217 100644 (file)
 
 #include "cmslocal.h"
 
-#include "secitem.h"
+#include "SecAsn1Item.h"
 #include "secoid.h"
+
 #include <security_asn1/secasn1.h>
 #include <security_asn1/secerr.h>
+#include <security_asn1/secport.h>
 
 /*
  * SecCmsEncryptedDataCreate - create an empty encryptedData object.
@@ -61,7 +63,9 @@ SecCmsEncryptedDataCreate(SecCmsMessageRef cmsg, SECOidTag algorithm, int keysiz
     void *mark;
     SecCmsEncryptedDataRef encd;
     PLArenaPool *poolp;
+#if 0
     SECAlgorithmID *pbe_algid;
+#endif
     OSStatus rv;
 
     poolp = cmsg->poolp;
@@ -72,32 +76,36 @@ SecCmsEncryptedDataCreate(SecCmsMessageRef cmsg, SECOidTag algorithm, int keysiz
     if (encd == NULL)
        goto loser;
 
-    encd->cmsg = cmsg;
+    encd->contentInfo.cmsg = cmsg;
 
     /* version is set in SecCmsEncryptedDataEncodeBeforeStart() */
 
     switch (algorithm) {
     /* XXX hmmm... hardcoded algorithms? */
+    case SEC_OID_AES_128_CBC:
+    case SEC_OID_AES_192_CBC:
+    case SEC_OID_AES_256_CBC:
     case SEC_OID_RC2_CBC:
     case SEC_OID_DES_EDE3_CBC:
     case SEC_OID_DES_CBC:
-       rv = SecCmsContentInfoSetContentEncAlg((SecArenaPoolRef)poolp, &(encd->contentInfo), algorithm, NULL, keysize);
+       rv = SecCmsContentInfoSetContentEncAlg(&(encd->contentInfo), algorithm, NULL, keysize);
        break;
     default:
        /* Assume password-based-encryption.  At least, try that. */
 #if 1
        // @@@ Fix me
-       pbe_algid = NULL;
+        rv = SECFailure;
+        break;
 #else
        pbe_algid = PK11_CreatePBEAlgorithmID(algorithm, 1, NULL);
-#endif
        if (pbe_algid == NULL) {
            rv = SECFailure;
            break;
        }
-       rv = SecCmsContentInfoSetContentEncAlgID((SecArenaPoolRef)poolp, &(encd->contentInfo), pbe_algid, keysize);
+       rv = SecCmsContentInfoSetContentEncAlgID(&(encd->contentInfo), pbe_algid, keysize);
        SECOID_DestroyAlgorithmID (pbe_algid, PR_TRUE);
        break;
+#endif
     }
     if (rv != SECSuccess)
        goto loser;
@@ -116,6 +124,9 @@ loser:
 void
 SecCmsEncryptedDataDestroy(SecCmsEncryptedDataRef encd)
 {
+    if (encd == NULL) {
+        return;
+    }
     /* everything's in a pool, so don't worry about the storage */
     SecCmsContentInfoDestroy(&(encd->contentInfo));
     return;
@@ -143,7 +154,7 @@ SecCmsEncryptedDataEncodeBeforeStart(SecCmsEncryptedDataRef encd)
 {
     int version;
     SecSymmetricKeyRef bulkkey = NULL;
-    CSSM_DATA_PTR dummy;
+    SecAsn1Item * dummy;
     SecCmsContentInfoRef cinfo = &(encd->contentInfo);
 
     if (SecCmsArrayIsEmpty((void **)encd->unprotectedAttr))
@@ -151,13 +162,13 @@ SecCmsEncryptedDataEncodeBeforeStart(SecCmsEncryptedDataRef encd)
     else
        version = SEC_CMS_ENCRYPTED_DATA_VERSION_UPATTR;
     
-    dummy = SEC_ASN1EncodeInteger (encd->cmsg->poolp, &(encd->version), version);
+    dummy = SEC_ASN1EncodeInteger (encd->contentInfo.cmsg->poolp, &(encd->version), version);
     if (dummy == NULL)
        return SECFailure;
 
     /* now get content encryption key (bulk key) by using our cmsg callback */
-    if (encd->cmsg->decrypt_key_cb)
-       bulkkey = (*encd->cmsg->decrypt_key_cb)(encd->cmsg->decrypt_key_cb_arg, 
+    if (encd->contentInfo.cmsg->decrypt_key_cb)
+       bulkkey = (*encd->contentInfo.cmsg->decrypt_key_cb)(encd->contentInfo.cmsg->decrypt_key_cb_arg, 
                    SecCmsContentInfoGetContentEncAlg(cinfo));
     if (bulkkey == NULL)
        return SECFailure;
@@ -192,7 +203,7 @@ SecCmsEncryptedDataEncodeBeforeData(SecCmsEncryptedDataRef encd)
     /* this may modify algid (with IVs generated in a token).
      * it is therefore essential that algid is a pointer to the "real" contentEncAlg,
      * not just to a copy */
-    cinfo->ciphcx = SecCmsCipherContextStartEncrypt(encd->cmsg->poolp, bulkkey, algid);
+    cinfo->ciphcx = SecCmsCipherContextStartEncrypt(encd->contentInfo.cmsg->poolp, bulkkey, algid);
     CFRelease(bulkkey);
     if (cinfo->ciphcx == NULL)
        return SECFailure;
@@ -231,10 +242,10 @@ SecCmsEncryptedDataDecodeBeforeData(SecCmsEncryptedDataRef encd)
 
     bulkalg = SecCmsContentInfoGetContentEncAlg(cinfo);
 
-    if (encd->cmsg->decrypt_key_cb == NULL)    /* no callback? no key../ */
+    if (encd->contentInfo.cmsg->decrypt_key_cb == NULL)        /* no callback? no key../ */
        goto loser;
 
-    bulkkey = (*encd->cmsg->decrypt_key_cb)(encd->cmsg->decrypt_key_cb_arg, bulkalg);
+    bulkkey = (*encd->contentInfo.cmsg->decrypt_key_cb)(encd->contentInfo.cmsg->decrypt_key_cb_arg, bulkalg);
     if (bulkkey == NULL)
        /* no success finding a bulk key */
        goto loser;