X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/fa7225c82381bac4432a6edf16f53b5370238d85..07691282a056c4efea71e1e505527601e8cc166b:/OSX/libsecurity_smime/lib/cmspubkey.c diff --git a/OSX/libsecurity_smime/lib/cmspubkey.c b/OSX/libsecurity_smime/lib/cmspubkey.c index 19ff2065..c4dc0eaa 100644 --- a/OSX/libsecurity_smime/lib/cmspubkey.c +++ b/OSX/libsecurity_smime/lib/cmspubkey.c @@ -70,13 +70,7 @@ SecCmsUtilEncryptSymKeyRSA(PLArenaPool *poolp, SecCertificateRef cert, 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; @@ -94,29 +88,23 @@ SecCmsUtilEncryptSymKeyRSAPubKey(PLArenaPool *poolp, unsigned int data_len; //KeyType keyType; void *mark = NULL; + CFDictionaryRef theirKeyAttrs = NULL; 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 */ -#if TARGET_OS_MAC && !TARGET_OS_IPHONE - rv = SecKeyGetStrengthInBits(publickey, NULL, &data_len); - if (rv) + theirKeyAttrs = SecKeyCopyAttributes(publickey); + if (!theirKeyAttrs) { goto loser; + } + + CFNumberRef keySizeNum = CFDictionaryGetValue(theirKeyAttrs, kSecAttrKeySizeInBits); + if (!CFNumberGetValue(keySizeNum, kCFNumberIntType, &data_len)) { + goto loser; + } // 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; @@ -132,6 +120,9 @@ SecCmsUtilEncryptSymKeyRSAPubKey(PLArenaPool *poolp, return SECSuccess; loser: + if (theirKeyAttrs) { + CFRelease(theirKeyAttrs); + } if (mark) { PORT_ArenaRelease(poolp, mark); } @@ -780,11 +771,7 @@ SecCmsUtilEncryptSymKeyECDH( 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;