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