]> git.saurik.com Git - apple/security.git/blob - Keychain/SecKeychain.h
Security-176.tar.gz
[apple/security.git] / Keychain / SecKeychain.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18 /*!
19 @header SecKeychain
20 SecKeychain implements a repository for securely storing items with publicly visible attributes by which to find the items.
21 */
22
23 #ifndef _SECURITY_SECKEYCHAIN_H_
24 #define _SECURITY_SECKEYCHAIN_H_
25
26 #include <Security/SecBase.h>
27 #include <Security/cssmapple.h>
28 #include <CoreFoundation/CFArray.h>
29
30 #if defined(__cplusplus)
31 extern "C" {
32 #endif
33
34 /*!
35 @enum KeychainStatus
36 @abstract Defines the current status of a keychain.
37 @constant kSecUnlockStateStatus Indicates the keychain is unlocked.
38 @constant kSecReadPermStatus Indicates the keychain is readable.
39 @constant kSecWritePermStatus Indicates the keychain is writable.
40 */
41 enum
42 {
43 kSecUnlockStateStatus = 1,
44 kSecReadPermStatus = 2,
45 kSecWritePermStatus = 4
46 };
47
48 #define SEC_KEYCHAIN_SETTINGS_VERS1 1
49
50
51 /*!
52 @typedef SecKeychainSettings
53 @abstract Contains keychain settings.
54 @field version An unsigned 32-bit integer representing the keychain version.
55 @field lockOnSleep A boolean value indicating whether the keychain locks when the system sleeps.
56 @field useLockInterval A boolean value indicating whether the keychain automatically locks after a certain period of time.
57 @field lockInterval An unsigned 32-bit integer representing the number of seconds before the keychain locks.
58 */
59 struct SecKeychainSettings
60 {
61 UInt32 version;
62 Boolean lockOnSleep;
63 Boolean useLockInterval;
64 UInt32 lockInterval;
65 };
66 typedef struct SecKeychainSettings SecKeychainSettings;
67
68 /*!
69 @typedef SecAuthenticationType
70 @abstract Represents the type of authentication to use for an Internet password.
71 */
72 typedef FourCharCode SecAuthenticationType;
73
74 /*!
75 @enum AuthenticationConstants
76 @abstract Defines constants you can use to identify the type of authentication to use for an Internet password.
77 @constant kSecAuthenticationTypeNTLM Specifies Windows NT LAN Manager authentication.
78 @constant kSecAuthenticationTypeMSN Specifies Microsoft Network default authentication.
79 @constant kSecAuthenticationTypeDPA Specifies Distributed Password authentication.
80 @constant kSecAuthenticationTypeRPA Specifies Remote Password authentication.
81 @constant kSecAuthenticationTypeHTTPBasic Specifies HTTP Basic authentication.
82 @constant kSecAuthenticationTypeHTTPDigest Specifies HTTP Digest Access authentication.
83 @constant kSecAuthenticationTypeHTMLForm Specifies HTML form based authentication.
84 @constant kSecAuthenticationTypeDefault Specifies the default authentication type.
85 */
86 #ifdef __LITTLE_ENDIAN__
87 #define AUTH_TYPE_FIX_(x) \
88 ((x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x & 0xff) << 24)
89 #else
90 #define AUTH_TYPE_FIX_(x) (x)
91 #endif
92
93 enum
94 {
95 kSecAuthenticationTypeNTLM = AUTH_TYPE_FIX_ ('ntlm'),
96 kSecAuthenticationTypeMSN = AUTH_TYPE_FIX_ ('msna'),
97 kSecAuthenticationTypeDPA = AUTH_TYPE_FIX_ ('dpaa'),
98 kSecAuthenticationTypeRPA = AUTH_TYPE_FIX_ ('rpaa'),
99 kSecAuthenticationTypeHTTPBasic = AUTH_TYPE_FIX_ ('http'),
100 kSecAuthenticationTypeHTTPDigest = AUTH_TYPE_FIX_ ('httd'),
101 kSecAuthenticationTypeHTMLForm = AUTH_TYPE_FIX_ ('form'),
102 kSecAuthenticationTypeDefault = AUTH_TYPE_FIX_ ('dflt')
103 };
104
105 /*!
106 @typedef SecProtocolType
107 @abstract Represents the protocol type associated with an AppleShare or Internet password.
108 */
109 typedef FourCharCode SecProtocolType;
110
111 /*!
112 @enum ProtocolTypeConstants
113 @abstract Defines the protocol type associated with an AppleShare or Internet password.
114 @constant kSecProtocolTypeFTP Indicates FTP.
115 @constant kSecProtocolTypeFTPAccount Indicates FTP Account (client side), usage deprecated.
116 @constant kSecProtocolTypeHTTP Indicates HTTP.
117 @constant kSecProtocolTypeIRC Indicates IRC.
118 @constant kSecProtocolTypeNNTP Indicates NNTP.
119 @constant kSecProtocolTypePOP3 Indicates POP3.
120 @constant kSecProtocolTypeSMTP Indicates SMTP.
121 @constant kSecProtocolTypeSOCKS Indicates SOCKS.
122 @constant kSecProtocolTypeIMAP Indicates IMAP.
123 @constant kSecProtocolTypeLDAP Indicates LDAP.
124 @constant kSecProtocolTypeAppleTalk Indicates AFP over AppleTalk.
125 @constant kSecProtocolTypeAFP Indicates AFP over TCP.
126 @constant kSecProtocolTypeTelnet Indicates Telnet.
127 @constant kSecProtocolTypeSSH Indicates SSH.
128 @constant kSecProtocolTypeFTPS Indicates FTPS (FTP over TLS/SSL).
129 @constant kSecProtocolTypeHTTPS Indicates HTTPS (HTTP over TLS/SSL).
130 @constant kSecProtocolTypeHTTPProxy Indicates HTTP proxy.
131 @constant kSecProtocolTypeHTTPSProxy Indicates HTTPS proxy.
132 @constant kSecProtocolTypeFTPProxy Indicates FTP proxy.
133 @constant kSecProtocolTypeSMB Indicates SMB.
134 @constant kSecProtocolTypeRTSP Indicates RTSP.
135 @constant kSecProtocolTypeRTSPProxy Indicates RTSP proxy.
136 @constant kSecProtocolTypeDAAP Indicates DAAP.
137 @constant kSecProtocolTypeEPPC Indicates EPPC (Remote Apple Events).
138 @constant kSecProtocolTypeIPP Indicates IPP.
139 @constant kSecProtocolTypeNNTPS Indicates NNTPS (NNTP over TLS/SSL).
140 @constant kSecProtocolTypeLDAPS Indicates LDAPS (LDAP over TLS/SSL).
141 @constant kSecProtocolTypeTelnetS Indicates Telnet over TLS/SSL.
142 @constant kSecProtocolTypeIMAPS Indicates IMAPS (IMAP4 over TLS/SSL).
143 @constant kSecProtocolTypeIRCS Indicates IRCS (IRC over TLS/SSL).
144 @constant kSecProtocolTypePOP3S Indicates POP3S (POP3 over TLS/SSL).
145 */
146 enum
147 {
148 kSecProtocolTypeFTP = 'ftp ',
149 kSecProtocolTypeFTPAccount = 'ftpa',
150 kSecProtocolTypeHTTP = 'http',
151 kSecProtocolTypeIRC = 'irc ',
152 kSecProtocolTypeNNTP = 'nntp',
153 kSecProtocolTypePOP3 = 'pop3',
154 kSecProtocolTypeSMTP = 'smtp',
155 kSecProtocolTypeSOCKS = 'sox ',
156 kSecProtocolTypeIMAP = 'imap',
157 kSecProtocolTypeLDAP = 'ldap',
158 kSecProtocolTypeAppleTalk = 'atlk',
159 kSecProtocolTypeAFP = 'afp ',
160 kSecProtocolTypeTelnet = 'teln',
161 kSecProtocolTypeSSH = 'ssh ',
162 kSecProtocolTypeFTPS = 'ftps',
163 kSecProtocolTypeHTTPS = 'htps',
164 kSecProtocolTypeHTTPProxy = 'htpx',
165 kSecProtocolTypeHTTPSProxy = 'htsx',
166 kSecProtocolTypeFTPProxy = 'ftpx',
167 kSecProtocolTypeSMB = 'smb ',
168 kSecProtocolTypeRTSP = 'rtsp',
169 kSecProtocolTypeRTSPProxy = 'rtsx',
170 kSecProtocolTypeDAAP = 'daap',
171 kSecProtocolTypeEPPC = 'eppc',
172 kSecProtocolTypeIPP = 'ipp ',
173 kSecProtocolTypeNNTPS = 'ntps',
174 kSecProtocolTypeLDAPS = 'ldps',
175 kSecProtocolTypeTelnetS = 'tels',
176 kSecProtocolTypeIMAPS = 'imps',
177 kSecProtocolTypeIRCS = 'ircs',
178 kSecProtocolTypePOP3S = 'pops'
179 };
180
181 /*!
182 @typedef SecKeychainEvent
183 @abstract Represents an event in which the state of a keychain or one of its items changed.
184 */
185 typedef UInt32 SecKeychainEvent;
186
187 /*!
188 @enum KeychainEventConstants
189 @abstract Defines the keychain-related event.
190 @constant kSecLockEvent Indicates a keychain was locked.
191 @constant kSecUnlockEvent Indicates a keychain was unlocked.
192 @constant kSecAddEvent Indicates an item was added to a keychain.
193 @constant kSecDeleteEvent Indicates an item was deleted from a keychain.
194 @constant kSecUpdateEvent Indicates a keychain item was updated.
195 @constant kSecPasswordChangedEvent Indicates the keychain password was changed.
196 @constant kSecDefaultChangedEvent Indicates that a different keychain was specified as the default.
197 @constant kSecDataAccessEvent Indicates a process has accessed a keychain item's data.
198 @constant kSecKeychainListChangedEvent Indicates the list of keychains has changed.
199 */
200 enum
201 {
202 kSecLockEvent = 1,
203 kSecUnlockEvent = 2,
204 kSecAddEvent = 3,
205 kSecDeleteEvent = 4,
206 kSecUpdateEvent = 5,
207 kSecPasswordChangedEvent = 6,
208 kSecDefaultChangedEvent = 9,
209 kSecDataAccessEvent = 10,
210 kSecKeychainListChangedEvent = 11
211 };
212
213 /*!
214 @typedef SecKeychainEventMask
215 @abstract Represents a bit mask of keychain events
216 */
217 typedef UInt32 SecKeychainEventMask;
218
219 /*!
220 @enum KeychainEventConstants
221 @abstract Defines keychain event constants
222 @constant kSecLockEventMask If the bit specified by this mask is set, your callback function will be invoked when a keychain is locked.
223 @constant kSecUnlockEventMask If the bit specified by this mask is set, your callback function will be invoked when a keychain is unlocked.
224 @constant kSecAddEventMask If the bit specified by this mask is set, your callback function will be invoked when an item is added to a keychain.
225 @constant kSecDeleteEventMask If the bit specified by this mask is set, your callback function will be invoked when an item is deleted from a keychain.
226 @constant kSecUpdateEventMask If the bit specified by this mask is set, your callback function will be invoked when a keychain item is updated.
227 @constant kSecPasswordChangedEventMask If the bit specified by this mask is set, your callback function will be invoked when the keychain password is changed.
228 @constant kSecDefaultChangedEventMask If the bit specified by this mask is set, your callback function will be invoked when a different keychain is specified as the default.
229 @constant kSecDataAccessEventMask If the bit specified by this mask is set, your callback function will be invoked when a process accesses a keychain item's data.
230 @constant kSecEveryEventMask If all the bits are set, your callback function will be invoked whenever any event occurs.
231 */
232 enum
233 {
234 kSecLockEventMask = 1 << kSecLockEvent,
235 kSecUnlockEventMask = 1 << kSecUnlockEvent,
236 kSecAddEventMask = 1 << kSecAddEvent,
237 kSecDeleteEventMask = 1 << kSecDeleteEvent,
238 kSecUpdateEventMask = 1 << kSecUpdateEvent,
239 kSecPasswordChangedEventMask = 1 << kSecPasswordChangedEvent,
240 kSecDefaultChangedEventMask = 1 << kSecDefaultChangedEvent,
241 kSecDataAccessEventMask = 1 << kSecDataAccessEvent,
242 kSecKeychainListChangedMask = 1 << kSecKeychainListChangedEvent,
243 kSecEveryEventMask = 0xffffffff
244 };
245
246 /*!
247 @typedef SecKeychainCallbackInfo
248 @abstract Contains information about a keychain event.
249 @field version The version of this structure.
250 @field item A reference to the keychain item associated with this event, if any. Note that some events do not involve a particular keychain item.
251 @field keychain A reference to the keychain in which the event occurred.
252 @field pid The id of the process that generated this event.
253 @discussion The SecKeychainCallbackInfo type represents a structure that contains information about the keychain event for which your application is being notified. For information on how to write a keychain event callback function, see SecKeychainCallback.
254 */
255 struct SecKeychainCallbackInfo
256 {
257 UInt32 version;
258 SecKeychainItemRef item;
259 SecKeychainRef keychain;
260 pid_t pid;
261 };
262 typedef struct SecKeychainCallbackInfo SecKeychainCallbackInfo;
263
264 /*!
265 @function SecKeychainGetTypeID
266 @abstract Returns the type identifier of SecKeychain instances.
267 @result The CFTypeID of SecKeychain instances.
268 */
269 CFTypeID SecKeychainGetTypeID(void);
270
271 /*!
272 @function SecKeychainGetVersion
273 @abstract Determines the version of the Keychain Manager installed on the userÕs system.
274 @param returnVers On return, a pointer to the version number of the Keychain Manager installed on the current system.
275 @result A result code. See "Security Error Codes" (SecBase.h).
276 */
277 OSStatus SecKeychainGetVersion(UInt32 *returnVers);
278
279 #pragma mark ÑÑÑÑ Keychain Management ÑÑÑÑ
280 /*!
281 @function SecKeychainOpen
282 @abstract Create a SecKeychainRef for a keychain at pathName. This keychain might
283 not currently exist, use SecKeychainGetStatus if you want to confirm the existence
284 of this keychain.
285 @param pathName The POSIX path to a keychain.
286 @param keychain On return, a pointer to the keychain reference. The memory that keychain occupies must be released by calling CFRelease when finished with it.
287 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if the keychain parameter is invalid (NULL).
288 */
289 OSStatus SecKeychainOpen(const char *pathName, SecKeychainRef *keychain);
290
291 /*!
292 @function SecKeychainCreate
293 @abstract Creates a new keychain.
294 @param pathName The POSIX path to a keychain file.
295 @param passwordLength An unsigned 32-bit integer representing the length of the password buffer.
296 @param password A pointer to the buffer containing the password. The password must be in canonical UTF8 encoding.
297 @param promptUser A boolean representing whether to display a password dialog to the user.
298 @param initialAccess An access reference.
299 @param keychain On return, a pointer to a keychain reference. The memory that keychain occupies must be released by calling CFRelease when finished with it.
300 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if the keychain parameter is invalid (NULL).
301 */
302 OSStatus SecKeychainCreate(const char *pathName, UInt32 passwordLength, const void *password, Boolean promptUser, SecAccessRef initialAccess, SecKeychainRef *keychain);
303
304 /*!
305 @function SecKeychainDelete
306 @abstract Removes one or more keychains from the current keychain searchlist, and deletes the keychain storage (if the keychains are file-based).
307 @param keychainOrArray A single keychain reference or a reference to an array of keychains to delete.
308 @result A result code. See "Security Error Codes" (SecBase.h). In addition, errSecInvalidKeychain (-25295) may be returned if the keychain parameter is invalid (NULL).
309 */
310 OSStatus SecKeychainDelete(SecKeychainRef keychainOrArray);
311
312 /*!
313 @function SecKeychainSetSettings
314 @abstract Changes the settings of a keychain.
315 @param keychain A reference to a keychain.
316 @param newSettings A pointer to the new keychain settings.
317 @result A result code. See "Security Error Codes" (SecBase.h).
318 */
319 OSStatus SecKeychainSetSettings(SecKeychainRef keychain, const SecKeychainSettings *newSettings);
320
321 /*!
322 @function SecKeychainCopySettings
323 @abstract Copy the keychain settings.
324 @param keychain A reference to the keychain from which to copy its settings.
325 @param outSettings A pointer to a keychain settings structure. Since this structure is versioned, you must preallocate it and fill in the version of the structure.
326 @result A result code. See "Security Error Codes" (SecBase.h).
327 */
328 OSStatus SecKeychainCopySettings(SecKeychainRef keychain, SecKeychainSettings *outSettings);
329
330 /*!
331 @function SecKeychainUnlock
332 @abstract Unlocks the specified keychain.
333 @param keychain A reference to the keychain to unlock. Pass NULL to specify the default keychain. If you pass NULL and the default keychain is currently locked, the keychain will appear as the default choice. If you pass a locked keychain, SecKeychainUnlock will use the password provided to unlock it. If the default keychain is currently unlocked, SecKeychainUnlock returns noErr.
334 @param passwordLength An unsigned 32-bit integer representing the length of the password buffer.
335 @param password A buffer containing the password for the keychain. Pass NULL if the user password is unknown. In this case, SecKeychainUnlock displays the Unlock Keychain dialog box, and the authentication user interface associated with the keychain about to be unlocked.
336 @param usePassword A boolean indicating whether the password parameter is used. You should pass TRUE if it is used or FALSE if it is ignored.
337 @result A result code. See "Security Error Codes" (SecBase.h).
338 @discussion In most cases, your application does not need to call the SecKeychainUnlock function directly, since most Keychain Manager functions that require an unlocked keychain call SecKeychainUnlock automatically. If your application needs to verify that a keychain is unlocked, call the function SecKeychainGetStatus.
339 */
340 OSStatus SecKeychainUnlock(SecKeychainRef keychain, UInt32 passwordLength, void *password, Boolean usePassword);
341
342 /*!
343 @function SecKeychainLock
344 @abstract Locks the specified keychain.
345 @param keychain A reference to the keychain to lock.
346 @result A result code. See "Security Error Codes" (SecBase.h).
347 */
348 OSStatus SecKeychainLock(SecKeychainRef keychain);
349
350 /*!
351 @function SecKeychainLockAll
352 @abstract Locks all keychains belonging to the current user.
353 @result A result code. See "Security Error Codes" (SecBase.h).
354 */
355 OSStatus SecKeychainLockAll(void);
356
357 /*!
358 @function SecKeychainCopyDefault
359 @abstract Retrieves a reference to the default keychain.
360 @param keychain On return, a pointer to the default keychain reference.
361 @result A result code. See "Security Error Codes" (SecBase.h).
362 */
363 OSStatus SecKeychainCopyDefault(SecKeychainRef *keychain);
364
365 /*!
366 @function SecKeychainSetDefault
367 @abstract Sets the default keychain.
368 @param keychain A reference to the keychain to set as default.
369 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if the keychain parameter is invalid (NULL).
370 */
371 OSStatus SecKeychainSetDefault(SecKeychainRef keychain);
372
373 /*!
374 @function SecKeychainCopySearchList
375 @abstract Retrieves a keychain search list.
376 @param searchList The returned list of keychains to search. When finished with the array, you must call CFRelease() to release the memory.
377 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if the keychain list is not specified (NULL).
378 */
379 OSStatus SecKeychainCopySearchList(CFArrayRef *searchList);
380
381 /*!
382 @function SecKeychainSetSearchList
383 @abstract Specifies the list of keychains to use in a keychain search list.
384 @param searchList The list of keychains to use in a search list when the SecKeychainCopySearchList function is called. An empty array clears the search list.
385 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if the keychain list is not specified (NULL).
386 */
387 OSStatus SecKeychainSetSearchList(CFArrayRef searchList);
388
389
390 /*
391 * New versions of {Copy,Get}{SearchList,Default} that address multiple preference domains.
392 * These calls subsume the old forms with domain == kPreferenceDomainUser.
393 */
394 typedef enum {
395 kSecPreferencesDomainUser, // user domain
396 kSecPreferencesDomainSystem, // system (daemon) domain
397 kSecPreferencesDomainCommon, // preferences to be merged to everyone
398 kSecPreferencesDomainAlternate // alternate user
399 } SecPreferencesDomain;
400
401 OSStatus SecKeychainCopyDomainDefault(SecPreferencesDomain domain, SecKeychainRef *keychain);
402 OSStatus SecKeychainSetDomainDefault(SecPreferencesDomain domain, SecKeychainRef keychain);
403 OSStatus SecKeychainCopyDomainSearchList(SecPreferencesDomain domain, CFArrayRef *searchList);
404 OSStatus SecKeychainSetDomainSearchList(SecPreferencesDomain domain, CFArrayRef searchList);
405 OSStatus SecKeychainSetPreferenceDomain(SecPreferencesDomain domain);
406 OSStatus SecKeychainGetPreferenceDomain(SecPreferencesDomain *domain);
407
408
409 /*!
410 @function SecKeychainGetStatus
411 @abstract Retrieves status information for the specified keychain.
412 @param keychain A keychain reference. Pass NULL to specify the default keychain.
413 @param keychainStatus On return, a pointer to the status of the specified keychain. See KeychainStatus for valid status constants.
414 @result A result code. See "Security Error Codes" (SecBase.h).
415 */
416 OSStatus SecKeychainGetStatus(SecKeychainRef keychain, SecKeychainStatus *keychainStatus);
417
418 /*!
419 @function SecKeychainGetPath
420 @abstract Get the path of the specified keychain.
421 @param keychain A reference to a keychain.
422 @param ioPathLength On input, a pointer to the size or the buffer pointed to by pathName. On return, the size of the buffer without the zero termination.
423 @param pathName On return, the POSIX path to the keychain.
424 @result A result code. See "Security Error Codes" (SecBase.h).
425 */
426 OSStatus SecKeychainGetPath(SecKeychainRef keychain, UInt32 *ioPathLength, char *pathName);
427
428 #pragma mark ÑÑÑÑ Keychain Item Attribute Information ÑÑÑÑ
429 /*!
430 @function SecKeychainAttributeInfoForItemID
431 @abstract Obtains tags for all possible attributes for a given item class.
432 @param keychain A keychain reference.
433 @param itemID The relation identifier of the item tags (an itemID is a CSSM_DB_RECORDTYPE defined in cssmtype.h).
434 @param info On return, a pointer to the keychain attribute information. User should call the SecKeychainFreeAttributeInfo function to release the structure when done with it.
435 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if not enough valid parameters were supplied (NULL).
436 @discussion Warning, this call returns more attributes than are support by the old style Keychain API and passing them into older calls will yield an invalid attribute error. The recommended call to retrieve the attribute values is the SecKeychainItemCopyAttributesAndData function.
437 */
438 OSStatus SecKeychainAttributeInfoForItemID(SecKeychainRef keychain, UInt32 itemID, SecKeychainAttributeInfo **info);
439
440 /*!
441 @function SecKeychainFreeAttributeInfo
442 @abstract Releases the memory acquired by calling the SecKeychainAttributeInfoForItemID function.
443 @param info A pointer to the keychain attribute information to release.
444 @result A result code. See "Security Error Codes" (SecBase.h). In addition, paramErr (-50) may be returned if not enough valid parameters were supplied (NULL).
445 */
446 OSStatus SecKeychainFreeAttributeInfo(SecKeychainAttributeInfo *info);
447
448 #pragma mark ÑÑÑÑ Keychain Manager Callbacks ÑÑÑÑ
449
450 /*!
451 @typedef SecKeychainCallback
452 @abstract Defines a pointer to a customized callback function. You supply the customized callback function to do a callback tailored to your application's needs.
453 @param keychainEvent The keychain event that your application wishes to be notified of. See SecKeychainEvent for a description of possible values. The type of event that can trigger your callback depends on the bit mask you passed in the eventMask parameter of the function SecKeychainAddCallback. For more information, see the discussion.
454 @param info A pointer to a structure of type SecKeychainCallbackInfo. On return, the structure contains information about the keychain event that occurred. The Keychain Manager passes this information to your callback function via the info parameter.
455 @param context A pointer to application-defined storage that your application previously passed to the function SecKeychainAddCallback. You can use this value to perform operations like track which instance of a function is operating.
456 @result A result code. See "Security Error Codes" (SecBase.h).
457 @discussion If you name your function MyKeychainEventCallback, you would declare it like this:
458 OSStatus MyKeychainEventCallback (
459 SecKeychainEvent keychainEvent,
460 SecKeychainCallbackInfo *info,
461 void *context);
462
463 To add your callback function, use the SecKeychainAddCallback function. To remove your callback function, use the SecKeychainRemoveCallback function.
464 */
465 typedef OSStatus (*SecKeychainCallback)(SecKeychainEvent keychainEvent, SecKeychainCallbackInfo *info, void *context);
466
467 /*!
468 @function SecKeychainAddCallback
469 @abstract Registers your keychain event callback function
470 @param callbackFunction A pointer to your keychain event callback function, described in SecKeychainCallback. You indicate the type of keychain events you want to receive by passing a bit mask of the desired events in the eventMask parameter.
471 @param eventMask A bit mask indicating the keychain events that your application wishes to be notified of. See SecKeychainEventMask for a description of this bit mask. The Keychain Manager tests this mask to determine the keychain events that you wish to receive, and passes these events in the keychainEvent parameter of your callback function. See SecKeychainEvent for a description of these events.
472 @param userContext A pointer to application-defined storage that will be passed to your callback function. Your application can use this to associate any particular call of SecKeychainAddCallback with any particular call of your keychain event callback function.
473 @result A result code. See "Security Error Codes" (SecBase.h).
474 */
475 OSStatus SecKeychainAddCallback(SecKeychainCallback callbackFunction, SecKeychainEventMask eventMask, void* userContext);
476
477 /*!
478 @function SecKeychainRemoveCallback
479 @abstract Unregisters your keychain event callback function. Once removed, keychain events won't be sent to the owner of the callback.
480 @param callbackFunction The callback function pointer to remove
481 @result A result code. See "Security Error Codes" (SecBase.h).
482 */
483 OSStatus SecKeychainRemoveCallback(SecKeychainCallback callbackFunction);
484
485 #pragma mark ÑÑÑÑ High Level Keychain Manager Calls ÑÑÑÑ
486 /*!
487 @function SecKeychainAddInternetPassword
488 @abstract Adds an Internet password to the specified keychain.
489 @param keychain A reference to a keychain in which to store an Internet password. Pass NULL to specify the user's default keychain.
490 @param serverNameLength The length of the buffer pointed to by serverName.
491 @param serverName A pointer to a string containing the server name associated with this password.
492 @param securityDomainLength The length of the buffer pointed to by securityDomain.
493 @param securityDomain A pointer to a string containing the security domain associated with this password, or NULL if there is no relevant security domain.
494 @param accountNameLength The length of the buffer pointed to by accountName.
495 @param accountName A pointer to a string containing the account name associated with this password.
496 @param pathLength The length of the buffer pointed to by path.
497 @param path A pointer to a string containing the path associated with this password, or NULL if there is no relevant path string.
498 @param port The TCP/IP port number. If no specific port number is associated with this item, pass 0.
499 @param protocol The protocol associated with this password. See SecProtocolType for a description of possible values.
500 @param authenticationType The authentication scheme used. See SecAuthenticationType for a description of possible values. Pass the constant kSecAuthenticationTypeDefault to specify the default authentication scheme.
501 @param passwordLength The length of the buffer pointed to by passwordData.
502 @param passwordData A pointer to a buffer containing the password data to be stored in the keychain.
503 @param itemRef On return, a reference to the new keychain item.
504 @result A result code. See "Security Error Codes" (SecBase.h).
505 @discussion The SecKeychainAddInternetPassword function adds a new Internet server password to the specified keychain. Required parameters to identify the password are serverName and accountName (you cannot pass NULL for both parameters). In addition, some protocols may require an optional securityDomain when authentication is requested. SecKeychainAddInternetPassword optionally returns a reference to the newly added item.
506 */
507 OSStatus SecKeychainAddInternetPassword(SecKeychainRef keychain, UInt32 serverNameLength, const char *serverName, UInt32 securityDomainLength, const char *securityDomain, UInt32 accountNameLength, const char *accountName, UInt32 pathLength, const char *path, UInt16 port, SecProtocolType protocol, SecAuthenticationType authenticationType, UInt32 passwordLength, const void *passwordData, SecKeychainItemRef *itemRef);
508
509 /*!
510 @function SecKeychainFindInternetPassword
511 @abstract Finds an Internet password based on the attributes passed.
512 @param keychainOrArray A reference to an array of keychains to search, a single keychain, or NULL to search the user's default keychain search list.
513 @param serverNameLength The length of the buffer pointed to by serverName.
514 @param serverName A pointer to a string containing the server name.
515 @param securityDomainLength The length of the buffer pointed to by securityDomain.
516 @param securityDomain A pointer to a string containing the security domain. This parameter is optional, as not all protocols will require it.
517 @param accountNameLength The length of the buffer pointed to by accountName.
518 @param accountName A pointer to a string containing the account name.
519 @param pathLength The length of the buffer pointed to by path.
520 @param path A pointer to a string containing the path.
521 @param port The TCP/IP port number. Pass 0 to ignore the port number.
522 @param protocol The protocol associated with this password. See SecProtocolType for a description of possible values.
523 @param authenticationType The authentication scheme used. See SecAuthenticationType for a description of possible values. Pass the constant kSecAuthenticationTypeDefault to specify the default authentication scheme.
524 @param passwordLength On return, the length of the buffer pointed to by passwordData.
525 @param passwordData On return, a pointer to a data buffer containing the password. Your application must call SecKeychainItemFreeContent(NULL, passwordData) to release this data buffer when it is no longer needed. Pass NULL if you are not interested in retrieving the password data at this time, but simply want to find the item reference.
526 @param itemRef On return, a reference to the keychain item which was found.
527 @result A result code. See "Security Error Codes" (SecBase.h).
528 @discussion The SecKeychainFindInternetPassword function finds the first Internet password item which matches the attributes you provide. Most attributes are optional; you should pass only as many as you need to narrow the search sufficiently for your application's intended use. SecKeychainFindInternetPassword optionally returns a reference to the found item.
529 */
530 OSStatus SecKeychainFindInternetPassword(CFTypeRef keychainOrArray, UInt32 serverNameLength, const char *serverName, UInt32 securityDomainLength, const char *securityDomain, UInt32 accountNameLength, const char *accountName, UInt32 pathLength, const char *path, UInt16 port, SecProtocolType protocol, SecAuthenticationType authenticationType, UInt32 *passwordLength, void **passwordData, SecKeychainItemRef *itemRef);
531
532 /*!
533 @function SecKeychainAddGenericPassword
534 @abstract Adds a generic password to the specified keychain.
535 @param keychain A reference to the keychain in which to store a generic password. Pass NULL to specify the user's default keychain.
536 @param serviceNameLength The length of the buffer pointed to by serviceName.
537 @param serviceName A pointer to a string containing the service name associated with this password.
538 @param accountNameLength The length of the buffer pointed to by accountName.
539 @param accountName A pointer to a string containing the account name associated with this password.
540 @param passwordLength The length of the buffer pointed to by passwordData.
541 @param passwordData A pointer to a buffer containing the password data to be stored in the keychain.
542 @param itemRef On return, a reference to the new keychain item.
543 @result A result code. See "Security Error Codes" (SecBase.h).
544 @discussion The SecKeychainAddGenericPassword function adds a new generic password to the default keychain. Required parameters to identify the password are serviceName and accountName, which are application-defined strings. SecKeychainAddGenericPassword optionally returns a reference to the newly added item.
545 */
546 OSStatus SecKeychainAddGenericPassword(SecKeychainRef keychain, UInt32 serviceNameLength, const char *serviceName, UInt32 accountNameLength, const char *accountName, UInt32 passwordLength, const void *passwordData, SecKeychainItemRef *itemRef);
547
548 /*!
549 @function SecKeychainFindGenericPassword
550 @abstract Find a generic password based on the attributes passed.
551 @param keychainOrArray A reference to an array of keychains to search, a single keychain, or NULL to search the user's default keychain search list.
552 @param serviceNameLength The length of the buffer pointed to by serviceName.
553 @param serviceName A pointer to a string containing the service name.
554 @param accountNameLength The length of the buffer pointed to by accountName.
555 @param accountName A pointer to a string containing the account name.
556 @param passwordLength On return, the length of the buffer pointed to by passwordData.
557 @param passwordData On return, a pointer to a data buffer containing the password. Your application must call SecKeychainItemFreeContent(NULL, passwordData) to release this data buffer when it is no longer needed. Pass NULL if you are not interested in retrieving the password data at this time, but simply want to find the item reference.
558 @param itemRef On return, a reference to the keychain item which was found.
559 @result A result code. See "Security Error Codes" (SecBase.h).
560 @discussion The SecKeychainFindGenericPassword function finds the first generic password item which matches the attributes you provide. Most attributes are optional; you should pass only as many as you need to narrow the search sufficiently for your application's intended use. SecKeychainFindGenericPassword optionally returns a reference to the found item.
561 */
562 OSStatus SecKeychainFindGenericPassword(CFTypeRef keychainOrArray, UInt32 serviceNameLength, const char *serviceName, UInt32 accountNameLength, const char *accountName, UInt32 *passwordLength, void **passwordData, SecKeychainItemRef *itemRef);
563
564 #pragma mark ÑÑÑÑ Managing User Interaction ÑÑÑÑ
565 /*!
566 @function SecKeychainSetUserInteractionAllowed
567 @abstract Turns on or off any optional user interaction
568 @param state A boolean representing the state of user interaction. You should pass TRUE to allow user interaction, and FALSE to disallow user interaction
569 @result A result code. See "Security Error Codes" (SecBase.h).
570 */
571 OSStatus SecKeychainSetUserInteractionAllowed(Boolean state);
572
573 /*!
574 @function SecKeychainGetUserInteractionAllowed
575 @abstract Retrieves the current state of user interaction.
576 @param state On return, a pointer to the current state of user interaction. If this is TRUE then user interaction is allowed, if it is FALSE, then user interaction is not allowed.
577 @result A result code. See "Security Error Codes" (SecBase.h).
578 */
579 OSStatus SecKeychainGetUserInteractionAllowed(Boolean *state);
580
581 #pragma mark ÑÑÑÑ CSSM Bridge Functions ÑÑÑÑ
582 /*!
583 @function SecKeychainGetCSPHandle
584 @abstract Returns the CSSM_CSP_HANDLE attachment for the given keychain reference. The handle is valid until the keychain reference is released.
585 @param keychain A keychain reference.
586 @param cspHandle On return, a pointer to the CSSM_CSP_HANDLE for the given keychain.
587 @result A result code. See "Security Error Codes" (SecBase.h).
588 */
589 OSStatus SecKeychainGetCSPHandle(SecKeychainRef keychain, CSSM_CSP_HANDLE *cspHandle);
590
591 /*!
592 @function SecKeychainGetDLDBHandle
593 @abstract Returns the CSSM_DL_DB_HANDLE for a given keychain reference. The handle is valid until the keychain reference is released.
594 @param keychain A keychain reference.
595 @param dldbHandle On return, a pointer to the CSSM_DL_DB_HANDLE for the given keychain.
596 @result A result code. See "Security Error Codes" (SecBase.h).
597 */
598 OSStatus SecKeychainGetDLDBHandle(SecKeychainRef keychain, CSSM_DL_DB_HANDLE *dldbHandle);
599
600 #pragma mark ÑÑÑÑ Keychain Access Management ÑÑÑÑ
601 /*!
602 @function SecKeychainCopyAccess
603 @abstract Retrieves the access for a keychain.
604 @param keychain A reference to the keychain from which to copy the access.
605 @param accessRef On return, a pointer to the access reference.
606 @result A result code. See "Security Error Codes" (SecBase.h).
607 */
608 OSStatus SecKeychainCopyAccess(SecKeychainRef keychain, SecAccessRef *access);
609
610 /*!
611 @function SecKeychainSetAccess
612 @abstract Sets the access for a keychain.
613 @param keychain A reference to the keychain for which to set the access.
614 @param accessRef An access reference.
615 @result A result code. See "Security Error Codes" (SecBase.h).
616 */
617 OSStatus SecKeychainSetAccess(SecKeychainRef keychain, SecAccessRef access);
618
619 #if defined(__cplusplus)
620 }
621 #endif
622
623 #endif /* !_SECURITY_SECKEYCHAIN_H_ */