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;
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;
return SECSuccess;
loser:
+ if (theirKeyAttrs) {
+ CFRelease(theirKeyAttrs);
+ }
if (mark) {
PORT_ArenaRelease(poolp, mark);
}
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;