2  * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved. 
   4  * The contents of this file constitute Original Code as defined in and are 
   5  * subject to the Apple Public Source License Version 1.2 (the 'License'). 
   6  * You may not use this file except in compliance with the License. Please obtain 
   7  * a copy of the License at http://www.apple.com/publicsource and read it before 
  10  * This Original Code and all software distributed under the License are 
  11  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 
  12  * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 
  13  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
  14  * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 
  15  * specific language governing rights and limitations under the License. 
  18 #include <Security/SecKey.h> 
  20 #include "SecBridge.h" 
  22 #include <Security/Access.h> 
  23 #include <Security/Keychains.h> 
  24 #include <Security/KeyItem.h> 
  31         return gTypes().keyItem
.typeId
; 
  33         END_SECAPI1(_kCFRuntimeNotATypeID
) 
  38         SecKeychainRef keychainRef
, 
  39         CSSM_ALGORITHMS algorithm
, 
  41         CSSM_CC_HANDLE contextHandle
, 
  42         CSSM_KEYUSE publicKeyUsage
, 
  44         CSSM_KEYUSE privateKeyUsage
, 
  45         uint32 privateKeyAttr
, 
  46         SecAccessRef initialAccess
, 
  47         SecKeyRef
* publicKeyRef
,  
  48         SecKeyRef
* privateKeyRef
) 
  52         Keychain keychain 
= Keychain::optional(keychainRef
); 
  53         RefPointer
<Access
> theAccess(initialAccess 
? gTypes().access
.required(initialAccess
) : new Access("<key>")); 
  54         RefPointer
<KeyItem
> pubItem
, privItem
; 
  56         KeyItem::createPair(keychain
, 
  68         // Return the generated keys. 
  70                 *publicKeyRef 
= gTypes().keyItem
.handle(*pubItem
); 
  72                 *privateKeyRef 
= gTypes().keyItem
.handle(*privItem
); 
  78 SecKeyGetCSSMKey(SecKeyRef key
, const CSSM_KEY 
**cssmKey
) 
  82         Required(cssmKey
) = &gTypes().keyItem
.required(key
)->cssmKey(); 
  95         CSSM_ACL_AUTHORIZATION_TAG operation
, 
  96         SecCredentialType credentialType
, 
  97         const CSSM_ACCESS_CREDENTIALS 
**outCredentials
) 
 101         RefPointer
<KeyItem
> keyItem(gTypes().keyItem
.required(keyRef
)); 
 102         Required(outCredentials
) = keyItem
->getCredentials(operation
, credentialType
); 
 109         SecKeychainRef keychainRef
, 
 110         const CSSM_KEY 
*publicCssmKey
, 
 111         const CSSM_KEY 
*privateCssmKey
, 
 112         SecAccessRef initialAccess
, 
 113         SecKeyRef
* publicKey
, 
 114         SecKeyRef
* privateKey
) 
 118         Keychain keychain 
= Keychain::optional(keychainRef
); 
 119         RefPointer
<Access
> theAccess(initialAccess 
? gTypes().access
.required(initialAccess
) : new Access("<key>")); 
 120         RefPointer
<KeyItem
> pubItem
, privItem
; 
 122         KeyItem::importPair(keychain
, 
 123                 Required(publicCssmKey
), 
 124                 Required(privateCssmKey
), 
 129         // Return the generated keys. 
 131                 *publicKey 
= gTypes().keyItem
.handle(*pubItem
); 
 133                 *privateKey 
= gTypes().keyItem
.handle(*privItem
);