2 * Copyright (c) 2000-2010 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 @header SecImportExport
26 contains import/export functionality for keys and certificates.
28 #ifndef _SECURITY_SEC_IMPORT_EXPORT_H_
29 #define _SECURITY_SEC_IMPORT_EXPORT_H_
31 #include <Security/cssmtype.h>
32 #include <Security/SecAccess.h>
33 #include <Security/SecKeychain.h>
34 #include <CoreFoundation/CoreFoundation.h>
42 * Supported import/export Formats
47 * When importing: unknown format
48 * When exporting: default format for item
50 kSecFormatUnknown
= 0,
53 * Public and Private Key formats.
54 * Default for export is kSecFormatOpenSSL.
56 kSecFormatOpenSSL
, /* a.k.a. X509 for public keys */
57 kSecFormatSSH
, /* OpenSSH v.1 */
60 /* Symmetric Key Formats */
61 kSecFormatRawKey
, /* raw unformatted key bits; default */
63 /* Formats for wrapped symmetric and private keys */
64 kSecFormatWrappedPKCS8
,
65 kSecFormatWrappedOpenSSL
, /* traditional openssl */
66 kSecFormatWrappedSSH
, /* OpenSSH v.1 */
69 /* Formats for certificates */
70 kSecFormatX509Cert
, /* DER encoded; default */
73 kSecFormatPEMSequence
, /* sequence of certs and/or keys, implies PEM
74 * armour. Default format for multiple items */
75 kSecFormatPKCS7
, /* sequence of certs */
76 kSecFormatPKCS12
, /* set of certs and private keys */
77 kSecFormatNetscapeCertSequence
, /* sequence of certs, form netscape-cert-sequence */
79 /* Added in Mac OS X 10.5 */
80 kSecFormatSSHv2
/* OpenSSH v.2. Note that OpenSSH v2 private keys
81 * are in format kSecFormatOpenSSL or
82 * kSecFormatWrappedOpenSSL. */
84 typedef uint32_t SecExternalFormat
;
87 * Indication of basic item type when importing.
90 kSecItemTypeUnknown
, /* caller doesn't know what this is */
91 kSecItemTypePrivateKey
,
92 kSecItemTypePublicKey
,
93 kSecItemTypeSessionKey
,
94 kSecItemTypeCertificate
,
95 kSecItemTypeAggregate
/* PKCS7, PKCS12, kSecFormatPEMSequence, etc. */
97 typedef uint32_t SecExternalItemType
;
100 * Flags passed to SecKeychainItemExport() and SecKeychainItemImport().
104 kSecItemPemArmour
= 0x00000001, /* exported blob is PEM formatted */
106 typedef uint32_t SecItemImportExportFlags
;
109 * SecKeyRef-specific flags, specified in SecKeyImportExportParameters.flags
114 * When true, prevents the importing of more than one private key
115 * in a given SecKeychainItemImport().
117 kSecKeyImportOnlyOne
= 0x00000001,
120 * When true, passphrase for import/export is obtained by user prompt
121 * instead of by caller-supplied data (SecKeyImportExportParameters.passphrase).
122 * This is the preferred method for obtaining a user-supplied passphrase
123 * as it avoids having the cleartext passphrase appear in the app's
124 * address space at any time.
126 kSecKeySecurePassphrase
= 0x00000002,
129 * When true, imported private keys will have no Access Control List
130 * (ACL) attached to them. In the absence of both this bit and the accessRef
131 * field in SecKeyImportExportParameters (see below), imported private
132 * keys are given a default ACL.
134 kSecKeyNoAccessControl
= 0x00000004
136 typedef uint32_t SecKeyImportExportFlags
;
139 * Version of a SecKeyImportExportParameters.
141 #define SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION 0
144 * Parameters specific to SecKeyRefs.
148 /* for import and export */
149 uint32_t version
; /* SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION */
150 SecKeyImportExportFlags flags
; /* SecKeyImportExportFlags bits */
151 CFTypeRef passphrase
; /* kSecFormatPKCS12, kSecFormatWrapped*
152 * formats only. Legal types are
153 * CFStringRef and CFDataRef. */
154 CFStringRef alertTitle
; /* title of secure passphrase alert panel */
155 CFStringRef alertPrompt
; /* prompt in secure passphrase alert panel */
157 /* for import only */
158 SecAccessRef accessRef
; /* specifies the initial ACL of imported
160 CSSM_KEYUSE keyUsage
; /* CSSM_KEYUSE_DECRYPT, CSSM_KEYUSE_SIGN,
162 CSSM_KEYATTR_FLAGS keyAttributes
; /* CSSM_KEYATTR_PERMANENT, etc. */
163 } SecKeyImportExportParameters
;
168 /* for import and export */
169 uint32_t version
; /* SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION */
170 SecKeyImportExportFlags flags
; /* SecKeyImportExportFlags bits */
171 CFTypeRef passphrase
; /* kSecFormatPKCS12, kSecFormatWrapped*
172 * formats only. Legal types are
173 * CFStringRef and CFDataRef. */
174 CFStringRef alertTitle
; /* title of s ecure passphrase alert panel */
175 CFStringRef alertPrompt
; /* prompt in secure passphrase alert panel */
177 /* for import only */
178 SecAccessRef accessRef
; /* specifies the initial ACL of imported
180 CFArrayRef keyUsage
; /* An Array containing item from SecItem.h i.e
181 kSecAttrCanEncrypt;, kSecAttrCanDecrypt, kSecAttrCanDerive, etc
184 CFArrayRef keyAttributes
; /* CSSM_KEYATTR_PERMANENT, etc. */
185 } SecItemImportExportKeyParameters
;
188 * SecKeychainItemExport()
190 * This function takes one or more SecKeychainItemRefs and creates an
191 * external representation of the item(s) in the form of a CFDataRef.
192 * Caller specifies the format of the external representation via a
193 * SecExternalFormat enum. Caller may specify kSecFormatUnknown for
194 * the format, in which case a the default format for the item
195 * being exported is used (as described in the SecExternalFormat enums).
196 * PEM armouring is optional and is specified by the kSecItemPemArmour
197 * flag in importFlags.
199 * If exactly one item is to be exported, the keychainItemOrArray argument
200 * can be a SecKeychainItem. Otherwise this argument is a CFArrayRef
201 * containing a number of SecKeychainItems.
203 * The following SecKeychainItems may be exported:
210 * Key-related SecKeyImportExportParameters fields
211 * -----------------------------------------------
213 * When exporting SecKeyRefs in one of the wrapped formats
214 * (kSecFormatWrappedOpenSSL, kSecFormatWrappedSSH,
215 * kSecFormatWrappedPKCS8), or in PKCS12 format, caller must
216 * either explicitly specify the passphrase field or set
217 * the kSecKeySecurePassphrase bit in SecKeyImportExportFlags.
219 * If kSecKeySecurePassphrase is selected, caller can optionally
220 * specify strings for the passphrase panel's title bar and for
221 * the prompt which appears in the panel via the alertTitle and
222 * alertPrompt fields in SecKeyImportExportParameters.
224 * If an explicit passphrase is specified, note that PKCS12
225 * explicitly requires that passphrases are in Unicode format;
226 * passing in a CFStringRef as the passphrase is the safest way
227 * to ensure that this requirement is met (and that the result
228 * will be compatible with other implementations). If a CFDataRef
229 * is supplied as the passphrase for a PKCS12 export operation,
230 * the referent data is assumed to be in UTF8 form and will be
231 * converted as appropriate.
233 * If no key items are being exported, the keyParams argument may be NULL.
234 * @discussion This API has been deprecated. Please us the SecItemExport API instead.
236 OSStatus
SecKeychainItemExport(
237 CFTypeRef keychainItemOrArray
,
238 SecExternalFormat outputFormat
,
239 SecItemImportExportFlags flags
, /* kSecItemPemArmor, etc. */
240 const SecKeyImportExportParameters
*keyParams
, /* optional */
241 CFDataRef
*exportedData
) /* external representation returned here */
242 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
;
247 * This function takes one or more SecItemRefs and creates an
248 * external representation of the item(s) in the form of a CFDataRef.
249 * Caller specifies the format of the external representation via a
250 * SecExternalFormat enum. Caller may specify kSecFormatUnknown for
251 * the format, in which case a the default format for the item
252 * being exported is used (as described in the SecExternalFormat enums).
253 * PEM armouring is optional and is specified by the kSecItemPemArmour
254 * flag in importFlags.
256 * If exactly one item is to be exported, the keychainItemOrArray argument
257 * can be a SecKeychainItem. Otherwise this argument is a CFArrayRef
258 * containing a number of SecKeychainItems.
260 * The following SecKeychainItems may be exported:
267 * Key-related SecItemExport fields
268 * -----------------------------------------------
270 * When exporting SecKeyRefs in one of the wrapped formats
271 * (kSecFormatWrappedOpenSSL, kSecFormatWrappedSSH,
272 * kSecFormatWrappedPKCS8), or in PKCS12 format, caller must
273 * either explicitly specify the passphrase field or set
274 * the kSecKeySecurePassphrase bit in SecKeyImportExportFlags.
276 * If kSecKeySecurePassphrase is selected, caller can optionally
277 * specify strings for the passphrase panel's title bar and for
278 * the prompt which appears in the panel via the alertTitle and
279 * alertPrompt fields in SecItemImportExportKeyParameters.
281 * If an explicit passphrase is specified, note that PKCS12
282 * explicitly requires that passphrases are in Unicode format;
283 * passing in a CFStringRef as the passphrase is the safest way
284 * to ensure that this requirement is met (and that the result
285 * will be compatible with other implementations). If a CFDataRef
286 * is supplied as the passphrase for a PKCS12 export operation,
287 * the referent data is assumed to be in UTF8 form and will be
288 * converted as appropriate.
290 * If no key items are being exported, the keyParams argument may be NULL.
293 OSStatus
SecItemExport(
294 CFTypeRef secItemOrArray
,
295 SecExternalFormat outputFormat
,
296 SecItemImportExportFlags flags
, /* kSecItemPemArmor, etc. */
297 const SecItemImportExportKeyParameters
*keyParams
, /* optional */
298 CFDataRef
*exportedData
) /* external representation returned here */
299 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_NA
);
301 * SecKeychainItemImport()
303 * This function takes a CFDataRef containing the external representation
304 * of one or more objects and creates SecKeychainItems corresponding to
305 * those objects and optionally imports those SecKeychainItems into a
306 * specified keychain. The format of the incoming representation is
307 * specified by one or more of the following:
309 * -- A SecExternalFormat. This optional in/out argument is used when
310 * the caller knows exactly what format the external representation
311 * is in. It's also used to return to the caller the format which the
312 * function actually determines the external representation to be in.
313 * A value of kSecFormatUnknown is specified on entry when the caller
314 * wishes to know the inferred format on return.
316 * -- A SecExternalItemType - optional, in/out. Used to specify what kind
317 * of item is in the incoming representation, if known by the caller.
318 * It's also used to return to the caller the item type which the
319 * function actually determines the external representation to contain.
320 * A value of kSecItemTypeUnknown is specified on entry when the caller
321 * wishes to know the inferred item type on return.
323 * -- fileNameOrExtension, a CFStringRef. This optional argument contains
324 * the name of the file from which the external representation was
325 * obtained; it can also be simply an extension like CFSTR(".p7r").
326 * This is a convenience for apps like KeychainAccess which can import a
327 * number of different formats.
329 * The SecKeychainItemImport() call does its best to figure out what is
330 * in an incoming external item given the info provided by the above three
331 * arguments. In most cases, SecKeychainItemImport() can even figure out
332 * what's in an external item if none of these are specified, but it would
333 * be unwise for an application to count on that ability.
335 * PEM formatting is determined internally via inspection of the incoming
336 * data, so the kSecItemPemArmuor in the flags field is ignored.
338 * Zero, one, or both of the following occurs upon successful completion
341 * -- The imported item(s) is (are) imported to the specified importKeychain.
342 * If importKeychain is NULL, this step does not occur.
344 * -- The imported item(s) is (are) returned to the caller via the
345 * CRArrayRef *outItems argument. If outItems is NULL, this step
346 * does not occur. If outItems is NON-NULL, then *outItems will be
347 * a CFArrayRef containing a number of SecKeychainItems upon return.
348 * Caller must CFRelease the result.
350 * The possible types of returned SecKeychainItems are:
356 * Note that when importing a PKCS12 blob, typically one SecIdentityRef
357 * and zero or more additional SecCertificateRefs are returned in
358 * outItems. No SecKeyRefs will appear there unless a key
359 * is found in the incoming blob with does not have a matching
362 * A typical case in which an app specifies the outItems
363 * argument and a NULL for importKeychain is when the app wishes to
364 * perform some user interaction, perhaps on a per-item basis, before
365 * committing to actually import the item(s). In this case, if the app
366 * does wish to proceed with the import, the standard import calls
367 * (SecCertificateAddToKeychain(), SecKeyAddToKeychain (implementation
368 * TBD)) would be used.
370 * Passing in NULL for both outItems and importKeychain
371 * is a perfectly acceptable way of using this function to determine,
372 * in a non-intrusive way, what is inside a given data blob. No effect
373 * other than returning inputFormat and/or itemType occurs in this
377 * Key-related SecKeyImportExportParameters fields
378 * -----------------------------------------------
380 * If importKeychain is NULL, the kSecKeyImportOnlyOne bit in the flags
381 * argument is ignored. Otherwise, if the kSecKeyImportOnlyOne bit is set, and
382 * there is more than one key in the incoming external representation, no
383 * items will be imported to the specified keychain and errSecMultipleKeys will
386 * The accessRef field allows the caller to specify the initial SecAccessRef
387 * for imported private keys. If more than one private key is being imported,
388 * all private keys get the same initial SecAccessRef. If this field is NULL
389 * when private keys are being imported, then the ACL attached to imported
390 * private keys depends on the kSecKeyNoAccessControl bit in the specified
391 * keyParams->flags. If this bit is 0, or keyParams is NULL, the default ACL
392 * will be used. If this bit is 1, no ACL will be attached to imported
395 * keyUsage and keyAttributes specify the low-level usage and attribute flags
396 * of imported keys. Each is a word of bits. The default value for keyUsage
397 * (used when keyParams is NULL or if keyParams->keyUsage is zero) is
398 * CSSM_KEYUSE_ANY. The default value for keyAttributes defaults is
399 * CSSM_KEYATTR_SENSITIVE | CSSM_KEYATTR_EXTRACTABLE; the CSSM_KEYATTR_PERMANENT
400 * bit is also added to the default if a non-NULL importKeychain is provided.
402 * The following are valid bits in keyAttributes:
404 * CSSM_KEYATTR_PERMANENT
405 * CSSM_KEYATTR_SENSITIVE
406 * CSSM_KEYATTR_EXTRACTABLE
408 * If the CSSM_KEYATTR_PERMANENT is set then the importKeychain argument must
409 * be valid or errSecInvalidKeychain will be returned if in fact any keys are found
410 * in the external representation.
412 * Note that if the caller does not set the CSSM_KEYATTR_EXTRACTABLE, this key
413 * will never be able to be extracted from the keychain in any form, not even
414 * in wrapped form. The CSSM_KEYATTR_SENSITIVE indicates that the key can only
415 * be extracted in wrapped form.
417 * The CSSM_KEYATTR_RETURN_xxx bits are always forced to
418 * CSSM_KEYATTR_RETURN_REF regardless of the specified keyAttributes
421 * When importing SecKeyRefs in one of the wrapped formats
422 * (kSecFormatWrappedOpenSSL, kSecFormatWrappedSSH,
423 * kSecFormatWrappedPKCS8), or in PKCS12 format, caller must
424 * either explicitly specify the passphrase field or set
425 * the kSecKeySecurePassphrase bit in SecKeyImportExportFlags.
427 * If kSecKeySecurePassphrase is selected, caller can optionally
428 * specify strings for the passphrase panel's title bar and for
429 * the prompt which appears in the panel via the alertTitle and
430 * alertPrompt fields in SecKeyImportExportParameters.
432 * If an explicit passphrase is specified, note that PKCS12
433 * explicitly requires that passphrases are in Unicode format;
434 * passing in a CFStringRef as the passphrase is the safest way
435 * to ensure that this requirement is met (and that the result
436 * will be compatible with other implementations). If a CFDataRef
437 * is supplied as the passphrase for a PKCS12 export operation,
438 * the referent data is assumed to be in UTF8 form and will be
439 * converted as appropriate.
441 * If no key items are being imported, the keyParams argument may be NULL.
443 * The SecItemImportExportFlags argument is currently unused; caller should pass
446 * @discussion This API has been deprecated. Please use the SecItemImport API instead.
448 OSStatus
SecKeychainItemImport(
449 CFDataRef importedData
,
450 CFStringRef fileNameOrExtension
, /* optional */
451 SecExternalFormat
*inputFormat
, /* optional, IN/OUT */
452 SecExternalItemType
*itemType
, /* optional, IN/OUT */
453 SecItemImportExportFlags flags
,
454 const SecKeyImportExportParameters
*keyParams
, /* optional */
455 SecKeychainRef importKeychain
, /* optional */
456 CFArrayRef
*outItems
) /* optional */
457 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
;
462 * This function takes a CFDataRef containing the external representation
463 * of one or more objects and creates SecKeychainItems corresponding to
464 * those objects and optionally imports those SecKeychainItems into a
465 * specified keychain. The format of the incoming representation is
466 * specified by one or more of the following:
468 * -- A SecExternalFormat. This optional in/out argument is used when
469 * the caller knows exactly what format the external representation
470 * is in. It's also used to return to the caller the format which the
471 * function actually determines the external representation to be in.
472 * A value of kSecFormatUnknown is specified on entry when the caller
473 * wishes to know the inferred format on return.
475 * -- A SecExternalItemType - optional, in/out. Used to specify what kind
476 * of item is in the incoming representation, if known by the caller.
477 * It's also used to return to the caller the item type which the
478 * function actually determines the external representation to contain.
479 * A value of kSecItemTypeUnknown is specified on entry when the caller
480 * wishes to know the inferred item type on return.
482 * -- fileNameOrExtension, a CFStringRef. This optional argument contains
483 * the name of the file from which the external representation was
484 * obtained; it can also be simply an extension like CFSTR(".p7r").
485 * This is a convenience for apps like KeychainAccess which can import a
486 * number of different formats.
488 * The SecItemImport() call does its best to figure out what is
489 * in an incoming external item given the info provided by the above three
490 * arguments. In most cases, SecItemImport() can even figure out
491 * what's in an external item if none of these are specified, but it would
492 * be unwise for an application to count on that ability.
494 * PEM formatting is determined internally via inspection of the incoming
495 * data, so the kSecItemPemArmuor in the flags field is ignored.
497 * Zero, one, or both of the following occurs upon successful completion
500 * -- The imported item(s) is (are) imported to the specified importKeychain.
501 * If importKeychain is NULL, this step does not occur.
503 * -- The imported item(s) is (are) returned to the caller via the
504 * CRArrayRef *outItems argument. If outItems is NULL, this step
505 * does not occur. If outItems is NON-NULL, then *outItems will be
506 * a CFArrayRef containing a number of SecKeychainItems upon return.
507 * Caller must CFRelease the result.
509 * The possible types of returned SecKeychainItems are:
515 * Note that when importing a PKCS12 blob, typically one SecIdentityRef
516 * and zero or more additional SecCertificateRefs are returned in
517 * outItems. No SecKeyRefs will appear there unless a key
518 * is found in the incoming blob with does not have a matching
521 * A typical case in which an app specifies the outItems
522 * argument and a NULL for importKeychain is when the app wishes to
523 * perform some user interaction, perhaps on a per-item basis, before
524 * committing to actually import the item(s). In this case, if the app
525 * does wish to proceed with the import, the standard import calls
526 * (SecCertificateAddToKeychain(), SecKeyAddToKeychain (implementation
527 * TBD)) would be used.
529 * Passing in NULL for both outItems and importKeychain
530 * is a perfectly acceptable way of using this function to determine,
531 * in a non-intrusive way, what is inside a given data blob. No effect
532 * other than returning inputFormat and/or itemType occurs in this
536 * Key-related SecItemImportExportKeyParameters fields
537 * -----------------------------------------------
539 * If importKeychain is NULL, the kSecKeyImportOnlyOne bit in the flags
540 * argument is ignored. Otherwise, if the kSecKeyImportOnlyOne bit is set, and
541 * there is more than one key in the incoming external representation, no
542 * items will be imported to the specified keychain and errSecMultipleKeys will
545 * The accessRef field allows the caller to specify the initial SecAccessRef
546 * for imported private keys. If more than one private key is being imported,
547 * all private keys get the same initial SecAccessRef. If this field is NULL
548 * when private keys are being imported, then the ACL attached to imported
549 * private keys depends on the kSecKeyNoAccessControl bit in the specified
550 * keyParams->flags. If this bit is 0, or keyParams is NULL, the default ACL
551 * will be used. If this bit is 1, no ACL will be attached to imported
554 * keyUsage and keyAttributes specify the low-level usage and attribute flags
555 * of imported keys. Each is a word of bits. The default value for keyUsage
556 * (used when keyParams is NULL or if keyParams->keyUsage is zero) is
557 * CSSM_KEYUSE_ANY. The default value for keyAttributes defaults is
558 * CSSM_KEYATTR_SENSITIVE | CSSM_KEYATTR_EXTRACTABLE; the CSSM_KEYATTR_PERMANENT
559 * bit is also added to the default if a non-NULL importKeychain is provided.
561 * The following are valid bits in keyAttributes:
563 * CSSM_KEYATTR_PERMANENT
564 * CSSM_KEYATTR_SENSITIVE
565 * CSSM_KEYATTR_EXTRACTABLE
567 * If the CSSM_KEYATTR_PERMANENT is set then the importKeychain argument must
568 * be valid or errSecInvalidKeychain will be returned if in fact any keys are found
569 * in the external representation.
571 * Note that if the caller does not set the CSSM_KEYATTR_EXTRACTABLE, this key
572 * will never be able to be extracted from the keychain in any form, not even
573 * in wrapped form. The CSSM_KEYATTR_SENSITIVE indicates that the key can only
574 * be extracted in wrapped form.
576 * The CSSM_KEYATTR_RETURN_xxx bits are always forced to
577 * CSSM_KEYATTR_RETURN_REF regardless of the specified keyAttributes
580 * When importing SecKeyRefs in one of the wrapped formats
581 * (kSecFormatWrappedOpenSSL, kSecFormatWrappedSSH,
582 * kSecFormatWrappedPKCS8), or in PKCS12 format, caller must
583 * either explicitly specify the passphrase field or set
584 * the kSecKeySecurePassphrase bit in SecKeyImportExportFlags.
586 * If kSecKeySecurePassphrase is selected, caller can optionally
587 * specify strings for the passphrase panel's title bar and for
588 * the prompt which appears in the panel via the alertTitle and
589 * alertPrompt fields in SecItemImportExportKeyParameters.
591 * If an explicit passphrase is specified, note that PKCS12
592 * explicitly requires that passphrases are in Unicode format;
593 * passing in a CFStringRef as the passphrase is the safest way
594 * to ensure that this requirement is met (and that the result
595 * will be compatible with other implementations). If a CFDataRef
596 * is supplied as the passphrase for a PKCS12 export operation,
597 * the referent data is assumed to be in UTF8 form and will be
598 * converted as appropriate.
600 * If no key items are being imported, the keyParams argument may be NULL.
602 * The SecItemImportExportFlags argument is currently unused; caller should pass
606 OSStatus
SecItemImport(
607 CFDataRef importedData
,
608 CFStringRef fileNameOrExtension
, /* optional */
609 SecExternalFormat
*inputFormat
, /* optional, IN/OUT */
610 SecExternalItemType
*itemType
, /* optional, IN/OUT */
611 SecItemImportExportFlags flags
,
612 const SecItemImportExportKeyParameters
*keyParams
, /* optional */
613 SecKeychainRef importKeychain
, /* optional */
614 CFArrayRef
*outItems
) /* optional */
615 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_NA
);
617 @enum Import/Export options
618 @discussion Predefined key constants used when passing dictionary-based arguments to import/export functions.
619 @constant kSecImportExportPassphrase Specifies a passphrase represented by a CFStringRef to be used when exporting to (or importing from) PKCS#12 format.
620 @constant kSecImportExportKeychain Specifies a keychain represented by a SecKeychainRef to be used as the target when importing from PKCS#12 format.
621 @constant kSecImportExportAccess Specifies an access represented by a SecAccessRef for the initial access (ACL) of a key imported from PKCS#12 format.
623 extern CFStringRef kSecImportExportPassphrase
;
624 extern CFStringRef kSecImportExportKeychain
;
625 extern CFStringRef kSecImportExportAccess
;
628 @enum Import/Export item description
629 @discussion Predefined key constants used by functions which return a CFArray with a CFDictionary per item.
630 @constant kSecImportItemLabel A CFStringRef representing the item label. This implementation specific identifier cannot be expected to have any format.
631 @constant kSecImportItemKeyID A CFDataRef representing the key id. Typically this is the SHA-1 digest of the public key.
632 @constant kSecImportItemIdentity A SecIdentityRef representing the identity.
633 @constant kSecImportItemTrust A SecTrustRef set up with all relevant certificates. Not guaranteed to succesfully evaluate.
634 @constant kSecImportItemCertChain A CFArrayRef holding all relevant certificates for this item's identity.
636 extern CFStringRef kSecImportItemLabel
;
637 extern CFStringRef kSecImportItemKeyID
;
638 extern CFStringRef kSecImportItemTrust
;
639 extern CFStringRef kSecImportItemCertChain
;
640 extern CFStringRef kSecImportItemIdentity
;
643 @function SecPKCS12Import
644 @abstract Imports the contents of a PKCS12 formatted blob.
645 @param pkcs12_data The PKCS12 data to be imported.
646 @param options A dictionary containing import options. A kSecImportExportPassphrase entry is required at minimum. Only password-based PKCS12 blobs are currently supported.
647 @param items On return, an array containing a dictionary for every item extracted. Use kSecImportItem constants to access specific elements of these dictionaries. Your code must CFRelease the array when it is no longer needed.
648 @result errSecSuccess in case of success. errSecDecode means either the blob can't be read or it is malformed.
649 errSecAuthFailed means an incorrect password was supplied, or data in the container is damaged.
651 OSStatus
SecPKCS12Import(CFDataRef pkcs12_data
, CFDictionaryRef options
, CFArrayRef
*items
);
657 #endif /* _SECURITY_SEC_IMPORT_EXPORT_H_ */