2 * Copyright (c) 2006-2010 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 @header SecCertificatePriv
26 The functions provided in SecCertificatePriv.h implement and manage a particular
27 type of keychain item that represents a certificate. You can store a
28 certificate in a keychain, but a certificate can also be a transient
31 You can use a certificate as a keychain item in most functions.
32 Certificates are able to compute their parent certificates, and much more.
35 #ifndef _SECURITY_SECCERTIFICATEPRIV_H_
36 #define _SECURITY_SECCERTIFICATEPRIV_H_
38 #include <Security/SecCertificate.h>
39 #include <CoreFoundation/CFArray.h>
40 #include <CoreFoundation/CFData.h>
41 #include <CoreFoundation/CFDate.h>
42 #include <CoreFoundation/CFDictionary.h>
45 #if defined(__cplusplus)
49 typedef uint32_t SecKeyUsage
;
51 kSecKeyUsageUnspecified
= 0,
52 kSecKeyUsageDigitalSignature
= 1 << 0,
53 kSecKeyUsageNonRepudiation
= 1 << 1,
54 kSecKeyUsageContentCommitment
= 1 << 1,
55 kSecKeyUsageKeyEncipherment
= 1 << 2,
56 kSecKeyUsageDataEncipherment
= 1 << 3,
57 kSecKeyUsageKeyAgreement
= 1 << 4,
58 kSecKeyUsageKeyCertSign
= 1 << 5,
59 kSecKeyUsageCRLSign
= 1 << 6,
60 kSecKeyUsageEncipherOnly
= 1 << 7,
61 kSecKeyUsageDecipherOnly
= 1 << 8,
62 kSecKeyUsageCritical
= 1 << 31,
63 kSecKeyUsageAll
= 0x7FFFFFFF
66 /* Return a certificate for the DER representation of this certificate.
67 Return NULL if the passed-in data is not a valid DER-encoded X.509
69 SecCertificateRef
SecCertificateCreateWithBytes(CFAllocatorRef allocator
,
70 const UInt8
*bytes
, CFIndex length
);
72 /* Return the length of the DER representation of this certificate. */
73 CFIndex
SecCertificateGetLength(SecCertificateRef certificate
);
75 /* Return the bytes of the DER representation of this certificate. */
76 const UInt8
*SecCertificateGetBytePtr(SecCertificateRef certificate
);
79 #pragma mark Certificate Accessors
81 CFDataRef
SecCertificateGetSHA1Digest(SecCertificateRef certificate
);
83 CFDataRef
SecCertificateCopyIssuerSHA1Digest(SecCertificateRef certificate
);
85 CFDataRef
SecCertificateCopyPublicKeySHA1Digest(SecCertificateRef certificate
);
88 @function SecCertificateCopyIssuerSummary
89 @abstract Return a simple string which hopefully represents a human understandable issuer.
90 @param certificate SecCertificate object created with SecCertificateCreateWithData().
91 @discussion All the data in this string comes from the certificate itself
92 and thus it's in whatever language the certificate itself is in.
93 @result A CFStringRef which the caller should CFRelease() once it's no longer needed.
95 CFStringRef
SecCertificateCopyIssuerSummary(SecCertificateRef certificate
);
98 @function SecCertificateCopyProperties
99 @abstract Return a property array for this trust certificate.
100 @param certificate A reference to the certificate to evaluate.
101 @result A property array. It is the caller's responsability to CFRelease
102 the returned array when it is no longer needed.
103 See SecTrustCopySummaryPropertiesAtIndex on how to intepret this array.
104 Unlike that function call this function returns a detailed description
105 of the certificate in question.
107 CFArrayRef
SecCertificateCopyProperties(SecCertificateRef certificate
);
109 CFMutableArrayRef
SecCertificateCopySummaryProperties(
110 SecCertificateRef certificate
, CFAbsoluteTime verifyTime
);
112 /* Return the content of a DER-encoded integer (without the tag and length
113 fields) for this certificate's serial number. The caller must CFRelease
114 the value returned. */
115 CFDataRef
SecCertificateCopySerialNumber(SecCertificateRef certificate
);
117 /* Return an array of CFStringRefs representing the ip addresses in the
118 certificate if any. */
119 CFArrayRef
SecCertificateCopyIPAddresses(SecCertificateRef certificate
);
121 /* Return an array of CFStringRefs representing the dns addresses in the
122 certificate if any. */
123 CFArrayRef
SecCertificateCopyDNSNames(SecCertificateRef certificate
);
125 /* Return an array of CFStringRefs representing the email addresses in the
126 certificate if any. */
127 CFArrayRef
SecCertificateCopyRFC822Names(SecCertificateRef certificate
);
129 /* Return an array of CFStringRefs representing the common names in the
130 certificates subject if any. */
131 CFArrayRef
SecCertificateCopyCommonNames(SecCertificateRef certificate
);
133 /* Return an array of CFStringRefs representing the organization in the
134 certificate's subject if any. */
135 CFArrayRef
SecCertificateCopyOrganization(SecCertificateRef certificate
);
137 /* Return an array of CFStringRefs representing the NTPrincipalNames in the
138 certificate if any. */
139 CFArrayRef
SecCertificateCopyNTPrincipalNames(SecCertificateRef certificate
);
141 /* Return a string formatted according to RFC 2253 representing the complete
142 subject of certificate. */
143 CFStringRef
SecCertificateCopySubjectString(SecCertificateRef certificate
);
145 /* Return a string with the company name of an ev leaf certificate. */
146 CFStringRef
SecCertificateCopyCompanyName(SecCertificateRef certificate
);
148 /* X.509 Certificate Version: 1, 2 or 3. */
149 CFIndex
SecCertificateVersion(SecCertificateRef certificate
);
150 CFAbsoluteTime
SecCertificateNotValidBefore(SecCertificateRef certificate
);
151 CFAbsoluteTime
SecCertificateNotValidAfter(SecCertificateRef certificate
);
153 /* Return true iff certificate is self signed and has a basic constraints
154 extension indicating that it's a certificate authority. */
155 bool SecCertificateIsSelfSignedCA(SecCertificateRef certificate
);
157 SecKeyUsage
SecCertificateGetKeyUsage(SecCertificateRef certificate
);
159 /* Returns an array of CFDataRefs for all extended key usage oids or NULL */
160 CFArrayRef
SecCertificateCopyExtendedKeyUsage(SecCertificateRef certificate
);
162 /* Returns a certificate from a pem blob */
163 SecCertificateRef
SecCertificateCreateWithPEM(CFAllocatorRef allocator
,
164 CFDataRef pem_certificate
);
166 /* Return an array of CFDataRefs from an array of SecCertificateRefs. */
167 CFArrayRef
SecCertificateArrayCopyDataArray(CFArrayRef certificates
);
169 /* Return an array of SecCertificateRefs from an array of CFDataRefs. */
170 CFArrayRef
SecCertificateDataArrayCopyArray(CFArrayRef certificates
);
173 #if defined(__cplusplus)
177 #endif /* !_SECURITY_SECCERTIFICATEPRIV_H_ */