]> git.saurik.com Git - apple/security.git/blob - trust/SecCertificate.h
Security-58286.220.15.tar.gz
[apple/security.git] / trust / SecCertificate.h
1 /*
2 * Copyright (c) 2002-2017 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 */
154 __nullable CF_RETURNS_RETAINED
155 SecKeyRef SecCertificateCopyKey(SecCertificateRef certificate)
156 API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0));
157
158 #if TARGET_OS_IPHONE
159 /*!
160 @function SecCertificateCopyPublicKey
161 @abstract Retrieves the public key for a given certificate.
162 @param certificate A reference to the certificate from which to retrieve the public key.
163 @result A reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function.
164 @discussion NOTE: Deprecated in iOS 12.0; use SecCertificateCopyKey instead for cross-platform availability.
165 */
166 __nullable
167 SecKeyRef SecCertificateCopyPublicKey(SecCertificateRef certificate)
168 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopyKey", ios(10.3, 12.0)) API_UNAVAILABLE(macos);
169 #endif
170
171 #if TARGET_OS_OSX
172 /*!
173 @function SecCertificateCopyPublicKey
174 @abstract Retrieves the public key for a given certificate.
175 @param certificate A reference to the certificate from which to retrieve the public key.
176 @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.
177 @result A result code. See "Security Error Codes" (SecBase.h).
178 @discussion NOTE: Deprecated in macOS 10.14; use SecCertificateCopyKey instead for cross-platform availability.
179 */
180 OSStatus SecCertificateCopyPublicKey(SecCertificateRef certificate, SecKeyRef * __nonnull CF_RETURNS_RETAINED key)
181 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopyKey", macos(10.3, 10.14)) API_UNAVAILABLE(ios);
182 #endif
183
184 /*!
185 @function SecCertificateCopySerialNumberData
186 @abstract Return the certificate's serial number.
187 @param certificate The certificate from which to get values.
188 @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.
189 @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.
190 */
191 __nullable
192 CFDataRef SecCertificateCopySerialNumberData(SecCertificateRef certificate, CFErrorRef *error)
193 __OSX_AVAILABLE_STARTING(__MAC_10_13, __IPHONE_11_0);
194
195 #if TARGET_OS_IPHONE
196 /*!
197 @function SecCertificateCopySerialNumber
198 @abstract Return the certificate's serial number.
199 @param certificate The certificate from which to get values.
200 @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.
201 */
202 __nullable
203 CFDataRef SecCertificateCopySerialNumber(SecCertificateRef certificate)
204 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopySerialNumberData", ios(10.3, 11.0)) API_UNAVAILABLE(macos);
205 #endif
206
207 #if TARGET_OS_OSX
208 /*!
209 @function SecCertificateCopySerialNumber
210 @abstract Return the certificate's serial number.
211 @param certificate The certificate from which to get values.
212 @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.
213 @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.
214 */
215 __nullable
216 CFDataRef SecCertificateCopySerialNumber(SecCertificateRef certificate, CFErrorRef *error)
217 API_DEPRECATED_WITH_REPLACEMENT("SecCertificateCopySerialNumberData", macos(10.7, 10.13)) API_UNAVAILABLE(ios);
218 #endif
219
220 /*
221 * Legacy functions (OS X only)
222 */
223 #if SEC_OS_OSX
224 /*!
225 @enum CertificateItemAttributes
226 @abstract Indicates the type of a certificate item attribute.
227 @constant kSecSubjectItemAttr Indicates a DER-encoded subject distinguished name.
228 @constant kSecIssuerItemAttr Indicates a DER-encoded issuer distinguished name.
229 @constant kSecSerialNumberItemAttr Indicates a DER-encoded certificate serial number (without the tag and length).
230 @constant kSecPublicKeyHashItemAttr Indicates a public key hash.
231 @constant kSecSubjectKeyIdentifierItemAttr Indicates a subject key identifier.
232 @constant kSecCertTypeItemAttr Indicates a certificate type.
233 @constant kSecCertEncodingItemAttr Indicates a certificate encoding.
234 */
235 enum
236 {
237 kSecSubjectItemAttr = 'subj',
238 kSecIssuerItemAttr = 'issu',
239 kSecSerialNumberItemAttr = 'snbr',
240 kSecPublicKeyHashItemAttr = 'hpky',
241 kSecSubjectKeyIdentifierItemAttr = 'skid',
242 kSecCertTypeItemAttr = 'ctyp',
243 kSecCertEncodingItemAttr = 'cenc'
244 } /*DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER*/;
245
246 #pragma mark ---- Certificate Operations ----
247
248 /*!
249 @function SecCertificateCreateFromData
250 @abstract Creates a certificate based on the input data, type, and encoding.
251 @param data A pointer to the certificate data.
252 @param type The certificate type as defined in cssmtype.h.
253 @param encoding The certificate encoding as defined in cssmtype.h.
254 @param certificate On return, a reference to the newly created certificate.
255 @result A result code. See "Security Error Codes" (SecBase.h).
256 @discussion This API is deprecated in 10.7 Please use the SecCertificateCreateWithData API instead.
257 */
258 OSStatus SecCertificateCreateFromData(const CSSM_DATA *data, CSSM_CERT_TYPE type, CSSM_CERT_ENCODING encoding, SecCertificateRef * __nonnull CF_RETURNS_RETAINED certificate)
259 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
260
261 /*!
262 @function SecCertificateAddToKeychain
263 @abstract Adds a certificate to the specified keychain.
264 @param certificate A reference to a certificate.
265 @param keychain A reference to the keychain in which to add the certificate. Pass NULL to add the certificate to the default keychain.
266 @result A result code. See "Security Error Codes" (SecBase.h).
267 @discussion This function is successful only if the certificate was created using the SecCertificateCreateFromData or
268 SecCertificateCreateWithData functions, and the certificate has not yet been added to the specified keychain.
269 */
270 OSStatus SecCertificateAddToKeychain(SecCertificateRef certificate, SecKeychainRef __nullable keychain)
271 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_NA);
272
273 /*!
274 @function SecCertificateGetData
275 @abstract Retrieves the data for a given certificate.
276 @param certificate A reference to the certificate from which to retrieve the data.
277 @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.
278 @result A result code. See "Security Error Codes" (SecBase.h).
279 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyData API instead.
280 */
281 OSStatus SecCertificateGetData(SecCertificateRef certificate, CSSM_DATA_PTR data)
282 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
283
284 /*!
285 @function SecCertificateGetType
286 @abstract Retrieves the type for a given certificate.
287 @param certificate A reference to the certificate from which to obtain the type.
288 @param certificateType On return, the certificate type of the certificate. Certificate types are defined in cssmtype.h.
289 @result A result code. See "Security Error Codes" (SecBase.h).
290 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
291 */
292 OSStatus SecCertificateGetType(SecCertificateRef certificate, CSSM_CERT_TYPE *certificateType)
293 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
294
295 /*!
296 @function SecCertificateGetSubject
297 @abstract Retrieves the subject name for a given certificate.
298 @param certificate A reference to the certificate from which to obtain the subject name.
299 @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.
300 @result A result code. See "Security Error Codes" (SecBase.h).
301 @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.
302 For example:
303 const CSSM_X509_NAME *subject = NULL;
304 OSStatus status = SecCertificateGetSubject(certificate, &subject);
305 if ( (status == errSecSuccess) && (subject != NULL) ) {
306 // subject is valid
307 }
308 This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
309 */
310 OSStatus SecCertificateGetSubject(SecCertificateRef certificate, const CSSM_X509_NAME * __nullable * __nonnull subject)
311 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
312
313 /*!
314 @function SecCertificateGetIssuer
315 @abstract Retrieves the issuer name for a given certificate.
316 @param certificate A reference to the certificate from which to obtain the issuer name.
317 @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.
318 @result A result code. See "Security Error Codes" (SecBase.h).
319 @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.
320 For example:
321 const CSSM_X509_NAME *issuer = NULL;
322 OSStatus status = SecCertificateGetIssuer(certificate, &issuer);
323 if ( (status == errSecSuccess) && (issuer != NULL) ) {
324 // issuer is valid
325 }
326 This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
327 */
328 OSStatus SecCertificateGetIssuer(SecCertificateRef certificate, const CSSM_X509_NAME * __nullable * __nonnull issuer)
329 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
330
331 /*!
332 @function SecCertificateGetCLHandle
333 @abstract Retrieves the certificate library handle for a given certificate.
334 @param certificate A reference to the certificate from which to obtain the certificate library handle.
335 @param clHandle On return, the certificate library handle of the given certificate. This handle remains valid at least as long as the certificate does.
336 @result A result code. See "Security Error Codes" (SecBase.h).
337 @discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
338 */
339 OSStatus SecCertificateGetCLHandle(SecCertificateRef certificate, CSSM_CL_HANDLE *clHandle)
340 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
341
342 /*!
343 @function SecCertificateGetAlgorithmID
344 @abstract Retrieves the algorithm identifier for a given certificate.
345 @param certificate A reference to the certificate from which to retrieve the algorithm identifier.
346 @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.
347 @result A result code. See "Security Error Codes" (SecBase.h).
348 discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
349 */
350 OSStatus SecCertificateGetAlgorithmID(SecCertificateRef certificate, const CSSM_X509_ALGORITHM_IDENTIFIER * __nullable * __nonnull algid)
351 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
352
353 /*!
354 @function SecCertificateCopyPreference
355 @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.
356 @param name A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
357 @param keyUsage A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to ignore this parameter.
358 @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.
359 @result A result code. See "Security Error Codes" (SecBase.h).
360 @discussion This function will typically be used to obtain the preferred encryption certificate for an email recipient.
361 This API is deprecated in 10.7. Please use the SecCertificateCopyPreferred API instead.
362 */
363 OSStatus SecCertificateCopyPreference(CFStringRef name, uint32 keyUsage, SecCertificateRef * __nonnull CF_RETURNS_RETAINED certificate)
364 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
365
366 /*!
367 @function SecCertificateCopyPreferred
368 @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.
369 @param name A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
370 @param keyUsage A CFArrayRef value, containing items defined in SecItem.h Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
371 @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.
372 @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
373 for the supplied name, the returned reference will be NULL. Your code should then perform a search for possible certificates, using the SecItemCopyMatching API.
374 */
375 __nullable
376 SecCertificateRef SecCertificateCopyPreferred(CFStringRef name, CFArrayRef __nullable keyUsage)
377 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
378
379 /*!
380 @function SecCertificateSetPreference
381 @abstract Sets the preferred certificate for a specified name, key usage, and date.
382 @param certificate A reference to the certificate which will be preferred.
383 @param name A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
384 @param keyUsage A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to avoid specifying a particular key usage.
385 @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.
386 @result A result code. See "Security Error Codes" (SecBase.h).
387 @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.
388 This API is deprecated in 10.7. Plese use the SecCertificateSetPreferred API instead.
389 */
390 OSStatus SecCertificateSetPreference(SecCertificateRef certificate, CFStringRef name, uint32 keyUsage, CFDateRef __nullable date)
391 DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
392
393 /*!
394 @function SecCertificateSetPreferred
395 @abstract Sets the preferred certificate for a specified name and optional key usage.
396 @param certificate A reference to the preferred certificate. If NULL is passed, any existing preference for the specified name is cleared instead.
397 @param name A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
398 @param keyUsage A CFArrayRef value, containing items defined in SecItem.h Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
399 @result A result code. See "Security Error Codes" (SecBase.h).
400 @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)
401 or automatically upon receipt of encrypted email.
402 */
403 OSStatus SecCertificateSetPreferred(SecCertificateRef __nullable certificate, CFStringRef name, CFArrayRef __nullable keyUsage)
404 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
405
406 /*!
407 @typedef SecKeyUsage
408 @abstract Flags to indicate key usages in the KeyUsage extension of a certificate
409 @constant kSecKeyUsageUnspecified No KeyUsage extension in certificate.
410 @constant kSecKeyUsageDigitalSignature DigitalSignature bit set in KeyUsage extension.
411 @constant kSecKeyUsageNonRepudiation NonRepudiation bit set in KeyUsage extension.
412 @constant kSecKeyUsageContentCommitment ContentCommitment bit set in KeyUsage extension.
413 @constant kSecKeyUsageKeyEncipherment KeyEncipherment bit set in KeyUsage extension.
414 @constant kSecKeyUsageDataEncipherment DataEncipherment bit set in KeyUsage extension.
415 @constant kSecKeyUsageKeyAgreement KeyAgreement bit set in KeyUsage extension.
416 @constant kSecKeyUsageKeyCertSign KeyCertSign bit set in KeyUsage extension.
417 @constant kSecKeyUsageCRLSign CRLSign bit set in KeyUsage extension.
418 @constant kSecKeyUsageEncipherOnly EncipherOnly bit set in KeyUsage extension.
419 @constant kSecKeyUsageDecipherOnly DecipherOnly bit set in KeyUsage extension.
420 @constant kSecKeyUsageCritical KeyUsage extension is marked critical.
421 @constant kSecKeyUsageAll For masking purposes, all SecKeyUsage values.
422 */
423 typedef CF_OPTIONS(uint32_t, SecKeyUsage) {
424 kSecKeyUsageUnspecified = 0u,
425 kSecKeyUsageDigitalSignature = 1u << 0,
426 kSecKeyUsageNonRepudiation = 1u << 1,
427 kSecKeyUsageContentCommitment= 1u << 1,
428 kSecKeyUsageKeyEncipherment = 1u << 2,
429 kSecKeyUsageDataEncipherment = 1u << 3,
430 kSecKeyUsageKeyAgreement = 1u << 4,
431 kSecKeyUsageKeyCertSign = 1u << 5,
432 kSecKeyUsageCRLSign = 1u << 6,
433 kSecKeyUsageEncipherOnly = 1u << 7,
434 kSecKeyUsageDecipherOnly = 1u << 8,
435 kSecKeyUsageCritical = 1u << 31,
436 kSecKeyUsageAll = 0x7FFFFFFFu
437 };
438
439 /*!
440 @enum kSecPropertyKey
441 @abstract Constants used to access dictionary entries returned by SecCertificateCopyValues
442 @constant kSecPropertyKeyType The type of the entry
443 @constant kSecPropertyKeyLabel The label of the entry
444 @constant kSecPropertyKeyLocalizedLabel The localized label of the entry
445 @constant kSecPropertyKeyValue The value of the entry
446 */
447
448 extern const CFStringRef kSecPropertyKeyType __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
449 extern const CFStringRef kSecPropertyKeyLabel __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
450 extern const CFStringRef kSecPropertyKeyLocalizedLabel __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
451 extern const CFStringRef kSecPropertyKeyValue __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
452
453 /*!
454 @enum kSecPropertyType
455 @abstract Public Constants for property list values returned by SecCertificateCopyValues
456 @discussion Note that kSecPropertyTypeTitle and kSecPropertyTypeError are defined in SecTrust.h
457 */
458 extern const CFStringRef kSecPropertyTypeWarning __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
459 extern const CFStringRef kSecPropertyTypeSuccess __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
460 extern const CFStringRef kSecPropertyTypeSection __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
461 extern const CFStringRef kSecPropertyTypeData __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
462 extern const CFStringRef kSecPropertyTypeString __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
463 extern const CFStringRef kSecPropertyTypeURL __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
464 extern const CFStringRef kSecPropertyTypeDate __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
465
466 /*!
467 @function SecCertificateCopyValues
468 @abstract Creates a dictionary that represents a certificate's contents.
469 @param certificate The certificate from which to get values
470 @param keys An array of string OID values, or NULL. If present, this is
471 the subset of values from the certificate to return. If NULL,
472 all values will be returned. Only OIDs that are top level keys
473 in the returned dictionary can be specified. Unknown OIDs are
474 ignored.
475 @param error An optional pointer to a CFErrorRef. This value is
476 set if an error occurred. If not NULL the caller is
477 responsible for releasing the CFErrorRef.
478 @discussion The keys array will contain all of the keys used in the
479 returned dictionary. The top level keys in the returned
480 dictionary are OIDs, many of which are found in SecCertificateOIDs.h.
481 Each entry that is returned is itself a dictionary with four
482 entries, whose keys are kSecPropertyKeyType, kSecPropertyKeyLabel,
483 kSecPropertyKeyLocalizedLabel, kSecPropertyKeyValue. The label
484 entries may contain a descriptive (localized) string, or an
485 OID string. The kSecPropertyKeyType describes the type in the
486 value entry. The value entry may be any CFType, although it
487 is usually a CFStringRef, CFArrayRef or a CFDictionaryRef.
488 */
489 __nullable
490 CFDictionaryRef SecCertificateCopyValues(SecCertificateRef certificate, CFArrayRef __nullable keys, CFErrorRef *error)
491 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
492
493 /*!
494 @function SecCertificateCopyLongDescription
495 @abstract Return the long description of a certificate
496 @param alloc The CFAllocator which should be used to allocate
497 memory for the dictionary and its storage for values. This
498 parameter may be NULL in which case the current default
499 CFAllocator is used. If this reference is not a valid
500 CFAllocator, the behavior is undefined.
501 @param certificate The certificate from which to retrieve the long description
502 @param error An optional pointer to a CFErrorRef. This value is
503 set if an error occurred. If not NULL the caller is
504 responsible for releasing the CFErrorRef.
505 @result A CFStringRef of the long description or NULL. If NULL and the error
506 parameter is supplied the error will be returned in the error parameter
507 @discussion Note that the format of this string may change in the future
508 */
509
510 __nullable
511 CFStringRef SecCertificateCopyLongDescription(CFAllocatorRef __nullable alloc, SecCertificateRef certificate, CFErrorRef *error)
512 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
513
514 /*!
515 @function SecCertificateCopyShortDescription
516 @abstract Return the short description of a certificate
517 @param alloc The CFAllocator which should be used to allocate
518 memory for the dictionary and its storage for values. This
519 parameter may be NULL in which case the current default
520 CFAllocator is used. If this reference is not a valid
521 CFAllocator, the behavior is undefined.
522 @param certificate The certificate from which to retrieve the short description
523 @param error An optional pointer to a CFErrorRef. This value is
524 set if an error occurred. If not NULL the caller is
525 responsible for releasing the CFErrorRef.
526 @result A CFStringRef of the short description or NULL. If NULL and the error
527 parameter is supplied the error will be returned in the error parameter
528 @discussion Note that the format of this string may change in the future
529 */
530
531 __nullable
532 CFStringRef SecCertificateCopyShortDescription(CFAllocatorRef __nullable alloc, SecCertificateRef certificate, CFErrorRef *error)
533 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
534
535 /*!
536 @function SecCertificateCopyNormalizedIssuerContent
537 @abstract Return the certificate's normalized issuer
538 @param certificate The certificate from which to get values
539 @param error An optional pointer to a CFErrorRef. This value is
540 set if an error occurred. If not NULL the caller is
541 responsible for releasing the CFErrorRef.
542 @discussion The issuer is a sequence in the format used by
543 SecItemCopyMatching. The content returned is a DER-encoded
544 X.509 distinguished name. For a display version of the issuer,
545 call SecCertificateCopyValues. The caller must CFRelease
546 the value returned.
547 */
548
549 __nullable
550 CFDataRef SecCertificateCopyNormalizedIssuerContent(SecCertificateRef certificate, CFErrorRef *error)
551 __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_7, __MAC_10_12_4, __IPHONE_NA, __IPHONE_NA, "SecCertificateCopyNormalizedIssuerContent is deprecated. Use SecCertificateCopyNormalizedIssuerSequence instead.");
552
553 /*!
554 @function SecCertificateCopyNormalizedSubjectContent
555 @abstract Return the certificate's normalized subject
556 @param certificate The certificate from which to get values
557 @param error An optional pointer to a CFErrorRef. This value is
558 set if an error occurred. If not NULL the caller is
559 responsible for releasing the CFErrorRef.
560 @discussion The subject is a sequence in the format used by
561 SecItemCopyMatching. The content returned is a DER-encoded
562 X.509 distinguished name. For a display version of the subject,
563 call SecCertificateCopyValues. The caller must CFRelease
564 the value returned.
565 */
566
567 __nullable
568 CFDataRef SecCertificateCopyNormalizedSubjectContent(SecCertificateRef certificate, CFErrorRef *error)
569 __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_7, __MAC_10_12_4, __IPHONE_NA, __IPHONE_NA, "SecCertificateCopyNormalizedSubjectContent is deprecated. Use SecCertificateCopyNormalizedSubjectSequence instead.");
570
571
572 #endif /* SEC_OS_OSX */
573
574 CF_IMPLICIT_BRIDGING_DISABLED
575 CF_ASSUME_NONNULL_END
576
577 __END_DECLS
578
579 #endif /* !_SECURITY_SECCERTIFICATE_H_ */