]> git.saurik.com Git - apple/security.git/blob - trust/headers/SecCertificate.h
Security-59754.41.1.tar.gz
[apple/security.git] / trust / headers / SecCertificate.h
1 /*
2 * Copyright (c) 2002-2020 Apple 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 SecCertificate
26 The functions provided in SecCertificate.h implement and manage a
27 particular type of keychain item that represents a X.509 public key
28 certificate. You can store a certificate in a keychain, but a
29 certificate can also be a transient object.
30
31 You can use a certificate as a keychain item in most functions.
32 */
33
34 #ifndef _SECURITY_SECCERTIFICATE_H_
35 #define _SECURITY_SECCERTIFICATE_H_
36
37 #include <CoreFoundation/CFBase.h>
38 #include <CoreFoundation/CFArray.h>
39 #include <CoreFoundation/CFData.h>
40 #include <CoreFoundation/CFDate.h>
41 #include <CoreFoundation/CFError.h>
42 #include <Availability.h>
43 #include <AvailabilityMacros.h>
44
45 #include <Security/SecBase.h>
46
47 #if SEC_OS_OSX
48 #define _SECURITY_VERSION_GREATER_THAN_57610_
49
50 #include <Security/cssmtype.h>
51 #include <Security/x509defs.h>
52 #endif // SEC_OS_OSX
53
54 __BEGIN_DECLS
55
56 CF_ASSUME_NONNULL_BEGIN
57 CF_IMPLICIT_BRIDGING_ENABLED
58
59 /*!
60 @function SecCertificateGetTypeID
61 @abstract Returns the type identifier of SecCertificate instances.
62 @result The CFTypeID of SecCertificate instances.
63 */
64 CFTypeID SecCertificateGetTypeID(void)
65 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
66
67 /*!
68 @function SecCertificateCreateWithData
69 @abstract Create a certificate given it's DER representation as a CFData.
70 @param allocator CFAllocator to allocate the certificate with.
71 @param data DER encoded X.509 certificate.
72 @result Return NULL if the passed-in data is not a valid DER-encoded
73 X.509 certificate, return a SecCertificateRef otherwise.
74 */
75 __nullable
76 SecCertificateRef SecCertificateCreateWithData(CFAllocatorRef __nullable allocator, CFDataRef data)
77 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
78
79 /*!
80 @function SecCertificateCopyData
81 @abstract Return the DER representation of an X.509 certificate.
82 @param certificate SecCertificate object created with
83 SecCertificateCreateWithData().
84 @result DER encoded X.509 certificate.
85 */
86 CFDataRef SecCertificateCopyData(SecCertificateRef certificate)
87 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
88
89 /*!
90 @function SecCertificateCopySubjectSummary
91 @abstract Return a simple string which hopefully represents a human
92 understandable summary.
93 @param certificate A reference to the certificate from which to derive
94 the subject summary string.
95 @discussion All the data in this string comes from the certificate itself
96 and thus it's in whatever language the certificate itself is in.
97 @result A CFStringRef which the caller should CFRelease() once it's no
98 longer needed.
99 */
100 __nullable
101 CFStringRef SecCertificateCopySubjectSummary(SecCertificateRef certificate)
102 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
103
104 /*!
105 @function SecCertificateCopyCommonName
106 @abstract Retrieves the common name of the subject of a given certificate.
107 @param certificate A reference to the certificate from which to retrieve the common name.
108 @param commonName On return, a reference to the common name. Your code must release this reference by calling the CFRelease function.
109 @result A result code. See "Security Error Codes" (SecBase.h).
110 @discussion All the data in this string comes from the certificate itself, and thus it's in whatever language the certificate itself is in.
111 Note that the certificate's common name field may not be present, or may be inadequate to describe the certificate; for display purposes,
112 you should consider using SecCertificateCopySubjectSummary instead of this function.
113 */
114 OSStatus SecCertificateCopyCommonName(SecCertificateRef certificate, CFStringRef * __nonnull CF_RETURNS_RETAINED commonName)
115 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_10_3);
116
117 /*!
118 @function SecCertificateCopyEmailAddresses
119 @abstract Returns an array of zero or more email addresses for the subject of a given certificate.
120 @param certificate A reference to the certificate from which to retrieve the email addresses.
121 @param emailAddresses On return, an array of zero or more CFStringRef elements corresponding to each email address found.
122 Your code must release this array reference by calling the CFRelease function.
123 @result A result code. See "Security Error Codes" (SecBase.h).
124 */
125 OSStatus SecCertificateCopyEmailAddresses(SecCertificateRef certificate, CFArrayRef * __nonnull CF_RETURNS_RETAINED emailAddresses)
126 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_10_3);
127
128 /*!
129 @function SecCertificateCopyNormalizedIssuerSequence
130 @abstract Return the certificate's normalized issuer
131 @param certificate The certificate from which to get values
132 @discussion The issuer is a sequence in the format used by SecItemCopyMatching. The content returned is a DER-encoded X.509 distinguished name. For a display version of the issuer, call SecCertificateCopyValues. The caller must CFRelease the value returned.
133 */
134 __nullable
135 CFDataRef SecCertificateCopyNormalizedIssuerSequence(SecCertificateRef certificate)
136 __OSX_AVAILABLE_STARTING(__MAC_10_12_4, __IPHONE_10_3);
137
138 /*!
139 @function SecCertificateCopyNormalizedSubjectSequence
140 @abstract Return the certificate's normalized subject
141 @param certificate The certificate from which to get values
142 @discussion The subject is a sequence in the format used by SecItemCopyMatching. The content returned is a DER-encoded X.509 distinguished name. For a display version of the subject, call SecCertificateCopyValues. The caller must CFRelease the value returned.
143 */
144 __nullable
145 CFDataRef SecCertificateCopyNormalizedSubjectSequence(SecCertificateRef certificate)
146 __OSX_AVAILABLE_STARTING(__MAC_10_12_4, __IPHONE_10_3);
147
148 /*!
149 @function SecCertificateCopyKey
150 @abstract Retrieves the public key for a given certificate.
151 @param certificate A reference to the certificate from which to retrieve the public key.
152 @result A reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function. If the public key has an encoding issue or uses an unsupported algorithm, the returned reference will be null.
153 @discussion RSA and ECDSA public keys are supported. All other public key algorithms are unsupported.
154 */
155 __nullable CF_RETURNS_RETAINED
156 SecKeyRef SecCertificateCopyKey(SecCertificateRef certificate)
157 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0), bridgeos(3.0));
158
159 #if TARGET_OS_OSX && TARGET_CPU_ARM64
160 #define SEC_SUFFIX_LEGACYMAC(symbol) __asm("_" __STRING(symbol) "$LEGACYMAC")
161 #else
162 #define SEC_SUFFIX_LEGACYMAC(symbol) /**/
163 #endif
164
165 #if TARGET_OS_IPHONE
166 /*!
167 @function SecCertificateCopyPublicKey
168 @abstract Retrieves the public key for a given certificate.
169 @param certificate A reference to the certificate from which to retrieve the public key.
170 @result A reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function.
171 @discussion NOTE: Deprecated in iOS 12.0; use SecCertificateCopyKey instead for cross-platform availability.
172 */
173 __nullable
174 SecKeyRef SecCertificateCopyPublicKey(SecCertificateRef certificate)
175 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopyKey", ios(10.3, 12.0)) API_UNAVAILABLE(macos, macCatalyst);
176 #endif
177
178 #if TARGET_OS_OSX
179 /*!
180 @function SecCertificateCopyPublicKey
181 @abstract Retrieves the public key for a given certificate.
182 @param certificate A reference to the certificate from which to retrieve the public key.
183 @param key On return, a reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function.
184 @result A result code. See "Security Error Codes" (SecBase.h).
185 @discussion NOTE: Deprecated in macOS 10.14; use SecCertificateCopyKey instead for cross-platform availability.
186 */
187 OSStatus SecCertificateCopyPublicKey(SecCertificateRef certificate, SecKeyRef * __nonnull CF_RETURNS_RETAINED key)
188 SEC_SUFFIX_LEGACYMAC(SecCertificateCopyPublicKey)
189 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopyKey", macos(10.3, 10.14)) API_UNAVAILABLE(ios, tvos, watchos, bridgeos, macCatalyst);
190 #endif
191
192 /*!
193 @function SecCertificateCopySerialNumberData
194 @abstract Return the certificate's serial number.
195 @param certificate The certificate from which to get values.
196 @param error An optional pointer to a CFErrorRef which will be set on return from the function if an error occurred. If not NULL, the caller is responsible for releasing the CFErrorRef.
197 @discussion Return the content of a DER-encoded integer (without the tag and length fields) for this certificate's serial number. The caller must CFRelease the value returned.
198 */
199 __nullable
200 CFDataRef SecCertificateCopySerialNumberData(SecCertificateRef certificate, CFErrorRef *error)
201 API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0), bridgeos(3.0));
202
203 #if TARGET_OS_IPHONE
204 /*!
205 @function SecCertificateCopySerialNumber
206 @abstract Return the certificate's serial number.
207 @param certificate The certificate from which to get values.
208 @discussion Return the content of a DER-encoded integer (without the tag and length fields) for this certificate's serial number. The caller must CFRelease the value returned. NOTE: Deprecated in iOS 11.0; use SecCertificateCopySerialNumberData instead for cross-platform availability.
209 */
210 __nullable
211 CFDataRef SecCertificateCopySerialNumber(SecCertificateRef certificate)
212 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopySerialNumberData", ios(10.3, 11.0)) API_UNAVAILABLE(macos, macCatalyst);
213 #endif
214
215 #if TARGET_OS_OSX
216 /*!
217 @function SecCertificateCopySerialNumber
218 @abstract Return the certificate's serial number.
219 @param certificate The certificate from which to get values.
220 @param error An optional pointer to a CFErrorRef which will be set on return from the function if an error occurred. If not NULL, the caller is responsible for releasing the CFErrorRef.
221 @discussion Return the content of a DER-encoded integer (without the tag and length fields) for this certificate's serial number. The caller must CFRelease the value returned. NOTE: Deprecated in macOS 10.13; use SecCertificateCopySerialNumberData instead for cross-platform availability.
222 */
223 __nullable
224 CFDataRef SecCertificateCopySerialNumber(SecCertificateRef certificate, CFErrorRef *error)
225 SEC_SUFFIX_LEGACYMAC(SecCertificateCopySerialNumber)
226 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopySerialNumberData", macos(10.7, 10.13)) API_UNAVAILABLE(ios, tvos, watchos, bridgeos, macCatalyst);
227 #endif
228
229 /*
230 * Legacy functions (OS X only)
231 */
232 #if SEC_OS_OSX
233 /*!
234 @enum CertificateItemAttributes
235 @abstract Indicates the type of a certificate item attribute.
236 @constant kSecSubjectItemAttr Indicates a DER-encoded subject distinguished name.
237 @constant kSecIssuerItemAttr Indicates a DER-encoded issuer distinguished name.
238 @constant kSecSerialNumberItemAttr Indicates a DER-encoded certificate serial number (without the tag and length).
239 @constant kSecPublicKeyHashItemAttr Indicates a public key hash.
240 @constant kSecSubjectKeyIdentifierItemAttr Indicates a subject key identifier.
241 @constant kSecCertTypeItemAttr Indicates a certificate type.
242 @constant kSecCertEncodingItemAttr Indicates a certificate encoding.
243 */
244 enum
245 {
246 kSecSubjectItemAttr = 'subj',
247 kSecIssuerItemAttr = 'issu',
248 kSecSerialNumberItemAttr = 'snbr',
249 kSecPublicKeyHashItemAttr = 'hpky',
250 kSecSubjectKeyIdentifierItemAttr = 'skid',
251 kSecCertTypeItemAttr = 'ctyp',
252 kSecCertEncodingItemAttr = 'cenc'
253 } /*DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER*/;
254
255 #pragma mark ---- Certificate Operations ----
256
257 /*!
258 @function SecCertificateCreateFromData
259 @abstract Creates a certificate based on the input data, type, and encoding.
260 @param data A pointer to the certificate data.
261 @param type The certificate type as defined in cssmtype.h.
262 @param encoding The certificate encoding as defined in cssmtype.h.
263 @param certificate On return, a reference to the newly created certificate.
264 @result A result code. See "Security Error Codes" (SecBase.h).
265 @discussion This API is deprecated in 10.7 Please use the SecCertificateCreateWithData API instead.
266 */
267 OSStatus SecCertificateCreateFromData(const CSSM_DATA *data, CSSM_CERT_TYPE type, CSSM_CERT_ENCODING encoding, SecCertificateRef * __nonnull CF_RETURNS_RETAINED certificate)
268 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
269
270 /*!
271 @function SecCertificateAddToKeychain
272 @abstract Adds a certificate to the specified keychain.
273 @param certificate A reference to a certificate.
274 @param keychain A reference to the keychain in which to add the certificate. Pass NULL to add the certificate to the default keychain.
275 @result A result code. See "Security Error Codes" (SecBase.h).
276 @discussion This function is successful only if the certificate was created using the SecCertificateCreateFromData or
277 SecCertificateCreateWithData functions, and the certificate has not yet been added to the specified keychain.
278 */
279 OSStatus SecCertificateAddToKeychain(SecCertificateRef certificate, SecKeychainRef __nullable keychain)
280 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_NA);
281
282 /*!
283 @function SecCertificateGetData
284 @abstract Retrieves the data for a given certificate.
285 @param certificate A reference to the certificate from which to retrieve the data.
286 @param data On return, the CSSM_DATA structure pointed to by data is filled in. You must allocate the space for a CSSM_DATA structure before calling this function. This data pointer is only guaranteed to remain valid as long as the certificate remains unchanged and valid.
287 @result A result code. See "Security Error Codes" (SecBase.h).
288 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyData API instead.
289 */
290 OSStatus SecCertificateGetData(SecCertificateRef certificate, CSSM_DATA_PTR data)
291 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
292
293 /*!
294 @function SecCertificateGetType
295 @abstract Retrieves the type for a given certificate.
296 @param certificate A reference to the certificate from which to obtain the type.
297 @param certificateType On return, the certificate type of the certificate. Certificate types are defined in cssmtype.h.
298 @result A result code. See "Security Error Codes" (SecBase.h).
299 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
300 */
301 OSStatus SecCertificateGetType(SecCertificateRef certificate, CSSM_CERT_TYPE *certificateType)
302 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
303
304 /*!
305 @function SecCertificateGetSubject
306 @abstract Retrieves the subject name for a given certificate.
307 @param certificate A reference to the certificate from which to obtain the subject name.
308 @param subject On return, a pointer to a CSSM_X509_NAME struct which contains the subject's X.509 name (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
309 @result A result code. See "Security Error Codes" (SecBase.h).
310 @discussion Prior to Mac OS X 10.5, this function did not return any output in the subject parameter. Your code should check the returned pointer value (in addition to the function result) before attempting to use it.
311 For example:
312 const CSSM_X509_NAME *subject = NULL;
313 OSStatus status = SecCertificateGetSubject(certificate, &subject);
314 if ( (status == errSecSuccess) && (subject != NULL) ) {
315 // subject is valid
316 }
317 This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
318 */
319 OSStatus SecCertificateGetSubject(SecCertificateRef certificate, const CSSM_X509_NAME * __nullable * __nonnull subject)
320 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
321
322 /*!
323 @function SecCertificateGetIssuer
324 @abstract Retrieves the issuer name for a given certificate.
325 @param certificate A reference to the certificate from which to obtain the issuer name.
326 @param issuer On return, a pointer to a CSSM_X509_NAME struct which contains the issuer's X.509 name (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
327 @result A result code. See "Security Error Codes" (SecBase.h).
328 @discussion Prior to Mac OS X 10.5, this function did not return any output in the issuer parameter. Your code should check the returned pointer value (in addition to the function result) before attempting to use it.
329 For example:
330 const CSSM_X509_NAME *issuer = NULL;
331 OSStatus status = SecCertificateGetIssuer(certificate, &issuer);
332 if ( (status == errSecSuccess) && (issuer != NULL) ) {
333 // issuer is valid
334 }
335 This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
336 */
337 OSStatus SecCertificateGetIssuer(SecCertificateRef certificate, const CSSM_X509_NAME * __nullable * __nonnull issuer)
338 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
339
340 /*!
341 @function SecCertificateGetCLHandle
342 @abstract Retrieves the certificate library handle for a given certificate.
343 @param certificate A reference to the certificate from which to obtain the certificate library handle.
344 @param clHandle On return, the certificate library handle of the given certificate. This handle remains valid at least as long as the certificate does.
345 @result A result code. See "Security Error Codes" (SecBase.h).
346 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
347 */
348 OSStatus SecCertificateGetCLHandle(SecCertificateRef certificate, CSSM_CL_HANDLE *clHandle)
349 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
350
351 /*!
352 @function SecCertificateGetAlgorithmID
353 @abstract Retrieves the algorithm identifier for a given certificate.
354 @param certificate A reference to the certificate from which to retrieve the algorithm identifier.
355 @param algid On return, a pointer to a CSSM_X509_ALGORITHM_IDENTIFIER struct which identifies the algorithm for this certificate (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
356 @result A result code. See "Security Error Codes" (SecBase.h).
357 discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
358 */
359 OSStatus SecCertificateGetAlgorithmID(SecCertificateRef certificate, const CSSM_X509_ALGORITHM_IDENTIFIER * __nullable * __nonnull algid)
360 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
361
362 /*!
363 @function SecCertificateCopyPreference
364 @abstract Returns the preferred certificate for the specified name and key usage. If a preferred certificate does not exist for the specified name and key usage, NULL is returned.
365 @param name A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
366 @param keyUsage A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to ignore this parameter.
367 @param certificate On return, a reference to the preferred certificate, or NULL if none was found. You are responsible for releasing this reference by calling the CFRelease function.
368 @result A result code. See "Security Error Codes" (SecBase.h).
369 @discussion This function will typically be used to obtain the preferred encryption certificate for an email recipient.
370 This API is deprecated in 10.7. Please use the SecCertificateCopyPreferred API instead.
371 */
372 OSStatus SecCertificateCopyPreference(CFStringRef name, uint32 keyUsage, SecCertificateRef * __nonnull CF_RETURNS_RETAINED certificate)
373 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
374
375 /*!
376 @function SecCertificateCopyPreferred
377 @abstract Returns the preferred certificate for the specified name and key usage. If a preferred certificate does not exist for the specified name and key usage, NULL is returned.
378 @param name A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
379 @param keyUsage A CFArrayRef value, containing items defined in SecItem.h Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
380 @result On return, a reference to the preferred certificate, or NULL if none was found. You are responsible for releasing this reference by calling the CFRelease function.
381 @discussion This function will typically be used to obtain the preferred encryption certificate for an email recipient. If a preferred certificate has not been set
382 for the supplied name, the returned reference will be NULL. Your code should then perform a search for possible certificates, using the SecItemCopyMatching API.
383 */
384 __nullable
385 SecCertificateRef SecCertificateCopyPreferred(CFStringRef name, CFArrayRef __nullable keyUsage)
386 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
387
388 /*!
389 @function SecCertificateSetPreference
390 @abstract Sets the preferred certificate for a specified name, key usage, and date.
391 @param certificate A reference to the certificate which will be preferred.
392 @param name A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
393 @param keyUsage A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to avoid specifying a particular key usage.
394 @param date (optional) A date reference. If supplied, the preferred certificate will be changed only if this date is later than the currently saved setting. Pass NULL if this preference should not be restricted by date.
395 @result A result code. See "Security Error Codes" (SecBase.h).
396 @discussion This function will typically be used to set the preferred encryption certificate for an email recipient, either manually (when encrypting email to a recipient) or automatically upon receipt of encrypted email.
397 This API is deprecated in 10.7. Plese use the SecCertificateSetPreferred API instead.
398 */
399 OSStatus SecCertificateSetPreference(SecCertificateRef certificate, CFStringRef name, uint32 keyUsage, CFDateRef __nullable date)
400 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
401
402 /*!
403 @function SecCertificateSetPreferred
404 @abstract Sets the preferred certificate for a specified name and optional key usage.
405 @param certificate A reference to the preferred certificate. If NULL is passed, any existing preference for the specified name is cleared instead.
406 @param name A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
407 @param keyUsage A CFArrayRef value, containing items defined in SecItem.h Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
408 @result A result code. See "Security Error Codes" (SecBase.h).
409 @discussion This function will typically be used to set the preferred encryption certificate for an email recipient, either manually (when encrypting email to a recipient)
410 or automatically upon receipt of encrypted email.
411 */
412 OSStatus SecCertificateSetPreferred(SecCertificateRef __nullable certificate, CFStringRef name, CFArrayRef __nullable keyUsage)
413 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
414
415 /*!
416 @typedef SecKeyUsage
417 @abstract Flags to indicate key usages in the KeyUsage extension of a certificate
418 @constant kSecKeyUsageUnspecified No KeyUsage extension in certificate.
419 @constant kSecKeyUsageDigitalSignature DigitalSignature bit set in KeyUsage extension.
420 @constant kSecKeyUsageNonRepudiation NonRepudiation bit set in KeyUsage extension.
421 @constant kSecKeyUsageContentCommitment ContentCommitment bit set in KeyUsage extension.
422 @constant kSecKeyUsageKeyEncipherment KeyEncipherment bit set in KeyUsage extension.
423 @constant kSecKeyUsageDataEncipherment DataEncipherment bit set in KeyUsage extension.
424 @constant kSecKeyUsageKeyAgreement KeyAgreement bit set in KeyUsage extension.
425 @constant kSecKeyUsageKeyCertSign KeyCertSign bit set in KeyUsage extension.
426 @constant kSecKeyUsageCRLSign CRLSign bit set in KeyUsage extension.
427 @constant kSecKeyUsageEncipherOnly EncipherOnly bit set in KeyUsage extension.
428 @constant kSecKeyUsageDecipherOnly DecipherOnly bit set in KeyUsage extension.
429 @constant kSecKeyUsageCritical KeyUsage extension is marked critical.
430 @constant kSecKeyUsageAll For masking purposes, all SecKeyUsage values.
431 */
432 typedef CF_OPTIONS(uint32_t, SecKeyUsage) {
433 kSecKeyUsageUnspecified = 0u,
434 kSecKeyUsageDigitalSignature = 1u << 0,
435 kSecKeyUsageNonRepudiation = 1u << 1,
436 kSecKeyUsageContentCommitment= 1u << 1,
437 kSecKeyUsageKeyEncipherment = 1u << 2,
438 kSecKeyUsageDataEncipherment = 1u << 3,
439 kSecKeyUsageKeyAgreement = 1u << 4,
440 kSecKeyUsageKeyCertSign = 1u << 5,
441 kSecKeyUsageCRLSign = 1u << 6,
442 kSecKeyUsageEncipherOnly = 1u << 7,
443 kSecKeyUsageDecipherOnly = 1u << 8,
444 kSecKeyUsageCritical = 1u << 31,
445 kSecKeyUsageAll = 0x7FFFFFFFu
446 };
447
448 /*!
449 @enum kSecPropertyKey
450 @abstract Constants used to access dictionary entries returned by SecCertificateCopyValues
451 @constant kSecPropertyKeyType The type of the entry
452 @constant kSecPropertyKeyLabel The label of the entry
453 @constant kSecPropertyKeyLocalizedLabel The localized label of the entry
454 @constant kSecPropertyKeyValue The value of the entry
455 */
456
457 extern const CFStringRef kSecPropertyKeyType __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
458 extern const CFStringRef kSecPropertyKeyLabel __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
459 extern const CFStringRef kSecPropertyKeyLocalizedLabel __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
460 extern const CFStringRef kSecPropertyKeyValue __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
461
462 /*!
463 @enum kSecPropertyType
464 @abstract Public Constants for property list values returned by SecCertificateCopyValues
465 @discussion Note that kSecPropertyTypeTitle and kSecPropertyTypeError are defined in SecTrust.h
466 */
467 extern const CFStringRef kSecPropertyTypeWarning __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
468 extern const CFStringRef kSecPropertyTypeSuccess __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
469 extern const CFStringRef kSecPropertyTypeSection __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
470 extern const CFStringRef kSecPropertyTypeData __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
471 extern const CFStringRef kSecPropertyTypeString __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
472 extern const CFStringRef kSecPropertyTypeURL __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
473 extern const CFStringRef kSecPropertyTypeDate __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
474 extern const CFStringRef kSecPropertyTypeArray API_AVAILABLE(macos(10.15)) SPI_AVAILABLE(ios(13.0), watchos(6.0), tvos(13.0), macCatalyst(13.0));
475 extern const CFStringRef kSecPropertyTypeNumber API_AVAILABLE(macos(10.15)) SPI_AVAILABLE(ios(13.0), watchos(6.0), tvos(13.0), macCatalyst(13.0));
476
477 /*!
478 @function SecCertificateCopyValues
479 @abstract Creates a dictionary that represents a certificate's contents.
480 @param certificate The certificate from which to get values
481 @param keys An array of string OID values, or NULL. If present, this is
482 the subset of values from the certificate to return. If NULL,
483 all values will be returned. Only OIDs that are top level keys
484 in the returned dictionary can be specified. Unknown OIDs are
485 ignored.
486 @param error An optional pointer to a CFErrorRef. This value is
487 set if an error occurred. If not NULL the caller is
488 responsible for releasing the CFErrorRef.
489 @discussion The keys array will contain all of the keys used in the
490 returned dictionary. The top level keys in the returned
491 dictionary are OIDs, many of which are found in SecCertificateOIDs.h.
492 Each entry that is returned is itself a dictionary with four
493 entries, whose keys are kSecPropertyKeyType, kSecPropertyKeyLabel,
494 kSecPropertyKeyLocalizedLabel, kSecPropertyKeyValue. The label
495 entries may contain a descriptive (localized) string, or an
496 OID string. The kSecPropertyKeyType describes the type in the
497 value entry. The value entry may be any CFType, although it
498 is usually a CFStringRef, CFArrayRef or a CFDictionaryRef.
499 */
500 __nullable
501 CFDictionaryRef SecCertificateCopyValues(SecCertificateRef certificate, CFArrayRef __nullable keys, CFErrorRef *error)
502 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
503
504 /*!
505 @function SecCertificateCopyLongDescription
506 @abstract Return the long description of a certificate
507 @param alloc The CFAllocator which should be used to allocate
508 memory for the dictionary and its storage for values. This
509 parameter may be NULL in which case the current default
510 CFAllocator is used. If this reference is not a valid
511 CFAllocator, the behavior is undefined.
512 @param certificate The certificate from which to retrieve the long description
513 @param error An optional pointer to a CFErrorRef. This value is
514 set if an error occurred. If not NULL the caller is
515 responsible for releasing the CFErrorRef.
516 @result A CFStringRef of the long description or NULL. If NULL and the error
517 parameter is supplied the error will be returned in the error parameter
518 @discussion Note that the format of this string may change in the future
519 */
520
521 __nullable
522 CFStringRef SecCertificateCopyLongDescription(CFAllocatorRef __nullable alloc, SecCertificateRef certificate, CFErrorRef *error)
523 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
524
525 /*!
526 @function SecCertificateCopyShortDescription
527 @abstract Return the short description of a certificate
528 @param alloc The CFAllocator which should be used to allocate
529 memory for the dictionary and its storage for values. This
530 parameter may be NULL in which case the current default
531 CFAllocator is used. If this reference is not a valid
532 CFAllocator, the behavior is undefined.
533 @param certificate The certificate from which to retrieve the short description
534 @param error An optional pointer to a CFErrorRef. This value is
535 set if an error occurred. If not NULL the caller is
536 responsible for releasing the CFErrorRef.
537 @result A CFStringRef of the short description or NULL. If NULL and the error
538 parameter is supplied the error will be returned in the error parameter
539 @discussion Note that the format of this string may change in the future
540 */
541
542 __nullable
543 CFStringRef SecCertificateCopyShortDescription(CFAllocatorRef __nullable alloc, SecCertificateRef certificate, CFErrorRef *error)
544 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
545
546 /*!
547 @function SecCertificateCopyNormalizedIssuerContent
548 @abstract Return the certificate's normalized issuer
549 @param certificate The certificate from which to get values
550 @param error An optional pointer to a CFErrorRef. This value is
551 set if an error occurred. If not NULL the caller is
552 responsible for releasing the CFErrorRef.
553 @discussion The issuer is a sequence in the format used by
554 SecItemCopyMatching. The content returned is a DER-encoded
555 X.509 distinguished name. For a display version of the issuer,
556 call SecCertificateCopyValues. The caller must CFRelease
557 the value returned.
558 */
559
560 __nullable
561 CFDataRef SecCertificateCopyNormalizedIssuerContent(SecCertificateRef certificate, CFErrorRef *error)
562 __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_7, __MAC_10_12_4, __IPHONE_NA, __IPHONE_NA, "SecCertificateCopyNormalizedIssuerContent is deprecated. Use SecCertificateCopyNormalizedIssuerSequence instead.");
563
564 /*!
565 @function SecCertificateCopyNormalizedSubjectContent
566 @abstract Return the certificate's normalized subject
567 @param certificate The certificate from which to get values
568 @param error An optional pointer to a CFErrorRef. This value is
569 set if an error occurred. If not NULL the caller is
570 responsible for releasing the CFErrorRef.
571 @discussion The subject is a sequence in the format used by
572 SecItemCopyMatching. The content returned is a DER-encoded
573 X.509 distinguished name. For a display version of the subject,
574 call SecCertificateCopyValues. The caller must CFRelease
575 the value returned.
576 */
577
578 __nullable
579 CFDataRef SecCertificateCopyNormalizedSubjectContent(SecCertificateRef certificate, CFErrorRef *error)
580 __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_7, __MAC_10_12_4, __IPHONE_NA, __IPHONE_NA, "SecCertificateCopyNormalizedSubjectContent is deprecated. Use SecCertificateCopyNormalizedSubjectSequence instead.");
581
582
583 #endif /* SEC_OS_OSX */
584
585 CF_IMPLICIT_BRIDGING_DISABLED
586 CF_ASSUME_NONNULL_END
587
588 __END_DECLS
589
590 #endif /* !_SECURITY_SECCERTIFICATE_H_ */