]> git.saurik.com Git - apple/security.git/blob - sec/Security/SecCertificatePriv.h
Security-55163.44.tar.gz
[apple/security.git] / sec / Security / SecCertificatePriv.h
1 /*
2 * Copyright (c) 2006-2010 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 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
29 object.
30
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.
33 */
34
35 #ifndef _SECURITY_SECCERTIFICATEPRIV_H_
36 #define _SECURITY_SECCERTIFICATEPRIV_H_
37
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>
43 #include <stdbool.h>
44
45 #if defined(__cplusplus)
46 extern "C" {
47 #endif
48
49 typedef uint32_t SecKeyUsage;
50 enum {
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
64 };
65
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
68 certificate. */
69 SecCertificateRef SecCertificateCreateWithBytes(CFAllocatorRef allocator,
70 const UInt8 *bytes, CFIndex length);
71
72 /* Return the length of the DER representation of this certificate. */
73 CFIndex SecCertificateGetLength(SecCertificateRef certificate);
74
75 /* Return the bytes of the DER representation of this certificate. */
76 const UInt8 *SecCertificateGetBytePtr(SecCertificateRef certificate);
77
78 #pragma mark -
79 #pragma mark Certificate Accessors
80
81 CFDataRef SecCertificateGetSHA1Digest(SecCertificateRef certificate);
82
83 CFDataRef SecCertificateCopyIssuerSHA1Digest(SecCertificateRef certificate);
84
85 CFDataRef SecCertificateCopyPublicKeySHA1Digest(SecCertificateRef certificate);
86
87 /*!
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.
94 */
95 CFStringRef SecCertificateCopyIssuerSummary(SecCertificateRef certificate);
96
97 /*!
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.
106 */
107 CFArrayRef SecCertificateCopyProperties(SecCertificateRef certificate);
108
109 CFMutableArrayRef SecCertificateCopySummaryProperties(
110 SecCertificateRef certificate, CFAbsoluteTime verifyTime);
111
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);
116
117 /* Return an array of CFStringRefs representing the ip addresses in the
118 certificate if any. */
119 CFArrayRef SecCertificateCopyIPAddresses(SecCertificateRef certificate);
120
121 /* Return an array of CFStringRefs representing the dns addresses in the
122 certificate if any. */
123 CFArrayRef SecCertificateCopyDNSNames(SecCertificateRef certificate);
124
125 /* Return an array of CFStringRefs representing the email addresses in the
126 certificate if any. */
127 CFArrayRef SecCertificateCopyRFC822Names(SecCertificateRef certificate);
128
129 /* Return an array of CFStringRefs representing the common names in the
130 certificates subject if any. */
131 CFArrayRef SecCertificateCopyCommonNames(SecCertificateRef certificate);
132
133 /* Return an array of CFStringRefs representing the organization in the
134 certificate's subject if any. */
135 CFArrayRef SecCertificateCopyOrganization(SecCertificateRef certificate);
136
137 /* Return an array of CFStringRefs representing the NTPrincipalNames in the
138 certificate if any. */
139 CFArrayRef SecCertificateCopyNTPrincipalNames(SecCertificateRef certificate);
140
141 /* Return a string formatted according to RFC 2253 representing the complete
142 subject of certificate. */
143 CFStringRef SecCertificateCopySubjectString(SecCertificateRef certificate);
144
145 /* Return a string with the company name of an ev leaf certificate. */
146 CFStringRef SecCertificateCopyCompanyName(SecCertificateRef certificate);
147
148 /* X.509 Certificate Version: 1, 2 or 3. */
149 CFIndex SecCertificateVersion(SecCertificateRef certificate);
150 CFAbsoluteTime SecCertificateNotValidBefore(SecCertificateRef certificate);
151 CFAbsoluteTime SecCertificateNotValidAfter(SecCertificateRef certificate);
152
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);
156
157 SecKeyUsage SecCertificateGetKeyUsage(SecCertificateRef certificate);
158
159 /* Returns an array of CFDataRefs for all extended key usage oids or NULL */
160 CFArrayRef SecCertificateCopyExtendedKeyUsage(SecCertificateRef certificate);
161
162 /* Returns a certificate from a pem blob */
163 SecCertificateRef SecCertificateCreateWithPEM(CFAllocatorRef allocator,
164 CFDataRef pem_certificate);
165
166 /* Return an array of CFDataRefs from an array of SecCertificateRefs. */
167 CFArrayRef SecCertificateArrayCopyDataArray(CFArrayRef certificates);
168
169 /* Return an array of SecCertificateRefs from an array of CFDataRefs. */
170 CFArrayRef SecCertificateDataArrayCopyArray(CFArrayRef certificates);
171
172
173 #if defined(__cplusplus)
174 }
175 #endif
176
177 #endif /* !_SECURITY_SECCERTIFICATEPRIV_H_ */