2 * Copyright (c) 2007-2019 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 SecCertificateInternal
28 #ifndef _SECURITY_SECCERTIFICATEINTERNAL_H_
29 #define _SECURITY_SECCERTIFICATEINTERNAL_H_
31 #include <TargetConditionals.h>
32 #include <libDER/DER_Keys.h>
34 #include <Security/SecBase.h>
35 #include <Security/SecCertificatePriv.h>
37 #include <Security/certextensions.h>
39 // This file can only be included under the ios view of the headers.
40 // If you're not under that view, we'll forward declare the things you need here.
41 #if SECURITY_PROJECT_TAPI_HACKS && SEC_OS_OSX
46 bool pathLenConstraintPresent
;
47 uint32_t pathLenConstraint
;
48 } SecCEBasicConstraints
;
53 bool requireExplicitPolicyPresent
;
54 uint32_t requireExplicitPolicy
;
55 bool inhibitPolicyMappingPresent
;
56 uint32_t inhibitPolicyMapping
;
57 } SecCEPolicyConstraints
;
60 DERItem policyIdentifier
;
61 DERItem policyQualifiers
;
62 } SecCEPolicyInformation
;
67 size_t numPolicies
; // size of *policies;
68 SecCEPolicyInformation
*policies
;
69 } SecCECertificatePolicies
;
72 DERItem issuerDomainPolicy
;
73 DERItem subjectDomainPolicy
;
79 size_t numMappings
; // size of *mappings;
80 SecCEPolicyMapping
*mappings
;
81 } SecCEPolicyMappings
;
87 } SecCEInhibitAnyPolicy
;
93 CFDataRef
SecCertificateGetAuthorityKeyID(SecCertificateRef certificate
);
94 CFDataRef
SecCertificateGetSubjectKeyID(SecCertificateRef certificate
);
96 /* Return an array of CFURLRefs each of which is an crl distribution point for
98 CFArrayRef
SecCertificateGetCRLDistributionPoints(SecCertificateRef certificate
);
100 /* Return an array of CFURLRefs each of which is an caIssuer for this
102 CFArrayRef
SecCertificateGetCAIssuers(SecCertificateRef certificate
);
104 /* Dump certificate for debugging. */
105 void SecCertificateShow(SecCertificateRef certificate
);
107 /* Return the normalized name or NULL if it fails to parse */
108 CFDataRef
SecDistinguishedNameCopyNormalizedContent(CFDataRef distinguished_name
);
110 /* Return true iff the certificate has a subject. */
111 bool SecCertificateHasSubject(SecCertificateRef certificate
);
112 /* Return true iff the certificate has a critical subject alt name. */
113 bool SecCertificateHasCriticalSubjectAltName(SecCertificateRef certificate
);
115 /* Return the contents of the SubjectAltName extension. */
116 const DERItem
* SecCertificateGetSubjectAltName(SecCertificateRef certificate
);
118 /* Return true if certificate contains one or more critical extensions we
119 are unable to parse. */
120 bool SecCertificateHasUnknownCriticalExtension(SecCertificateRef certificate
);
122 /* Return an attribute dictionary used to store this item in a keychain. */
123 CFDictionaryRef
SecCertificateCopyAttributeDictionary(
124 SecCertificateRef certificate
);
126 /* Return a certificate from the attribute dictionary that was used to store
127 this item in a keychain. */
128 SecCertificateRef
SecCertificateCreateFromAttributeDictionary(
129 CFDictionaryRef refAttributes
);
131 /* Return a SecKeyRef for the public key embedded in the cert. */
133 SecKeyRef
SecCertificateCopyPublicKey_ios(SecCertificateRef certificate
)
134 __OSX_DEPRECATED(__MAC_10_12
, __MAC_10_14
, "Use SecCertificateCopyKey instead.");
137 /* Return the SecCEBasicConstraints extension for this certificate if it
139 const SecCEBasicConstraints
*
140 SecCertificateGetBasicConstraints(SecCertificateRef certificate
);
142 /* Returns array of CFDataRefs containing the generalNames that are
143 Permitted Subtree Name Constraints for this certificate if it has
145 CFArrayRef
SecCertificateGetPermittedSubtrees(SecCertificateRef certificate
);
147 /* Returns array of CFDataRefs containing the generalNames that are
148 Excluded Subtree Name Constraints for this certificate if it has
150 CFArrayRef
SecCertificateGetExcludedSubtrees(SecCertificateRef certificate
);
152 /* Return the SecCEPolicyConstraints extension for this certificate if it
154 const SecCEPolicyConstraints
*
155 SecCertificateGetPolicyConstraints(SecCertificateRef certificate
);
157 /* Return a dictionary from CFDataRef to CFArrayRef of CFDataRef
158 representing the policyMapping extension of this certificate. */
159 const SecCEPolicyMappings
*
160 SecCertificateGetPolicyMappings(SecCertificateRef certificate
);
162 /* Return the SecCECertificatePolicies extension for this certificate if it
164 const SecCECertificatePolicies
*
165 SecCertificateGetCertificatePolicies(SecCertificateRef certificate
);
167 /* Returns UINT32_MAX if InhibitAnyPolicy extension is not present or invalid,
168 returns the value of the SkipCerts field of the InhibitAnyPolicy extension
170 const SecCEInhibitAnyPolicy
*
171 SecCertificateGetInhibitAnyPolicySkipCerts(SecCertificateRef certificate
);
173 /* Return the public key algorithm and parameters for certificate. */
174 const DERAlgorithmId
*SecCertificateGetPublicKeyAlgorithm(
175 SecCertificateRef certificate
);
177 /* Return the raw public key data for certificate. */
178 const DERItem
*SecCertificateGetPublicKeyData(SecCertificateRef certificate
);
180 /* Return legacy property values for use by SecCertificateCopyValues. */
181 CFArrayRef
SecCertificateCopyLegacyProperties(SecCertificateRef certificate
);
184 // MARK: Certificate Operations
186 OSStatus
SecCertificateIsSignedBy(SecCertificateRef certificate
,
187 SecKeyRef issuerKey
);
189 #ifndef SECURITY_PROJECT_TAPI_HACKS
190 void appendProperty(CFMutableArrayRef properties
, CFStringRef propertyType
,
191 CFStringRef label
, CFStringRef localizedLabel
, CFTypeRef value
, bool localized
);
194 /* Utility functions. */
195 CFStringRef
SecDERItemCopyOIDDecimalRepresentation(CFAllocatorRef allocator
,
198 #ifndef SECURITY_PROJECT_TAPI_HACKS
199 CFDataRef
createNormalizedX501Name(CFAllocatorRef allocator
,
200 const DERItem
*x501name
);
203 /* Decode a choice of UTCTime or GeneralizedTime to a CFAbsoluteTime. Return
204 an absoluteTime if the date was valid and properly decoded. Return
205 NULL_TIME otherwise. */
206 CFAbsoluteTime
SecAbsoluteTimeFromDateContent(DERTag tag
, const uint8_t *bytes
,
209 bool SecCertificateHasMarkerExtension(SecCertificateRef certificate
, CFTypeRef oid
);
211 bool SecCertificateHasOCSPNoCheckMarkerExtension(SecCertificateRef certificate
);
213 typedef OSStatus (*parseGeneralNameCallback
)(void *context
,
214 SecCEGeneralNameType type
, const DERItem
*value
);
215 OSStatus
SecCertificateParseGeneralNameContentProperty(DERTag tag
,
216 const DERItem
*generalNameContent
,
217 void *context
, parseGeneralNameCallback callback
);
219 OSStatus
SecCertificateParseGeneralNames(const DERItem
*generalNames
, void *context
,
220 parseGeneralNameCallback callback
);
222 CFArrayRef
SecCertificateCopyOrganizationFromX501NameContent(const DERItem
*nameContent
);
224 bool SecCertificateIsWeakKey(SecCertificateRef certificate
);
225 bool SecCertificateIsAtLeastMinKeySize(SecCertificateRef certificate
,
226 CFDictionaryRef keySizes
);
227 bool SecCertificateIsStrongKey(SecCertificateRef certificate
);
229 extern const CFStringRef kSecSignatureDigestAlgorithmUnknown
;
230 #ifndef SECURITY_PROJECT_TAPI_HACKS
231 extern const CFStringRef kSecSignatureDigestAlgorithmMD2
;
232 extern const CFStringRef kSecSignatureDigestAlgorithmMD4
;
233 extern const CFStringRef kSecSignatureDigestAlgorithmMD5
;
234 extern const CFStringRef kSecSignatureDigestAlgorithmSHA1
;
235 extern const CFStringRef kSecSignatureDigestAlgorithmSHA224
;
236 extern const CFStringRef kSecSignatureDigestAlgorithmSHA256
;
237 extern const CFStringRef kSecSignatureDigestAlgorithmSHA384
;
238 extern const CFStringRef kSecSignatureDigestAlgorithmSHA512
;
241 bool SecCertificateIsWeakHash(SecCertificateRef certificate
);
243 CFDataRef
SecCertificateCreateOidDataFromString(CFAllocatorRef allocator
, CFStringRef string
);
244 bool SecCertificateIsOidString(CFStringRef oid
);
246 DERItem
*SecCertificateGetExtensionValue(SecCertificateRef certificate
, CFTypeRef oid
);
248 CFArrayRef
SecCertificateCopyDNSNamesFromSubject(SecCertificateRef certificate
);
249 CFArrayRef
SecCertificateCopyIPAddressesFromSubject(SecCertificateRef certificate
);
250 CFArrayRef
SecCertificateCopyRFC822NamesFromSubject(SecCertificateRef certificate
);
252 CFArrayRef
SecCertificateCopyDNSNamesFromSAN(SecCertificateRef certificate
);
254 CFIndex
SecCertificateGetUnparseableKnownExtension(SecCertificateRef certificate
);
258 #endif /* !_SECURITY_SECCERTIFICATEINTERNAL_H_ */