]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_smime/lib/cmspubkey.c
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / libsecurity_smime / lib / cmspubkey.c
index 19ff2065c2725d618baecdcd8e8fce7dab38fe92..c4dc0eaa4f65397f10da3b3a2bbd4c0314698cd8 100644 (file)
@@ -70,13 +70,7 @@ SecCmsUtilEncryptSymKeyRSA(PLArenaPool *poolp, SecCertificateRef cert,
                               CSSM_DATA_PTR encKey)
 {
     OSStatus rv;
                               CSSM_DATA_PTR encKey)
 {
     OSStatus rv;
-    SecPublicKeyRef publickey;
-
-#if TARGET_OS_MAC && !TARGET_OS_IPHONE
-    rv = SecCertificateCopyPublicKey(cert,&publickey);
-#else
-    publickey = SecCertificateCopyPublicKey(cert);
-#endif
+    SecPublicKeyRef publickey = SecCertificateCopyKey(cert);
     if (publickey == NULL)
        return SECFailure;
 
     if (publickey == NULL)
        return SECFailure;
 
@@ -94,29 +88,23 @@ SecCmsUtilEncryptSymKeyRSAPubKey(PLArenaPool *poolp,
     unsigned int data_len;
     //KeyType keyType;
     void *mark = NULL;
     unsigned int data_len;
     //KeyType keyType;
     void *mark = NULL;
+    CFDictionaryRef theirKeyAttrs = NULL;
 
     mark = PORT_ArenaMark(poolp);
     if (!mark)
        goto loser;
 
     mark = PORT_ArenaMark(poolp);
     if (!mark)
        goto loser;
-
-#if 0
-    /* sanity check */
-    keyType = SECKEY_GetPublicKeyType(publickey);
-    PORT_Assert(keyType == rsaKey);
-    if (keyType != rsaKey) {
-       goto loser;
-    }
-#endif
     /* allocate memory for the encrypted key */
     /* allocate memory for the encrypted key */
-#if TARGET_OS_MAC && !TARGET_OS_IPHONE
-    rv = SecKeyGetStrengthInBits(publickey, NULL, &data_len);
-    if (rv)
+    theirKeyAttrs = SecKeyCopyAttributes(publickey);
+    if (!theirKeyAttrs) {
         goto loser;
         goto loser;
+    }
+
+    CFNumberRef keySizeNum = CFDictionaryGetValue(theirKeyAttrs, kSecAttrKeySizeInBits);
+    if (!CFNumberGetValue(keySizeNum, kCFNumberIntType, &data_len)) {
+        goto loser;
+    }
     // Convert length to bytes;
     // Convert length to bytes;
-    data_len = data_len / 8;
-#else
-    data_len = SecKeyGetSize(publickey, kSecKeyEncryptedDataSize);
-#endif
+    data_len /= 8;
 
     encKey->Data = (unsigned char*)PORT_ArenaAlloc(poolp, data_len);
     encKey->Length = data_len;
 
     encKey->Data = (unsigned char*)PORT_ArenaAlloc(poolp, data_len);
     encKey->Length = data_len;
@@ -132,6 +120,9 @@ SecCmsUtilEncryptSymKeyRSAPubKey(PLArenaPool *poolp,
     return SECSuccess;
 
 loser:
     return SECSuccess;
 
 loser:
+    if (theirKeyAttrs) {
+        CFRelease(theirKeyAttrs);
+    }
     if (mark) {
        PORT_ArenaRelease(poolp, mark);
     }
     if (mark) {
        PORT_ArenaRelease(poolp, mark);
     }
@@ -780,11 +771,7 @@ SecCmsUtilEncryptSymKeyECDH(
     encKey->Length = 0;
 
     /* Copy the recipient's static public ECDH key */
     encKey->Length = 0;
 
     /* Copy the recipient's static public ECDH key */
-#if TARGET_OS_IPHONE
-    theirPubKey = SecCertificateCopyPublicKey(cert);
-#else
-    rv = SecCertificateCopyPublicKey(cert, &theirPubKey);
-#endif
+    theirPubKey = SecCertificateCopyKey(cert);
     if (rv || !theirPubKey) {
         dprintf("SecCmsUtilEncryptSymKeyECDH: failed to get public key from cert, %d\n", (int)rv);
         goto out;
     if (rv || !theirPubKey) {
         dprintf("SecCmsUtilEncryptSymKeyECDH: failed to get public key from cert, %d\n", (int)rv);
         goto out;