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