5 * Created by Michael Brouwer on Fri Nov 08 2002.
6 * Copyright (c) 2002 __MyCompanyName__. All rights reserved.
11 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
13 * The contents of this file constitute Original Code as defined in and are
14 * subject to the Apple Public Source License Version 1.2 (the 'License').
15 * You may not use this file except in compliance with the License. Please obtain
16 * a copy of the License at http://www.apple.com/publicsource and read it before
19 * This Original Code and all software distributed under the License are
20 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
21 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
22 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
24 * specific language governing rights and limitations under the License.
29 The functions provided in SecKeyPriv implement a particular type of SecKeychainItem which represents a key. SecKeys might be stored in a SecKeychain, but can also be used as transient object representing keys.
31 Most SecKeychainItem* functions will work on an SecKeyRef.
34 #ifndef _SECURITY_SECKEYPRIV_H_
35 #define _SECURITY_SECKEYPRIV_H_
37 #include <Security/SecKey.h>
40 #if defined(__cplusplus)
45 @typedef SecCredentialType
46 @abstract Determines the type of credential returned by SecKeyGetCredentials.
48 typedef uint32 SecCredentialType
;
51 @enum SecCredentialType
52 @abstract Determines the type of credential returned by SecKeyGetCredentials.
53 @constant kSecCredentialTypeWithUI will cause UI to happen if needed.
54 @constant kSecCredentialTypeNoUI will fail if UI would of been required.
55 @constant kSecCredentialTypeDefault will choose to do UI when other SecKeychain calls currently do.
59 kSecCredentialTypeDefault
= 0,
60 kSecCredentialTypeWithUI
,
61 kSecCredentialTypeNoUI
66 @function SecKeyGetCSPHandle
67 @abstract Returns the CSSM_CSP_HANDLE attachment for the given key reference. The handle is valid until the key reference is released.
68 @param keyRef A key reference.
69 @param cspHandle On return, a pointer to the CSSM_CSP_HANDLE for the given keychain.
70 @result A result code. See "Security Error Codes" (SecBase.h).
73 SecKeyGetCSPHandle(SecKeyRef keyRef
, CSSM_CSP_HANDLE
*cspHandle
);
76 SecKeyGetAlgorithmID(SecKeyRef key
, const CSSM_X509_ALGORITHM_IDENTIFIER
**algid
);
79 SecKeyGetStrengthInBits(SecKeyRef key
, const CSSM_X509_ALGORITHM_IDENTIFIER
*algid
, unsigned int *strength
);
83 @function SecKeyGetCredentials
84 @abstract For a given key return a const CSSM_ACCESS_CREDENTIALS * which will allow the key to be used.
85 @param keyRef The key for which a credential is requested.
86 @param operation the type of operation which is going to be perform on this key. Examples are: CSSM_ACL_AUTHORIZATION_SIGN, CSSM_ACL_AUTHORIZATION_DECRYPT, CSSM_ACL_AUTHORIZATION_EXPORT_WRAPPED.
87 @param credentialType The type of credential requested.
88 @param outCredentials Output a pointer to a const CSSM_ACCESS_CREDENTIALS * is returned here which remains valid at least as long as the keyRef itself remains valid, which can be used in CDSA calls.
89 @result A result code. See "Security Error Codes" (SecBase.h).
91 OSStatus
SecKeyGetCredentials(
93 CSSM_ACL_AUTHORIZATION_TAG operation
,
94 SecCredentialType credentialType
,
95 const CSSM_ACCESS_CREDENTIALS
**outCredentials
);
98 @function SecKeyImportPair
99 @abstract Takes an asymmetric key pair and stores it in the keychain specified by the keychain parameter.
100 @param keychainRef A reference to the keychain in which to store the private and public key items. Specify NULL for the default keychain.
101 @param publicCssmKey A CSSM_KEY which is valid for the CSP returned by SecKeychainGetCSPHandle(). This may be a normal key or reference key.
102 @param privateCssmKey A CSSM_KEY which is valid for the CSP returned by SecKeychainGetCSPHandle(). This may be a normal key or reference key.
103 @param initialAccess A SecAccess object that determines the initial access rights to the private key. The public key is given an any/any acl by default.
104 @param publicKey Optional output pointer to the keychain item reference of the imported public key. The caller must call CFRelease on this value if it is returned.
105 @param privateKey Optional output pointer to the keychain item reference of the imported private key. The caller must call CFRelease on this value if it is returned.
106 @result A result code. See "Security Error Codes" (SecBase.h).
108 OSStatus
SecKeyImportPair(
109 SecKeychainRef keychainRef
,
110 const CSSM_KEY
*publicCssmKey
,
111 const CSSM_KEY
*privateCssmKey
,
112 SecAccessRef initialAccess
,
113 SecKeyRef
* publicKey
,
114 SecKeyRef
* privateKey
);
117 @function SecKeyGenerate
118 @abstract Generate a symmetric key and optionally stores it in the keychain specified by the keychainRef parameter.
119 @param keychainRef(optional) A reference to the keychain in which to store the private and public key items. Specify NULL to generate a transient key.
120 @param algorithm An algorithm for the key pair. This parameter is ignored if contextHandle is non 0.
121 @param keySizeInBits A key size for the key pair. This parameter is ignored if contextHandle is non 0.
122 @param contextHandle(optional) An optional CSSM_CC_HANDLE or 0. If this argument is not 0 the algorithm and keySizeInBits parameters are ignored. If extra parameters are needed to generate a key (some algortihms require this) you should create a context using CSSM_CSP_CreateKeyGenContext(), using the CSPHandle obtained by calling SecKeychainGetCSPHandle(). Then use CSSM_UpdateContextAttributes() to add additional parameters and dispose of the context using CSSM_DeleteContext after calling this function.
123 @param keyUsage A bit mask indicating all permitted uses for the new key. The bit mask values are defined in cssmtype.h
124 @param keyAttr A bit mask defining attribute values for the new key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h
125 @param initialAccess(optional) A SecAccess object that determines the initial access rights to the key. This parameter is ignored if the keychainRef is NULL.
126 @param key Output pointer to the keychain item reference of the geerated key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned.
127 @result A result code. See "Security Error Codes" (SecBase.h).
129 OSStatus
SecKeyGenerate(
130 SecKeychainRef keychainRef
,
131 CSSM_ALGORITHMS algorithm
,
132 uint32 keySizeInBits
,
133 CSSM_CC_HANDLE contextHandle
,
134 CSSM_KEYUSE keyUsage
,
136 SecAccessRef initialAccess
,
139 OSStatus
SecKeyCreate(const CSSM_KEY
*key
,
143 #if defined(__cplusplus)
147 #endif /* !_SECURITY_SECKEYPRIV_H_ */