2 * Copyright (c) 2007-2015 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 * SecPolicy.c - Implementation of various X.509 certificate trust policies
28 #include <Security/SecPolicyInternal.h>
29 #include <Security/SecPolicyPriv.h>
30 #include <AssertMacros.h>
32 #include <utilities/debugging.h>
33 #include <Security/SecInternal.h>
34 #include <CoreFoundation/CFDictionary.h>
35 #include <CoreFoundation/CFNumber.h>
36 #include <CoreFoundation/CFRuntime.h>
37 #include <CoreFoundation/CFString.h>
38 #include <CoreFoundation/CFTimeZone.h>
39 #include <Security/SecCertificateInternal.h>
40 #include <Security/SecCertificatePriv.h>
41 #include <Security/SecItem.h>
42 #include <libDER/oidsPriv.h>
43 #include <utilities/SecCFError.h>
44 #include <utilities/SecCFWrappers.h>
45 #include <utilities/array_size.h>
46 #include <ipc/securityd_client.h>
48 #include <utilities/SecInternalReleasePriv.h>
50 /********************************************************
51 **************** SecPolicy Constants *******************
52 ********************************************************/
54 // MARK: SecPolicy Constants
56 #define SEC_CONST_DECL(k,v) const CFStringRef k = CFSTR(v);
58 /********************************************************
59 ************** Unverified Leaf Checks ******************
60 ********************************************************/
61 SEC_CONST_DECL (kSecPolicyCheckSSLHostname
, "SSLHostname");
62 SEC_CONST_DECL (kSecPolicyCheckEmail
, "email");
64 /* Checks that the issuer of the leaf has exactly one Common Name and that it
65 matches the specified string. */
66 SEC_CONST_DECL (kSecPolicyCheckIssuerCommonName
, "IssuerCommonName");
68 /* Checks that the leaf has exactly one Common Name and that it
69 matches the specified string. */
70 SEC_CONST_DECL (kSecPolicyCheckSubjectCommonName
, "SubjectCommonName");
72 /* Checks that the leaf has exactly one Common Name and that it has the
73 specified string as a prefix. */
74 SEC_CONST_DECL (kSecPolicyCheckSubjectCommonNamePrefix
, "SubjectCommonNamePrefix");
76 /* Checks that the leaf has exactly one Common Name and that it
77 matches the specified "<string>" or "TEST <string> TEST". */
78 SEC_CONST_DECL (kSecPolicyCheckSubjectCommonNameTEST
, "SubjectCommonNameTEST");
80 /* Checks that the leaf has exactly one Organization and that it
81 matches the specified string. */
82 SEC_CONST_DECL (kSecPolicyCheckSubjectOrganization
, "SubjectOrganization");
84 /* Checks that the leaf has exactly one Organizational Unit and that it
85 matches the specified string. */
86 SEC_CONST_DECL (kSecPolicyCheckSubjectOrganizationalUnit
, "SubjectOrganizationalUnit");
88 /* Check that the leaf is not valid before the specified date (or verifyDate
89 if none is provided?). */
90 SEC_CONST_DECL (kSecPolicyCheckNotValidBefore
, "NotValidBefore");
92 SEC_CONST_DECL (kSecPolicyCheckEAPTrustedServerNames
, "EAPTrustedServerNames");
94 SEC_CONST_DECL (kSecPolicyCheckCertificatePolicy
, "CertificatePolicy");
96 SEC_CONST_DECL (kSecPolicyCheckLeafMarkerOid
, "CheckLeafMarkerOid");
97 SEC_CONST_DECL (kSecPolicyCheckLeafMarkerOidWithoutValueCheck
, "CheckLeafMarkerOidNoValueCheck");
98 SEC_CONST_DECL (kSecPolicyCheckLeafMarkersProdAndQA
, "CheckLeafMarkersProdAndQA");
100 /* options for kSecPolicyCheckLeafMarkersProdAndQA */
101 SEC_CONST_DECL (kSecPolicyLeafMarkerProd
, "ProdMarker");
102 SEC_CONST_DECL (kSecPolicyLeafMarkerQA
, "QAMarker");
105 /* Check for basic constraints on leaf to be valid. (rfc5280 check) */
106 SEC_CONST_DECL (kSecPolicyCheckLeafBasicConstraints
, "LeafBasicContraints");
109 SEC_CONST_DECL (kSecPolicyCheckBlackListedLeaf
, "BlackListedLeaf");
110 SEC_CONST_DECL (kSecPolicyCheckGrayListedLeaf
, "GrayListedLeaf");
112 /********************************************************
113 *********** Unverified Intermediate Checks *************
114 ********************************************************/
115 SEC_CONST_DECL (kSecPolicyCheckKeyUsage
, "KeyUsage"); /* (rfc5280 check) */
116 SEC_CONST_DECL (kSecPolicyCheckExtendedKeyUsage
, "ExtendedKeyUsage"); /* (rfc5280 check) */
117 SEC_CONST_DECL (kSecPolicyCheckBasicConstraints
, "BasicConstraints"); /* (rfc5280 check) */
118 SEC_CONST_DECL (kSecPolicyCheckQualifiedCertStatements
, "QualifiedCertStatements"); /* (rfc5280 check) */
119 SEC_CONST_DECL (kSecPolicyCheckIntermediateSPKISHA256
, "IntermediateSPKISHA256");
120 SEC_CONST_DECL (kSecPolicyCheckIntermediateEKU
, "IntermediateEKU");
121 SEC_CONST_DECL (kSecPolicyCheckIntermediateMarkerOid
, "CheckIntermediateMarkerOid");
122 SEC_CONST_DECL (kSecPolicyCheckIntermediateOrganization
, "CheckIntermediateOrganization");
123 SEC_CONST_DECL (kSecPolicyCheckIntermediateCountry
, "CheckIntermediateCountry");
125 /********************************************************
126 ************** Unverified Anchor Checks ****************
127 ********************************************************/
128 SEC_CONST_DECL (kSecPolicyCheckAnchorSHA1
, "AnchorSHA1");
129 SEC_CONST_DECL (kSecPolicyCheckAnchorSHA256
, "AnchorSHA256");
131 /* Fake key for isAnchored check. */
132 SEC_CONST_DECL (kSecPolicyCheckAnchorTrusted
, "AnchorTrusted");
134 /* Anchor is one of the apple trust anchors */
135 SEC_CONST_DECL (kSecPolicyCheckAnchorApple
, "AnchorApple");
137 /* options for kSecPolicyCheckAnchorApple */
138 SEC_CONST_DECL (kSecPolicyAppleAnchorIncludeTestRoots
, "AnchorAppleTestRoots");
140 /********************************************************
141 *********** Unverified Certificate Checks **************
142 ********************************************************/
143 /* Unverified Certificate Checks (any of the above) */
144 SEC_CONST_DECL (kSecPolicyCheckNonEmptySubject
, "NonEmptySubject");
145 SEC_CONST_DECL (kSecPolicyCheckIdLinkage
, "IdLinkage") /* (rfc5280 check) */
146 SEC_CONST_DECL (kSecPolicyCheckValidIntermediates
, "ValidIntermediates");
147 SEC_CONST_DECL (kSecPolicyCheckValidLeaf
, "ValidLeaf");
148 SEC_CONST_DECL (kSecPolicyCheckValidRoot
, "ValidRoot");
149 SEC_CONST_DECL (kSecPolicyCheckWeakIntermediates
, "WeakIntermediates");
150 SEC_CONST_DECL (kSecPolicyCheckWeakLeaf
, "WeakLeaf");
151 SEC_CONST_DECL (kSecPolicyCheckWeakRoot
, "WeakRoot");
152 SEC_CONST_DECL (kSecPolicyCheckKeySize
, "KeySize");
153 SEC_CONST_DECL (kSecPolicyCheckSignatureHashAlgorithms
, "SignatureHashAlgorithms");
155 /********************************************************
156 **************** Verified Path Checks ******************
157 ********************************************************/
158 /* (rfc5280 check) Ideally we should dynamically track all the extensions
159 we processed for each certificate and fail this test if any critical
160 extensions remain. */
161 SEC_CONST_DECL (kSecPolicyCheckCriticalExtensions
, "CriticalExtensions");
163 /* Check that the certificate chain length matches the specificed CFNumberRef
165 SEC_CONST_DECL (kSecPolicyCheckChainLength
, "ChainLength");
167 /* (rfc5280 check) */
168 SEC_CONST_DECL (kSecPolicyCheckBasicCertificateProcessing
, "BasicCertificateProcessing");
170 /* Check Certificate Transparency if specified. */
171 SEC_CONST_DECL (kSecPolicyCheckCertificateTransparency
, "CertificateTransparency");
173 SEC_CONST_DECL (kSecPolicyCheckGrayListedKey
, "GrayListedKey");
174 SEC_CONST_DECL (kSecPolicyCheckBlackListedKey
, "BlackListedKey");
176 SEC_CONST_DECL (kSecPolicyCheckUsageConstraints
, "UsageConstraints");
178 SEC_CONST_DECL (kSecPolicyCheckSystemTrustedWeakHash
, "SystemTrustedWeakHash");
180 /********************************************************
181 ******************* Feature toggles ********************
182 ********************************************************/
184 /* Check revocation if specified. */
185 SEC_CONST_DECL (kSecPolicyCheckExtendedValidation
, "ExtendedValidation");
186 SEC_CONST_DECL (kSecPolicyCheckRevocation
, "Revocation");
187 SEC_CONST_DECL (kSecPolicyCheckRevocationResponseRequired
, "RevocationResponseRequired");
188 SEC_CONST_DECL (kSecPolicyCheckRevocationOCSP
, "OCSP");
189 SEC_CONST_DECL (kSecPolicyCheckRevocationCRL
, "CRL");
190 SEC_CONST_DECL (kSecPolicyCheckRevocationAny
, "AnyRevocationMethod");
191 SEC_CONST_DECL (kSecPolicyCheckRevocationOnline
, "Online");
193 /* If present and true, we never go out to the network for anything
194 (OCSP, CRL or CA Issuer checking) but just used cached data instead. */
195 SEC_CONST_DECL (kSecPolicyCheckNoNetworkAccess
, "NoNetworkAccess");
197 /* Public policy names. */
198 SEC_CONST_DECL (kSecPolicyAppleX509Basic
, "1.2.840.113635.100.1.2");
199 SEC_CONST_DECL (kSecPolicyAppleSSL
, "1.2.840.113635.100.1.3");
200 SEC_CONST_DECL (kSecPolicyAppleSMIME
, "1.2.840.113635.100.1.8");
201 SEC_CONST_DECL (kSecPolicyAppleEAP
, "1.2.840.113635.100.1.9");
202 SEC_CONST_DECL (kSecPolicyAppleSWUpdateSigning
, "1.2.840.113635.100.1.10");
203 SEC_CONST_DECL (kSecPolicyAppleIPsec
, "1.2.840.113635.100.1.11");
204 SEC_CONST_DECL (kSecPolicyApplePKINITClient
, "1.2.840.113635.100.1.14");
205 SEC_CONST_DECL (kSecPolicyApplePKINITServer
, "1.2.840.113635.100.1.15");
206 SEC_CONST_DECL (kSecPolicyAppleCodeSigning
, "1.2.840.113635.100.1.16");
207 SEC_CONST_DECL (kSecPolicyApplePackageSigning
, "1.2.840.113635.100.1.17");
208 SEC_CONST_DECL (kSecPolicyAppleIDValidation
, "1.2.840.113635.100.1.18");
209 SEC_CONST_DECL (kSecPolicyMacAppStoreReceipt
, "1.2.840.113635.100.1.19");
210 SEC_CONST_DECL (kSecPolicyAppleTimeStamping
, "1.2.840.113635.100.1.20");
211 SEC_CONST_DECL (kSecPolicyAppleRevocation
, "1.2.840.113635.100.1.21");
212 SEC_CONST_DECL (kSecPolicyApplePassbookSigning
, "1.2.840.113635.100.1.22");
213 SEC_CONST_DECL (kSecPolicyAppleMobileStore
, "1.2.840.113635.100.1.23");
214 SEC_CONST_DECL (kSecPolicyAppleEscrowService
, "1.2.840.113635.100.1.24");
215 SEC_CONST_DECL (kSecPolicyAppleProfileSigner
, "1.2.840.113635.100.1.25");
216 SEC_CONST_DECL (kSecPolicyAppleQAProfileSigner
, "1.2.840.113635.100.1.26");
217 SEC_CONST_DECL (kSecPolicyAppleTestMobileStore
, "1.2.840.113635.100.1.27");
218 SEC_CONST_DECL (kSecPolicyAppleOTAPKISigner
, "1.2.840.113635.100.1.28");
219 SEC_CONST_DECL (kSecPolicyAppleTestOTAPKISigner
, "1.2.840.113635.100.1.29");
220 SEC_CONST_DECL (kSecPolicyAppleIDValidationRecordSigningPolicy
, "1.2.840.113635.100.1.30");
221 SEC_CONST_DECL (kSecPolicyAppleIDValidationRecordSigning
, "1.2.840.113635.100.1.30");
222 SEC_CONST_DECL (kSecPolicyAppleSMPEncryption
, "1.2.840.113635.100.1.31");
223 SEC_CONST_DECL (kSecPolicyAppleTestSMPEncryption
, "1.2.840.113635.100.1.32");
224 SEC_CONST_DECL (kSecPolicyAppleServerAuthentication
, "1.2.840.113635.100.1.33");
225 SEC_CONST_DECL (kSecPolicyApplePCSEscrowService
, "1.2.840.113635.100.1.34");
226 SEC_CONST_DECL (kSecPolicyApplePPQSigning
, "1.2.840.113635.100.1.35");
227 SEC_CONST_DECL (kSecPolicyAppleTestPPQSigning
, "1.2.840.113635.100.1.36");
228 // Not in use. Use kSecPolicyAppleTVOSApplicationSigning instead.
229 // SEC_CONST_DECL (kSecPolicyAppleATVAppSigning, "1.2.840.113635.100.1.37");
230 // SEC_CONST_DECL (kSecPolicyAppleTestATVAppSigning, "1.2.840.113635.100.1.38");
231 SEC_CONST_DECL (kSecPolicyApplePayIssuerEncryption
, "1.2.840.113635.100.1.39");
232 SEC_CONST_DECL (kSecPolicyAppleOSXProvisioningProfileSigning
, "1.2.840.113635.100.1.40");
233 SEC_CONST_DECL (kSecPolicyAppleATVVPNProfileSigning
, "1.2.840.113635.100.1.41");
234 SEC_CONST_DECL (kSecPolicyAppleAST2DiagnosticsServerAuth
, "1.2.840.113635.100.1.42");
235 SEC_CONST_DECL (kSecPolicyAppleEscrowProxyServerAuth
, "1.2.840.113635.100.1.43");
236 SEC_CONST_DECL (kSecPolicyAppleFMiPServerAuth
, "1.2.840.113635.100.1.44");
237 SEC_CONST_DECL (kSecPolicyAppleMMCSService
, "1.2.840.113635.100.1.45");
238 SEC_CONST_DECL (kSecPolicyAppleGSService
, "1.2.840.113635.100.1.46");
239 SEC_CONST_DECL (kSecPolicyApplePPQService
, "1.2.840.113635.100.1.47");
240 SEC_CONST_DECL (kSecPolicyAppleHomeKitServerAuth
, "1.2.840.113635.100.1.48");
241 SEC_CONST_DECL (kSecPolicyAppleiPhoneActivation
, "1.2.840.113635.100.1.49");
242 SEC_CONST_DECL (kSecPolicyAppleiPhoneDeviceCertificate
, "1.2.840.113635.100.1.50");
243 SEC_CONST_DECL (kSecPolicyAppleFactoryDeviceCertificate
, "1.2.840.113635.100.1.51");
244 SEC_CONST_DECL (kSecPolicyAppleiAP
, "1.2.840.113635.100.1.52");
245 SEC_CONST_DECL (kSecPolicyAppleiTunesStoreURLBag
, "1.2.840.113635.100.1.53");
246 SEC_CONST_DECL (kSecPolicyAppleiPhoneApplicationSigning
, "1.2.840.113635.100.1.54");
247 SEC_CONST_DECL (kSecPolicyAppleiPhoneProfileApplicationSigning
, "1.2.840.113635.100.1.55");
248 SEC_CONST_DECL (kSecPolicyAppleiPhoneProvisioningProfileSigning
, "1.2.840.113635.100.1.56");
249 SEC_CONST_DECL (kSecPolicyAppleLockdownPairing
, "1.2.840.113635.100.1.57");
250 SEC_CONST_DECL (kSecPolicyAppleURLBag
, "1.2.840.113635.100.1.58");
251 SEC_CONST_DECL (kSecPolicyAppleOTATasking
, "1.2.840.113635.100.1.59");
252 SEC_CONST_DECL (kSecPolicyAppleMobileAsset
, "1.2.840.113635.100.1.60");
253 SEC_CONST_DECL (kSecPolicyAppleIDAuthority
, "1.2.840.113635.100.1.61");
254 SEC_CONST_DECL (kSecPolicyAppleGenericApplePinned
, "1.2.840.113635.100.1.62");
255 SEC_CONST_DECL (kSecPolicyAppleGenericAppleSSLPinned
, "1.2.840.113635.100.1.63");
256 SEC_CONST_DECL (kSecPolicyAppleSoftwareSigning
, "1.2.840.113635.100.1.64");
257 SEC_CONST_DECL (kSecPolicyAppleExternalDeveloper
, "1.2.840.113635.100.1.65");
258 SEC_CONST_DECL (kSecPolicyAppleOCSPSigner
, "1.2.840.113635.100.1.66");
259 SEC_CONST_DECL (kSecPolicyAppleIDSService
, "1.2.840.113635.100.1.67");
260 SEC_CONST_DECL (kSecPolicyAppleIDSServiceContext
, "1.2.840.113635.100.1.68");
261 SEC_CONST_DECL (kSecPolicyApplePushService
, "1.2.840.113635.100.1.69");
262 SEC_CONST_DECL (kSecPolicyAppleLegacyPushService
, "1.2.840.113635.100.1.70");
263 SEC_CONST_DECL (kSecPolicyAppleTVOSApplicationSigning
, "1.2.840.113635.100.1.71");
264 SEC_CONST_DECL (kSecPolicyAppleUniqueDeviceIdentifierCertificate
, "1.2.840.113635.100.1.72");
265 SEC_CONST_DECL (kSecPolicyAppleEscrowProxyCompatibilityServerAuth
, "1.2.840.113635.100.1.73");
266 SEC_CONST_DECL (kSecPolicyAppleMMCSCompatibilityServerAuth
, "1.2.840.113635.100.1.74");
267 SEC_CONST_DECL (kSecPolicyAppleSecureIOStaticAsset
, "1.2.840.113635.100.1.75");
268 SEC_CONST_DECL (kSecPolicyAppleWarsaw
, "1.2.840.113635.100.1.76");
269 SEC_CONST_DECL (kSecPolicyAppleiCloudSetupServerAuth
, "1.2.840.113635.100.1.77");
270 SEC_CONST_DECL (kSecPolicyAppleiCloudSetupCompatibilityServerAuth
, "1.2.840.113635.100.1.78");
272 SEC_CONST_DECL (kSecPolicyOid
, "SecPolicyOid");
273 SEC_CONST_DECL (kSecPolicyName
, "SecPolicyName");
274 SEC_CONST_DECL (kSecPolicyClient
, "SecPolicyClient");
275 SEC_CONST_DECL (kSecPolicyRevocationFlags
, "SecPolicyRevocationFlags");
276 SEC_CONST_DECL (kSecPolicyTeamIdentifier
, "SecPolicyTeamIdentifier");
277 SEC_CONST_DECL (kSecPolicyContext
, "SecPolicyContext");
278 SEC_CONST_DECL (kSecPolicyPolicyName
, "SecPolicyPolicyName");
279 SEC_CONST_DECL (kSecPolicyIntermediateMarkerOid
, "SecPolicyIntermediateMarkerOid");
280 SEC_CONST_DECL (kSecPolicyLeafMarkerOid
, "SecPolicyLeafMarkerOid");
281 SEC_CONST_DECL (kSecPolicyRootDigest
, "SecPolicyRootDigest");
283 SEC_CONST_DECL (kSecPolicyKU_DigitalSignature
, "CE_KU_DigitalSignature");
284 SEC_CONST_DECL (kSecPolicyKU_NonRepudiation
, "CE_KU_NonRepudiation");
285 SEC_CONST_DECL (kSecPolicyKU_KeyEncipherment
, "CE_KU_KeyEncipherment");
286 SEC_CONST_DECL (kSecPolicyKU_DataEncipherment
, "CE_KU_DataEncipherment");
287 SEC_CONST_DECL (kSecPolicyKU_KeyAgreement
, "CE_KU_KeyAgreement");
288 SEC_CONST_DECL (kSecPolicyKU_KeyCertSign
, "CE_KU_KeyCertSign");
289 SEC_CONST_DECL (kSecPolicyKU_CRLSign
, "CE_KU_CRLSign");
290 SEC_CONST_DECL (kSecPolicyKU_EncipherOnly
, "CE_KU_EncipherOnly");
291 SEC_CONST_DECL (kSecPolicyKU_DecipherOnly
, "CE_KU_DecipherOnly");
293 /* Private policy names */
294 static CFStringRef kSecPolicyNameBasicX509
= CFSTR("basicX509");
295 static CFStringRef kSecPolicyNameSSLServer
= CFSTR("sslServer");
296 static CFStringRef kSecPolicyNameSSLClient
= CFSTR("sslClient");
297 static CFStringRef kSecPolicyNameiPhoneActivation
= CFSTR("iPhoneActivation");
298 static CFStringRef kSecPolicyNameiPhoneDeviceCertificate
=
299 CFSTR("iPhoneDeviceCertificate");
300 static CFStringRef kSecPolicyNameFactoryDeviceCertificate
=
301 CFSTR("FactoryDeviceCertificate");
302 static CFStringRef kSecPolicyNameiAP
= CFSTR("iAP");
303 static CFStringRef kSecPolicyNameiTunesStoreURLBag
= CFSTR("iTunesStoreURLBag");
304 static CFStringRef kSecPolicyNameEAPServer
= CFSTR("eapServer");
305 static CFStringRef kSecPolicyNameEAPClient
= CFSTR("eapClient");
306 static CFStringRef kSecPolicyNameIPSecServer
= CFSTR("ipsecServer");
307 static CFStringRef kSecPolicyNameIPSecClient
= CFSTR("ipsecClient");
308 static CFStringRef kSecPolicyNameiPhoneApplicationSigning
=
309 CFSTR("iPhoneApplicationSigning");
310 static CFStringRef kSecPolicyNameiPhoneProfileApplicationSigning
=
311 CFSTR("iPhoneProfileApplicationSigning");
312 static CFStringRef kSecPolicyNameiPhoneProvisioningProfileSigning
=
313 CFSTR("iPhoneProvisioningProfileSigning");
314 static CFStringRef kSecPolicyNameAppleSWUpdateSigning
= CFSTR("AppleSWUpdateSigning");
315 static CFStringRef kSecPolicyNameAppleTVOSApplicationSigning
=
316 CFSTR("AppleTVApplicationSigning");
317 static CFStringRef kSecPolicyNameRevocation
= CFSTR("revocation");
318 static CFStringRef kSecPolicyNameOCSPSigner
= CFSTR("OCSPSigner");
319 static CFStringRef kSecPolicyNameSMIME
= CFSTR("SMIME");
320 static CFStringRef kSecPolicyNameCodeSigning
= CFSTR("CodeSigning");
321 static CFStringRef kSecPolicyNamePackageSigning
= CFSTR("PackageSigning");
322 static CFStringRef kSecPolicyNameLockdownPairing
= CFSTR("LockdownPairing");
323 static CFStringRef kSecPolicyNameURLBag
= CFSTR("URLBag");
324 static CFStringRef kSecPolicyNameOTATasking
= CFSTR("OTATasking");
325 static CFStringRef kSecPolicyNameMobileAsset
= CFSTR("MobileAsset");
326 static CFStringRef kSecPolicyNameAppleIDAuthority
= CFSTR("AppleIDAuthority");
327 static CFStringRef kSecPolicyNameMacAppStoreReceipt
= CFSTR("MacAppStoreReceipt");
328 static CFStringRef kSecPolicyNameAppleTimeStamping
= CFSTR("AppleTimeStamping");
329 static CFStringRef kSecPolicyNameApplePassbook
= CFSTR("ApplePassbook");
330 static CFStringRef kSecPolicyNameAppleMobileStore
= CFSTR("AppleMobileStore");
331 static CFStringRef kSecPolicyNameAppleTestMobileStore
= CFSTR("AppleTestMobileStore");
332 static CFStringRef kSecPolicyNameAppleEscrowService
= CFSTR("AppleEscrowService");
333 static CFStringRef kSecPolicyNameApplePCSEscrowService
= CFSTR("ApplePCSEscrowService");
334 static CFStringRef kSecPolicyNameAppleProfileSigner
= CFSTR("AppleProfileSigner");
335 static CFStringRef kSecPolicyNameAppleQAProfileSigner
= CFSTR("AppleQAProfileSigner");
336 static CFStringRef kSecPolicyNameAppleOTAPKIAssetSigner
= CFSTR("AppleOTAPKIAssetSigner");
337 static CFStringRef kSecPolicyNameAppleTestOTAPKIAssetSigner
= CFSTR("AppleTestOTAPKIAssetSigner");
338 static CFStringRef kSecPolicyNameAppleIDValidationRecordSigningPolicy
= CFSTR("AppleIDValidationRecordSigningPolicy");
339 static CFStringRef kSecPolicyNameApplePayIssuerEncryption
= CFSTR("ApplePayIssuerEncryption");
340 static CFStringRef kSecPolicyNameAppleOSXProvisioningProfileSigning
= CFSTR("AppleOSXProvisioningProfileSigning");
341 static CFStringRef kSecPolicyNameAppleATVVPNProfileSigning
= CFSTR("AppleATVVPNProfileSigning");
342 static CFStringRef kSecPolicyNameAppleAST2Service
= CFSTR("AST2");
343 static CFStringRef kSecPolicyNameAppleEscrowProxyService
= CFSTR("Escrow");
344 static CFStringRef kSecPolicyNameAppleFMiPService
= CFSTR("FMiP");
345 static CFStringRef kSecPolicyNameAppleHomeKitServerAuth
= CFSTR("HomeKit");
346 static CFStringRef kSecPolicyNameAppleExternalDeveloper
= CFSTR("Developer");
347 static CFStringRef kSecPolicyNameAppleSoftwareSigning
= CFSTR("SoftwareSigning");
348 static CFStringRef kSecPolicyNameAppleSMPEncryption
= CFSTR("AppleSMPEncryption");
349 static CFStringRef kSecPolicyNameAppleTestSMPEncryption
= CFSTR("AppleTestSMPEncryption");
350 static CFStringRef kSecPolicyNameApplePPQSigning
= CFSTR("ApplePPQSigning");
351 static CFStringRef kSecPolicyNameAppleTestPPQSigning
= CFSTR("AppleTestPPQSigning");
352 static CFStringRef kSecPolicyNameAppleLegacyPushService
= CFSTR("AppleLegacyPushService");
353 static CFStringRef kSecPolicyNameAppleSSLService
= CFSTR("AppleSSLService");
354 static CFStringRef kSecPolicyNameApplePushService
= CFSTR("APN");
355 static CFStringRef kSecPolicyNameAppleIDSServiceContext
= CFSTR("IDS");
356 static CFStringRef kSecPolicyNameAppleGSService
= CFSTR("GS");
357 static CFStringRef kSecPolicyNameAppleMMCSService
= CFSTR("MMCS");
358 static CFStringRef kSecPolicyNameApplePPQService
= CFSTR("PPQ");
359 static CFStringRef kSecPolicyNameAppleUniqueDeviceCertificate
= CFSTR("UCRT");
360 static CFStringRef kSecPolicyNameAppleSecureIOStaticAsset
= CFSTR("SecureIOStaticAsset");
361 static CFStringRef kSecPolicyNameAppleWarsaw
= CFSTR("Warsaw");
362 static CFStringRef kSecPolicyNameAppleiCloudSetupService
= CFSTR("iCloudSetup");
365 /* Policies will now change to multiple categories of checks.
367 IDEA Store partial valid policy tree in each chain? Result tree pruning might make this not feasible unless you can pretend to prune the tree without actually deleting nodes and somehow still have shable nodes with parent chains (this assumes that chains will be built as cached things from the root down), and we can build something equivalent to rfc5280 in a tree of certs. So we need to maintain a cache of leaf->chain with this certificate as any_ca_cert->tree. Revocation status caching can be done in this cache as well, so maybe the cache should be in sqlite3, or at least written there before exit and querying of the cache could be done first on the in core (possibly CF or custom tree like structure) and secondarly on the sqlite3 backed store. We should choose the lowest memory footprint solution in my mind, while choosing a sqlite3 cache size that gives us a resonable io usage pattern.
368 NOTE no certificate can be an intermediate unless it is X.509V3 and it has a basicConstraints extension with isCA set to true. This can be used to classify certs for caching purposes.
370 kSecPolicySLCheck Static Subscriber Certificate Checks
371 kSecPolicySICheck Static Subsidiary CA Checks
372 kSecPolicySACheck Static Anchor Checks
374 kSecPolicyDLCheck Dynamic Subscriber Certificate Checks
375 kSecPolicyDICheck Dynamic Subsidiary CA Checks
376 kSecPolicyDACheck Dynamic Anchor Checks ? not yet needed other than to
377 possibly exclude in a exception template (but those should still be per
378 certificate --- i.o.w. exceptions (or a database backed multiple role/user
379 trust store of some sort) and policies are 2 different things and this
380 text is about policies.
382 All static checks are only allowed to consider the certificate in isolation,
383 just given the position in the chain or the cert (leaf, intermidate, root).
384 dynamic checks can make determinations about the chain as a whole.
386 Static Subscriber Certificate Checks will be done up front before the
387 chainbuilder is even instantiated. If they fail and details aren't required
388 by the client (if no exceptions were present for this certificate) we could
389 short circuit fail the evaluation.
390 IDEA: These checks can dynamically add new checks...[needs work]
391 ALTERNATIVE: A policy can have one or more sub-policies. Each sub-policy will be evaluated only after the parent policy succeeds. Subpolicies can be either required (making the parent policy fail) or optional making the parent policy succeed, but allowing the chainbuilder to continue building chains after an optional subpolicy failure in search of a chain for which the subpolicy also succeeded. Subpolicies can be dynamically added to the policy evaluation context tree (a tree with a node for every node in the certificate path. This tree however is from the leaf up stored in the SecCertificatePathRef objects themselves possibly - requiring a separate shared subtree of nodes for the underlying certificate state tree.) by a parent policy at any stage, since the subpolicy evaluation only starts after
392 will have a key in the info (or even details and make info client side generated from info to indicate the success or failure of optional subpolicies) tree the value of which is an
393 equivalent subtree from that level down. So SSL has EV as a subpolicy, but
394 EV dynamically enables the ocsp or crl or dcrl or any combination thereof subpolicies.
396 Static Subsidiary CA Checks will be used by the chain-builder to choose the
397 best parents to evaluate first. This feature is currently already implemented
398 but with a hardcoded is_valid(verifyTime) check. Instead we will evaluate all
399 Static Subsidiary CA Checks. The results of these checks for purposes of
400 generating details could be cached in the SecCertificatePathRefs themselves, or we can short circuit fail and recalc details on demand later.
402 Static Anchor Checks can do things like populate the chainbuilder level context value of the initial_valid_policy_tree with a particular anchors list of ev policies it represents or modify inputs to the policy itself.
404 Dynamic Subscriber Certificate Checks These can do things like check for EV policy conformance based on the valid_policy_tree at the end of the certificate evaluation, or based on things like the pathlen, etc. in the chain validation context.
406 Dynamic Subsidiary CA Checks might not be needed to have custom
407 implementations, since they are all done as part of the rfc5280 checks now.
408 This assumes that checks like issuer common name includes 'foo' are
409 implmented as Static Subscriber Certificate Checks instead.
411 Dynamic Anchor Checks might include EV type checks or chain validation context seeding as well, allthough we might be able to do them as static checks to seed the chain validation context instead.
414 Questions/Notes: Do we need to dynamically add new policies? If policy static checks fail and policy is optional we don't even run policy dynamic checks nor do we compute subpolicy values. So if the static check of the leaf for EV fails we skip the rest of the EV style checks and instead don't run the revocation subpolicy of the ev policy.
416 If an optional subpolicy s_p has a required subpolicy r_s_p. Then success of s_p will cause the entire chain evaluation to fail if r_s_p fails.
418 All policies static revocation checks are run at the appropriate phase in the evaluation. static leaf checks are done before chainbuilding even starts. static intermediate checks are done in the chainbuilder for each cadidate parent certificate. If all policies pass we check the signatures. We reject the whole chain if that step fails. Otherwise we add the path to builder->candidatePaths. If the top level policy or a required subpolicy or a required subpolicy of a successful subpolicy fails we stick the chain at the end of the expiredPaths, if one of the optional subpolicies fail, we stick the chain at the start of expiredPaths so it's considered first after all real candidatePaths have been processed.
420 Static revocation policy checks could check the passed in ocspresponses or even the local cache, though the latter is probably best left for the dynamic phase.
422 The same rules that apply above to the adding paths to candidatePaths v/s expiredPaths apply to dynamicpolicy checks, except that we don't remember failures anymore, we reject them.
424 We need to remember the best successful chain we find, where best is defined by: satisfies as many optional policies as possible.
426 Chain building ends when either we find a chain that matches all optional and required policies, or we run out of chains to build. Another case is if we run out of candiate paths but we already have a chain that matches at least the top level and required subpolicies. In that case we don't even consider any expiredPaths. Example: we find a valid SSL chain (top level policy), but no partial chain we constructed satisfied the static checks of the ev subpolicy, or the required revocation sub-subpolicy of the ev policy.
428 In order for this to work well with exceptions on subpolicies, we'd need to move the validation of exceptions to the server, something we'd do anyway if we had full on truststore. In this case exceptions would be live in the failure callback for a trust check.
430 Example sectrust operation in psuedocode:
434 new builder(verifyTime, certificates, anchors, anchorsOnly, policies);
435 chain = builder.subscriber_only_chain;
436 foreach (policy in policies{kSecPolicySLCheck}) {
437 foreach(check in policy)
438 SecPolicyRunCheck(builder, chain, check, details);
439 foreach (subpolicy in policy) {
440 check_policy(builder, chain, subpolicy, details{subpolicy.name})
442 propagate_subpolicy_results(builder, chain, details);
444 while (chain = builder.next) {
445 for (depth = 0; p_d = policies.at_depth(depth),
446 d_p_d = dynamic_policies.at_depth(depth), p_d || d_p_d; ++depth)
448 // Modify SecPathBuilderIsPartial() to
449 // run builder_check(buildier, policies, kSecPolicySICheck) instead
450 // of SecCertificateIsValid. Also rename considerExpired to
451 // considerSIFailures.
452 foreach (policy in p_d) {
453 check_policy(builder, chain, policy, kSecPolicySICheck, depth);
455 /// Recalculate since the static checks might have added new dynamic
457 d_p_d = dynamic_policies.at_depth(depth);
458 foreach (policy in d_p_d) {
459 check_policy(builder, chain, policy, kSecPolicySICheck, depth);
461 if (chain.is_anchored) {
462 foreach (policy in p_d) {
463 check_policy(builder, chain, policy, kSecPolicySACheck, depth);
465 foreach (policy in d_p_d) {
466 check_policy(builder, chain, policy, kSecPolicySACheck, depth);
468 foreach (policy in p_d) {
469 check_policy(builder, chain, policy, kSecPolicyDACheck, depth);
471 foreach (policy in d_p_d) {
472 check_policy(builder, chain, policy, kSecPolicyDACheck, depth);
475 foreach (policy in policies) {
476 check_policy(builder, chain, policy, kSecPolicySACheck, depth);
477 check_policy(builder, chain, policy, kSecPolicyDACheck, depth);
479 foreach (policy in policies{kSecPolicySDCheck}) {
484 check_policy(builder, chain, policy, check_class, details, depth) {
486 foreach(check in policy{check_class}) {
487 SecPolicyRunCheck(builder, chain, check, details);
491 foreach (subpolicy in policy) {
492 if (!check_policy(builder, chain, subpolicy, check_class,
493 details{subpolicy.name}) && subpolicy.is_required, depth)
497 propagate_subpolicy_results(builder, chain, details);
504 #define kSecPolicySHA1Size 20
505 #define kSecPolicySHA256Size 32
506 __unused
const UInt8 kAppleCASHA1
[kSecPolicySHA1Size
] = {
507 0x61, 0x1E, 0x5B, 0x66, 0x2C, 0x59, 0x3A, 0x08, 0xFF, 0x58,
508 0xD1, 0x4A, 0xE2, 0x24, 0x52, 0xD1, 0x98, 0xDF, 0x6C, 0x60
511 __unused
static const UInt8 kAppleTESTCASHA1
[kSecPolicySHA1Size
] = {
512 0xbc, 0x30, 0x55, 0xc8, 0xc8, 0xd3, 0x48, 0x3f, 0xf4, 0x8d,
513 0xfe, 0x3d, 0x51, 0x75, 0x31, 0xc9, 0xf4, 0xd7, 0x4a, 0xf7
516 static const UInt8 kITMSCASHA1
[kSecPolicySHA1Size
] = {
517 0x1D, 0x33, 0x42, 0x46, 0x8B, 0x10, 0xBD, 0xE6, 0x45, 0xCE,
518 0x44, 0x6E, 0xBB, 0xE8, 0xF5, 0x03, 0x5D, 0xF8, 0x32, 0x22
521 static const UInt8 kFactoryDeviceCASHA1
[kSecPolicySHA1Size
] = {
522 0xef, 0x68, 0x73, 0x17, 0xa4, 0xf8, 0xf9, 0x4b, 0x7b, 0x21,
523 0xe2, 0x2f, 0x09, 0x8f, 0xfd, 0x6a, 0xae, 0xc0, 0x0d, 0x63
526 static const UInt8 kApplePKISettingsAuthority
[kSecPolicySHA1Size
] = {
527 0x1D, 0x0C, 0xBA, 0xAD, 0x17, 0xFD, 0x7E, 0x9E, 0x9F, 0xF1,
528 0xC9, 0xA2, 0x66, 0x79, 0x60, 0x00, 0x8B, 0xAE, 0x70, 0xB8
531 static const UInt8 kAppleTestPKISettingsAuthority
[kSecPolicySHA1Size
] = {
532 0xDB, 0xBA, 0x25, 0x0B, 0xD8, 0x62, 0x71, 0x87, 0x54, 0x7E,
533 0xD7, 0xEF, 0x11, 0x94, 0x7E, 0x82, 0xE6, 0xD8, 0x1C, 0x9A
536 static const UInt8 kTestAppleRootCA_ECC_SHA1
[kSecPolicySHA1Size
] = {
537 0x62, 0x0A, 0xED, 0x83, 0xD2, 0x97, 0x4A, 0x77, 0x56, 0x33,
538 0x83, 0xBE, 0xDB, 0xF9, 0xA1, 0xBD, 0x5F, 0xFE, 0x55, 0x7B
541 __unused
static const UInt8 kAppleRootCA_ECC_SHA1
[kSecPolicySHA1Size
] = {
542 0xB5, 0x2C, 0xB0, 0x2F, 0xD5, 0x67, 0xE0, 0x35, 0x9F, 0xE8,
543 0xFA, 0x4D, 0x4C, 0x41, 0x03, 0x79, 0x70, 0xFE, 0x01, 0xB0
548 /********************************************************
549 ****************** SecPolicy object ********************
550 ********************************************************/
552 static void SecPolicyDestroy(CFTypeRef cf
) {
553 SecPolicyRef policy
= (SecPolicyRef
) cf
;
554 CFRelease(policy
->_oid
);
555 CFReleaseSafe(policy
->_name
);
556 CFRelease(policy
->_options
);
559 static Boolean
SecPolicyCompare(CFTypeRef cf1
, CFTypeRef cf2
) {
560 SecPolicyRef policy1
= (SecPolicyRef
) cf1
;
561 SecPolicyRef policy2
= (SecPolicyRef
) cf2
;
562 if (policy1
->_name
&& policy2
->_name
) {
563 return CFEqual(policy1
->_oid
, policy2
->_oid
) &&
564 CFEqual(policy1
->_name
, policy2
->_name
) &&
565 CFEqual(policy1
->_options
, policy2
->_options
);
567 return CFEqual(policy1
->_oid
, policy2
->_oid
) &&
568 CFEqual(policy1
->_options
, policy2
->_options
);
572 static CFHashCode
SecPolicyHash(CFTypeRef cf
) {
573 SecPolicyRef policy
= (SecPolicyRef
) cf
;
575 return CFHash(policy
->_oid
) + CFHash(policy
->_name
) + CFHash(policy
->_options
);
577 return CFHash(policy
->_oid
) + CFHash(policy
->_options
);
581 static CFStringRef
SecPolicyCopyFormatDescription(CFTypeRef cf
, CFDictionaryRef formatOptions
) {
582 SecPolicyRef policy
= (SecPolicyRef
) cf
;
583 CFMutableStringRef desc
= CFStringCreateMutable(kCFAllocatorDefault
, 0);
584 CFStringRef typeStr
= CFCopyTypeIDDescription(CFGetTypeID(cf
));
585 CFStringAppendFormat(desc
, NULL
,
586 CFSTR("<%@: oid: %@ name: %@ options %@"), typeStr
,
587 policy
->_oid
, (policy
->_name
) ? policy
->_name
: CFSTR(""),
590 CFStringAppend(desc
, CFSTR(" >"));
595 /* SecPolicy API functions. */
596 CFGiblisWithHashFor(SecPolicy
);
598 /* AUDIT[securityd](done):
599 oid (ok) is a caller provided string, only its cf type has been checked.
600 options is a caller provided dictionary, only its cf type has been checked.
602 SecPolicyRef
SecPolicyCreate(CFStringRef oid
, CFStringRef name
, CFDictionaryRef options
) {
603 SecPolicyRef result
= NULL
;
605 require(oid
, errOut
);
606 require(options
, errOut
);
608 (SecPolicyRef
)_CFRuntimeCreateInstance(kCFAllocatorDefault
,
609 SecPolicyGetTypeID(),
610 sizeof(struct __SecPolicy
) - sizeof(CFRuntimeBase
), 0), errOut
);
615 result
->_name
= name
;
617 result
->_options
= options
;
624 static void set_ku_from_properties(SecPolicyRef policy
, CFDictionaryRef properties
);
627 SecPolicyRef
SecPolicyCreateWithProperties(CFTypeRef policyIdentifier
,
628 CFDictionaryRef properties
) {
629 // Creates a policy reference for a given policy object identifier.
630 // If policy-specific parameters can be supplied (e.g. hostname),
631 // attempt to obtain from input properties dictionary.
632 // Returns NULL if the given identifier is unsupported.
634 SecPolicyRef policy
= NULL
;
635 CFTypeRef name
= NULL
;
636 CFStringRef teamID
= NULL
;
637 Boolean client
= false;
638 CFDictionaryRef context
= NULL
;
639 CFStringRef policyName
= NULL
, intermediateMarkerOid
= NULL
, leafMarkerOid
= NULL
;
640 CFDataRef rootDigest
= NULL
;
641 require(policyIdentifier
&& (CFStringGetTypeID() == CFGetTypeID(policyIdentifier
)), errOut
);
644 name
= CFDictionaryGetValue(properties
, kSecPolicyName
);
645 teamID
= CFDictionaryGetValue(properties
, kSecPolicyTeamIdentifier
);
647 CFBooleanRef dictionaryClientValue
;
648 client
= (CFDictionaryGetValueIfPresent(properties
, kSecPolicyClient
, (const void **)&dictionaryClientValue
) &&
649 (dictionaryClientValue
!= NULL
) && CFEqual(kCFBooleanTrue
, dictionaryClientValue
));
650 context
= CFDictionaryGetValue(properties
, kSecPolicyContext
);
651 policyName
= CFDictionaryGetValue(properties
, kSecPolicyPolicyName
);
652 intermediateMarkerOid
= CFDictionaryGetValue(properties
, kSecPolicyIntermediateMarkerOid
);
653 leafMarkerOid
= CFDictionaryGetValue(properties
, kSecPolicyLeafMarkerOid
);
654 rootDigest
= CFDictionaryGetValue(properties
, kSecPolicyRootDigest
);
657 /* only the EAP policy allows a non-string name */
658 if (name
&& !isString(name
) && !CFEqual(policyIdentifier
, kSecPolicyAppleEAP
)) {
659 secerror("policy \"%@\" requires a string value for the %@ key", policyIdentifier
, kSecPolicyName
);
663 /* These are in the same order as the constant declarations. */
664 /* @@@ This should be turned into a table. */
665 if (CFEqual(policyIdentifier
, kSecPolicyAppleX509Basic
)) {
666 policy
= SecPolicyCreateBasicX509();
668 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSSL
)) {
669 policy
= SecPolicyCreateSSL(!client
, name
);
671 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSMIME
)) {
672 policy
= SecPolicyCreateSMIME(kSecSignSMIMEUsage
| kSecAnyEncryptSMIME
, name
);
674 else if (CFEqual(policyIdentifier
, kSecPolicyAppleEAP
)) {
675 CFArrayRef array
= NULL
;
676 if (isString(name
)) {
677 array
= CFArrayCreate(kCFAllocatorDefault
, (const void **)&name
, 1, &kCFTypeArrayCallBacks
);
678 } else if (isArray(name
)) {
679 array
= CFArrayCreateCopy(NULL
, name
);
681 policy
= SecPolicyCreateEAP(!client
, array
);
682 CFReleaseSafe(array
);
684 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSWUpdateSigning
)) {
685 policy
= SecPolicyCreateAppleSWUpdateSigning();
687 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIPsec
)) {
688 policy
= SecPolicyCreateIPSec(!client
, name
);
690 else if (CFEqual(policyIdentifier
, kSecPolicyAppleCodeSigning
)) {
691 policy
= SecPolicyCreateCodeSigning();
693 else if (CFEqual(policyIdentifier
, kSecPolicyApplePackageSigning
)) {
694 policy
= SecPolicyCreateApplePackageSigning();
696 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIDValidation
)) {
697 policy
= SecPolicyCreateAppleIDAuthorityPolicy();
699 else if (CFEqual(policyIdentifier
, kSecPolicyMacAppStoreReceipt
)) {
700 policy
= SecPolicyCreateMacAppStoreReceipt();
702 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTimeStamping
)) {
703 policy
= SecPolicyCreateAppleTimeStamping();
705 else if (CFEqual(policyIdentifier
, kSecPolicyAppleRevocation
)) {
706 policy
= SecPolicyCreateRevocation(kSecRevocationUseAnyAvailableMethod
);
708 else if (CFEqual(policyIdentifier
, kSecPolicyApplePassbookSigning
)) {
709 policy
= SecPolicyCreatePassbookCardSigner(name
, teamID
);
711 else if (CFEqual(policyIdentifier
, kSecPolicyAppleMobileStore
)) {
712 policy
= SecPolicyCreateMobileStoreSigner();
714 else if (CFEqual(policyIdentifier
, kSecPolicyAppleEscrowService
)) {
715 policy
= SecPolicyCreateEscrowServiceSigner();
717 else if (CFEqual(policyIdentifier
, kSecPolicyAppleProfileSigner
)) {
718 policy
= SecPolicyCreateConfigurationProfileSigner();
720 else if (CFEqual(policyIdentifier
, kSecPolicyAppleQAProfileSigner
)) {
721 policy
= SecPolicyCreateQAConfigurationProfileSigner();
723 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTestMobileStore
)) {
724 policy
= SecPolicyCreateTestMobileStoreSigner();
726 else if (CFEqual(policyIdentifier
, kSecPolicyAppleOTAPKISigner
)) {
727 policy
= SecPolicyCreateOTAPKISigner();
729 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTestOTAPKISigner
)) {
730 policy
= SecPolicyCreateTestOTAPKISigner();
732 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIDValidationRecordSigning
)) {
733 policy
= SecPolicyCreateAppleIDValidationRecordSigningPolicy();
735 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSMPEncryption
)) {
736 policy
= SecPolicyCreateAppleSMPEncryption();
738 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTestSMPEncryption
)) {
739 policy
= SecPolicyCreateTestAppleSMPEncryption();
741 else if (CFEqual(policyIdentifier
, kSecPolicyAppleServerAuthentication
)) {
742 policy
= SecPolicyCreateAppleSSLService(name
);
744 else if (CFEqual(policyIdentifier
, kSecPolicyApplePCSEscrowService
)) {
745 policy
= SecPolicyCreatePCSEscrowServiceSigner();
747 else if (CFEqual(policyIdentifier
, kSecPolicyApplePPQSigning
)) {
748 policy
= SecPolicyCreateApplePPQSigning();
750 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTestPPQSigning
)) {
751 policy
= SecPolicyCreateTestApplePPQSigning();
753 else if (CFEqual(policyIdentifier
, kSecPolicyApplePayIssuerEncryption
)) {
754 policy
= SecPolicyCreateApplePayIssuerEncryption();
756 else if (CFEqual(policyIdentifier
, kSecPolicyAppleOSXProvisioningProfileSigning
)) {
757 policy
= SecPolicyCreateOSXProvisioningProfileSigning();
759 else if (CFEqual(policyIdentifier
, kSecPolicyAppleATVVPNProfileSigning
)) {
760 policy
= SecPolicyCreateAppleATVVPNProfileSigning();
762 else if (CFEqual(policyIdentifier
, kSecPolicyAppleAST2DiagnosticsServerAuth
)) {
764 policy
= SecPolicyCreateAppleAST2Service(name
, context
);
766 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
769 else if (CFEqual(policyIdentifier
, kSecPolicyAppleEscrowProxyServerAuth
)) {
771 policy
= SecPolicyCreateAppleEscrowProxyService(name
, context
);
773 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
776 else if (CFEqual(policyIdentifier
, kSecPolicyAppleFMiPServerAuth
)) {
778 policy
= SecPolicyCreateAppleFMiPService(name
, context
);
780 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
783 else if (CFEqual(policyIdentifier
, kSecPolicyAppleMMCSService
)) {
785 policy
= SecPolicyCreateAppleMMCSService(name
, context
);
787 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
790 else if (CFEqual(policyIdentifier
, kSecPolicyAppleGSService
)) {
792 policy
= SecPolicyCreateAppleGSService(name
, context
);
794 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
797 else if (CFEqual(policyIdentifier
, kSecPolicyApplePPQService
)) {
799 policy
= SecPolicyCreateApplePPQService(name
, context
);
801 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
804 else if (CFEqual(policyIdentifier
, kSecPolicyAppleHomeKitServerAuth
)) {
805 policy
= SecPolicyCreateAppleHomeKitServerAuth(name
);
807 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiPhoneActivation
)) {
808 policy
= SecPolicyCreateiPhoneActivation();
810 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiPhoneDeviceCertificate
)) {
811 policy
= SecPolicyCreateiPhoneDeviceCertificate();
813 else if (CFEqual(policyIdentifier
, kSecPolicyAppleFactoryDeviceCertificate
)) {
814 policy
= SecPolicyCreateFactoryDeviceCertificate();
816 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiAP
)) {
817 policy
= SecPolicyCreateiAP();
819 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiTunesStoreURLBag
)) {
820 policy
= SecPolicyCreateiTunesStoreURLBag();
822 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiPhoneApplicationSigning
)) {
823 policy
= SecPolicyCreateiPhoneApplicationSigning();
825 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiPhoneProfileApplicationSigning
)) {
826 policy
= SecPolicyCreateiPhoneProfileApplicationSigning();
828 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiPhoneProvisioningProfileSigning
)) {
829 policy
= SecPolicyCreateiPhoneProvisioningProfileSigning();
831 else if (CFEqual(policyIdentifier
, kSecPolicyAppleLockdownPairing
)) {
832 policy
= SecPolicyCreateLockdownPairing();
834 else if (CFEqual(policyIdentifier
, kSecPolicyAppleURLBag
)) {
835 policy
= SecPolicyCreateURLBag();
837 else if (CFEqual(policyIdentifier
, kSecPolicyAppleOTATasking
)) {
838 policy
= SecPolicyCreateOTATasking();
840 else if (CFEqual(policyIdentifier
, kSecPolicyAppleMobileAsset
)) {
841 policy
= SecPolicyCreateMobileAsset();
843 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIDAuthority
)) {
844 policy
= SecPolicyCreateAppleIDAuthorityPolicy();
846 else if (CFEqual(policyIdentifier
, kSecPolicyAppleGenericApplePinned
)) {
848 policy
= SecPolicyCreateApplePinned(policyName
, intermediateMarkerOid
, leafMarkerOid
);
850 secerror("policy \"%@\" requires kSecPolicyPolicyName input", policyIdentifier
);
853 else if (CFEqual(policyIdentifier
, kSecPolicyAppleGenericAppleSSLPinned
)) {
855 policy
= SecPolicyCreateAppleSSLPinned(policyName
, name
, intermediateMarkerOid
, leafMarkerOid
);
857 secerror("policy \"%@\" requires kSecPolicyPolicyName input", policyIdentifier
);
860 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSoftwareSigning
)) {
861 policy
= SecPolicyCreateAppleSoftwareSigning();
863 else if (CFEqual(policyIdentifier
, kSecPolicyAppleExternalDeveloper
)) {
864 policy
= SecPolicyCreateAppleExternalDeveloper();
866 else if (CFEqual(policyIdentifier
, kSecPolicyAppleOCSPSigner
)) {
867 policy
= SecPolicyCreateOCSPSigner();
869 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIDSService
)) {
870 policy
= SecPolicyCreateAppleIDSService(name
);
872 else if (CFEqual(policyIdentifier
, kSecPolicyAppleIDSServiceContext
)) {
874 policy
= SecPolicyCreateAppleIDSServiceContext(name
, context
);
876 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
879 else if (CFEqual(policyIdentifier
, kSecPolicyApplePushService
)) {
881 policy
= SecPolicyCreateApplePushService(name
, context
);
883 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
886 else if (CFEqual(policyIdentifier
, kSecPolicyAppleLegacyPushService
)) {
888 policy
= SecPolicyCreateApplePushServiceLegacy(name
);
890 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
893 else if (CFEqual(policyIdentifier
, kSecPolicyAppleTVOSApplicationSigning
)) {
894 policy
= SecPolicyCreateAppleTVOSApplicationSigning();
896 else if (CFEqual(policyIdentifier
, kSecPolicyAppleUniqueDeviceIdentifierCertificate
)) {
897 policy
= SecPolicyCreateAppleUniqueDeviceCertificate(rootDigest
);
899 else if (CFEqual(policyIdentifier
, kSecPolicyAppleEscrowProxyCompatibilityServerAuth
)) {
901 policy
= SecPolicyCreateAppleCompatibilityEscrowProxyService(name
);
903 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
906 else if (CFEqual(policyIdentifier
, kSecPolicyAppleMMCSCompatibilityServerAuth
)) {
908 policy
= SecPolicyCreateAppleCompatibilityMMCSService(name
);
910 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
913 else if (CFEqual(policyIdentifier
, kSecPolicyAppleSecureIOStaticAsset
)) {
914 policy
= SecPolicyCreateAppleSecureIOStaticAsset();
916 else if (CFEqual(policyIdentifier
, kSecPolicyAppleWarsaw
)) {
917 policy
= SecPolicyCreateAppleWarsaw();
919 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiCloudSetupServerAuth
)) {
921 policy
= SecPolicyCreateAppleiCloudSetupService(name
, context
);
923 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
926 else if (CFEqual(policyIdentifier
, kSecPolicyAppleiCloudSetupCompatibilityServerAuth
)) {
928 policy
= SecPolicyCreateAppleCompatibilityiCloudSetupService(name
);
930 secerror("policy \"%@\" requires kSecPolicyName input", policyIdentifier
);
934 secerror("ERROR: policy \"%@\" is unsupported", policyIdentifier
);
938 set_ku_from_properties(policy
, properties
);
944 CFDictionaryRef
SecPolicyCopyProperties(SecPolicyRef policyRef
) {
945 // Builds and returns a dictionary which the caller must release.
947 #pragma clang diagnostic push
948 #pragma clang diagnostic ignored "-Wnonnull"
949 // After introducing nullability annotations, policyRef is supposed to be nonnull, suppress the warning
950 if (!policyRef
) return NULL
;
951 #pragma clang diagnostic pop
952 CFMutableDictionaryRef properties
= CFDictionaryCreateMutable(NULL
, 0,
953 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
954 #pragma clang diagnostic push
955 #pragma clang diagnostic ignored "-Wnonnull"
956 // 'properties' is nonnull in reality suppress the warning
957 if (!properties
) return NULL
;
958 #pragma clang diagnostic pop
959 CFStringRef oid
= (CFStringRef
) CFRetain(policyRef
->_oid
);
960 CFTypeRef nameKey
= NULL
;
962 // Determine name key
963 if (policyRef
->_options
) {
964 if (CFDictionaryContainsKey(policyRef
->_options
, kSecPolicyCheckSSLHostname
)) {
965 nameKey
= kSecPolicyCheckSSLHostname
;
966 } else if (CFDictionaryContainsKey(policyRef
->_options
, kSecPolicyCheckEAPTrustedServerNames
)) {
967 nameKey
= kSecPolicyCheckEAPTrustedServerNames
;
968 } else if (CFDictionaryContainsKey(policyRef
->_options
, kSecPolicyCheckEmail
)) {
969 nameKey
= kSecPolicyCheckEmail
;
974 CFDictionarySetValue(properties
, (const void *)kSecPolicyOid
,
977 // Set kSecPolicyName if we have one
978 if (nameKey
&& policyRef
->_options
) {
979 CFTypeRef name
= (CFTypeRef
) CFDictionaryGetValue(policyRef
->_options
,
982 CFDictionarySetValue(properties
, (const void *)kSecPolicyName
,
987 // Set kSecPolicyClient
988 CFStringRef policyName
= (CFStringRef
) CFRetainSafe(policyRef
->_name
);
989 if (policyName
&& (CFEqual(policyName
, kSecPolicyNameSSLClient
) ||
990 CFEqual(policyName
, kSecPolicyNameIPSecClient
) ||
991 CFEqual(policyName
, kSecPolicyNameEAPClient
))) {
992 CFDictionarySetValue(properties
, (const void *)kSecPolicyClient
,
993 (const void *)kCFBooleanTrue
);
1000 static void SecPolicySetOid(SecPolicyRef policy
, CFStringRef oid
) {
1001 if (!policy
|| !oid
) return;
1002 CFStringRef temp
= policy
->_oid
;
1005 CFReleaseSafe(temp
);
1008 static void SecPolicySetName(SecPolicyRef policy
, CFStringRef policyName
) {
1009 if (!policy
|| !policyName
) return;
1010 CFStringRef temp
= policy
->_name
;
1011 CFRetain(policyName
);
1012 policy
->_name
= policyName
;
1013 CFReleaseSafe(temp
);
1016 CFStringRef
SecPolicyGetOidString(SecPolicyRef policy
) {
1017 return policy
->_oid
;
1020 CFStringRef
SecPolicyGetName(SecPolicyRef policy
) {
1021 return policy
->_name
;
1024 CFDictionaryRef
SecPolicyGetOptions(SecPolicyRef policy
) {
1025 return policy
->_options
;
1028 void SecPolicySetOptionsValue(SecPolicyRef policy
, CFStringRef key
, CFTypeRef value
) {
1029 if (!policy
|| !key
) return;
1030 CFMutableDictionaryRef options
= (CFMutableDictionaryRef
) policy
->_options
;
1032 options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1033 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1034 if (!options
) return;
1035 policy
->_options
= options
;
1037 CFDictionarySetValue(options
, key
, value
);
1040 /* Local forward declaration */
1041 static void set_ssl_ekus(CFMutableDictionaryRef options
, bool server
);
1043 #if TARGET_OS_IPHONE
1044 // this is declared as NA for iPhone in SecPolicy.h, so declare here
1045 OSStatus
SecPolicySetProperties(SecPolicyRef policyRef
, CFDictionaryRef properties
);
1048 OSStatus
SecPolicySetProperties(SecPolicyRef policyRef
, CFDictionaryRef properties
) {
1049 // Set policy options based on the provided dictionary keys.
1051 if (!(policyRef
&& properties
&& (CFDictionaryGetTypeID() == CFGetTypeID(properties
)))) {
1054 CFStringRef oid
= (CFStringRef
) CFRetain(policyRef
->_oid
);
1055 OSStatus result
= errSecSuccess
;
1058 CFTypeRef name
= NULL
;
1059 if (CFDictionaryGetValueIfPresent(properties
, (const void *)kSecPolicyName
,
1060 (const void **)&name
) && name
) {
1061 CFTypeID typeID
= CFGetTypeID(name
);
1062 if (CFEqual(oid
, kSecPolicyAppleSSL
) ||
1063 CFEqual(oid
, kSecPolicyAppleIPsec
)) {
1064 if (CFStringGetTypeID() == typeID
) {
1065 SecPolicySetOptionsValue(policyRef
, kSecPolicyCheckSSLHostname
, name
);
1067 else result
= errSecParam
;
1069 else if (CFEqual(oid
, kSecPolicyAppleEAP
)) {
1070 if ((CFStringGetTypeID() == typeID
) ||
1071 (CFArrayGetTypeID() == typeID
)) {
1072 SecPolicySetOptionsValue(policyRef
, kSecPolicyCheckEAPTrustedServerNames
, name
);
1074 else result
= errSecParam
;
1076 else if (CFEqual(oid
, kSecPolicyAppleSMIME
)) {
1077 if (CFStringGetTypeID() == typeID
) {
1078 SecPolicySetOptionsValue(policyRef
, kSecPolicyCheckEmail
, name
);
1080 else result
= errSecParam
;
1085 CFTypeRef client
= NULL
;
1086 if (CFDictionaryGetValueIfPresent(properties
, (const void *)kSecPolicyClient
,
1087 (const void **)&client
) && client
) {
1088 if (!(CFBooleanGetTypeID() == CFGetTypeID(client
))) {
1089 result
= errSecParam
;
1091 else if (CFEqual(client
, kCFBooleanTrue
)) {
1092 if (CFEqual(oid
, kSecPolicyAppleSSL
)) {
1093 SecPolicySetName(policyRef
, kSecPolicyNameSSLClient
);
1094 /* Set EKU checks for clients */
1095 CFMutableDictionaryRef newOptions
= CFDictionaryCreateMutableCopy(NULL
, 0, policyRef
->_options
);
1096 set_ssl_ekus(newOptions
, false);
1097 CFReleaseSafe(policyRef
->_options
);
1098 policyRef
->_options
= newOptions
;
1100 else if (CFEqual(oid
, kSecPolicyAppleIPsec
)) {
1101 SecPolicySetName(policyRef
, kSecPolicyNameIPSecClient
);
1103 else if (CFEqual(oid
, kSecPolicyNameEAPServer
)) {
1104 SecPolicySetName(policyRef
, kSecPolicyNameEAPClient
);
1105 /* Set EKU checks for clients */
1106 CFMutableDictionaryRef newOptions
= CFDictionaryCreateMutableCopy(NULL
, 0, policyRef
->_options
);
1107 set_ssl_ekus(newOptions
, false);
1108 CFReleaseSafe(policyRef
->_options
);
1109 policyRef
->_options
= newOptions
;
1113 if (CFEqual(oid
, kSecPolicyAppleSSL
)) {
1114 SecPolicySetName(policyRef
, kSecPolicyNameSSLServer
);
1115 /* Set EKU checks for servers */
1116 CFMutableDictionaryRef newOptions
= CFDictionaryCreateMutableCopy(NULL
, 0, policyRef
->_options
);
1117 set_ssl_ekus(newOptions
, true);
1118 CFReleaseSafe(policyRef
->_options
);
1119 policyRef
->_options
= newOptions
;
1121 else if (CFEqual(oid
, kSecPolicyAppleIPsec
)) {
1122 SecPolicySetName(policyRef
, kSecPolicyNameIPSecServer
);
1124 else if (CFEqual(oid
, kSecPolicyAppleEAP
)) {
1125 SecPolicySetName(policyRef
, kSecPolicyNameEAPServer
);
1126 /* Set EKU checks for servers */
1127 CFMutableDictionaryRef newOptions
= CFDictionaryCreateMutableCopy(NULL
, 0, policyRef
->_options
);
1128 set_ssl_ekus(newOptions
, true);
1129 CFReleaseSafe(policyRef
->_options
);
1130 policyRef
->_options
= newOptions
;
1135 #ifdef TARGET_OS_OSX
1136 set_ku_from_properties(policyRef
, properties
);
1142 static xpc_object_t
copy_xpc_policy_object(SecPolicyRef policy
);
1143 static bool append_policy_to_xpc_array(SecPolicyRef policy
, xpc_object_t xpc_policies
);
1144 extern xpc_object_t
copy_xpc_policies_array(CFArrayRef policies
);
1145 extern OSStatus
validate_array_of_items(CFArrayRef array
, CFStringRef arrayItemType
, CFTypeID itemTypeID
, bool required
);
1147 static xpc_object_t
copy_xpc_policy_object(SecPolicyRef policy
) {
1148 xpc_object_t xpc_policy
= NULL
;
1149 xpc_object_t data
[2] = { NULL
, NULL
};
1150 if (policy
->_oid
&& (CFGetTypeID(policy
->_oid
) == CFStringGetTypeID()) &&
1151 policy
->_name
&& (CFGetTypeID(policy
->_name
) == CFStringGetTypeID())) {
1152 /* These should really be different elements of the xpc array. But
1153 * SecPolicyCreateWithXPCObject previously checked the size via ==, which prevents
1154 * us from appending new information while maintaining backward compatibility.
1155 * Doing this makes the builders happy. */
1156 CFMutableStringRef oidAndName
= NULL
;
1157 oidAndName
= CFStringCreateMutableCopy(NULL
, 0, policy
->_oid
);
1159 CFStringAppend(oidAndName
, CFSTR("++"));
1160 CFStringAppend(oidAndName
, policy
->_name
);
1161 data
[0] = _CFXPCCreateXPCObjectFromCFObject(oidAndName
);
1162 CFReleaseNull(oidAndName
);
1164 data
[0] = _CFXPCCreateXPCObjectFromCFObject(policy
->_oid
);
1166 } else if (policy
->_oid
&& (CFGetTypeID(policy
->_oid
) == CFStringGetTypeID())) {
1167 data
[0] = _CFXPCCreateXPCObjectFromCFObject(policy
->_oid
);
1169 secerror("policy 0x%lX has no _oid", (uintptr_t)policy
);
1171 if (policy
->_options
&& (CFGetTypeID(policy
->_options
) == CFDictionaryGetTypeID())) {
1172 data
[1] = _CFXPCCreateXPCObjectFromCFObject(policy
->_options
);
1174 secerror("policy 0x%lX has no _options", (uintptr_t)policy
);
1176 xpc_policy
= xpc_array_create(data
, array_size(data
));
1177 if (data
[0]) xpc_release(data
[0]);
1178 if (data
[1]) xpc_release(data
[1]);
1182 static bool append_policy_to_xpc_array(SecPolicyRef policy
, xpc_object_t xpc_policies
) {
1184 return true; // NOOP
1186 xpc_object_t xpc_policy
= copy_xpc_policy_object(policy
);
1190 xpc_array_append_value(xpc_policies
, xpc_policy
);
1191 xpc_release(xpc_policy
);
1195 xpc_object_t
copy_xpc_policies_array(CFArrayRef policies
) {
1196 xpc_object_t xpc_policies
= xpc_array_create(NULL
, 0);
1197 if (!xpc_policies
) {
1200 validate_array_of_items(policies
, CFSTR("policy"), SecPolicyGetTypeID(), true);
1201 CFIndex ix
, count
= CFArrayGetCount(policies
);
1202 for (ix
= 0; ix
< count
; ++ix
) {
1203 SecPolicyRef policy
= (SecPolicyRef
) CFArrayGetValueAtIndex(policies
, ix
);
1204 #if SECTRUST_VERBOSE_DEBUG
1205 CFDictionaryRef props
= SecPolicyCopyProperties(policy
);
1206 secerror("idx=%d of %d; policy=0x%lX properties=%@", (int)ix
, (int)count
, (uintptr_t)policy
, props
);
1207 CFReleaseSafe(props
);
1209 if (!append_policy_to_xpc_array(policy
, xpc_policies
)) {
1210 xpc_release(xpc_policies
);
1211 xpc_policies
= NULL
;
1215 return xpc_policies
;
1218 static xpc_object_t
SecPolicyCopyXPCObject(SecPolicyRef policy
, CFErrorRef
*error
) {
1219 xpc_object_t xpc_policy
= NULL
;
1220 xpc_object_t data
[2] = {};
1221 CFMutableStringRef oidAndName
= NULL
;
1222 oidAndName
= CFStringCreateMutableCopy(NULL
, 0, policy
->_oid
);
1224 if (policy
->_name
) {
1225 CFStringAppend(oidAndName
, CFSTR("++"));
1226 CFStringAppend(oidAndName
, policy
->_name
);
1229 require_action_quiet(data
[0] = _CFXPCCreateXPCObjectFromCFObject(oidAndName
), exit
,
1230 SecError(errSecParam
, error
,
1231 CFSTR("failed to create xpc_object from policy oid and name")));
1233 require_action_quiet(data
[0] = _CFXPCCreateXPCObjectFromCFObject(policy
->_oid
), exit
,
1234 SecError(errSecParam
, error
, CFSTR("failed to create xpc_object from policy oid")));
1236 require_action_quiet(data
[1] = _CFXPCCreateXPCObjectFromCFObject(policy
->_options
), exit
,
1237 SecError(errSecParam
, error
, CFSTR("failed to create xpc_object from policy options")));
1238 require_action_quiet(xpc_policy
= xpc_array_create(data
, array_size(data
)), exit
,
1239 SecError(errSecAllocate
, error
, CFSTR("failed to create xpc_array for policy")));
1242 if (data
[0]) xpc_release(data
[0]);
1243 if (data
[1]) xpc_release(data
[1]);
1244 CFReleaseNull(oidAndName
);
1248 static bool SecPolicyAppendToXPCArray(SecPolicyRef policy
, xpc_object_t policies
, CFErrorRef
*error
) {
1250 return true; // NOOP
1252 xpc_object_t xpc_policy
= SecPolicyCopyXPCObject(policy
, error
);
1256 xpc_array_append_value(policies
, xpc_policy
);
1257 xpc_release(xpc_policy
);
1261 xpc_object_t
SecPolicyArrayCopyXPCArray(CFArrayRef policies
, CFErrorRef
*error
) {
1262 xpc_object_t xpc_policies
;
1263 require_action_quiet(xpc_policies
= xpc_array_create(NULL
, 0), exit
,
1264 SecError(errSecAllocate
, error
, CFSTR("failed to create xpc_array")));
1265 CFIndex ix
, count
= CFArrayGetCount(policies
);
1266 for (ix
= 0; ix
< count
; ++ix
) {
1267 if (!SecPolicyAppendToXPCArray((SecPolicyRef
)CFArrayGetValueAtIndex(policies
, ix
), xpc_policies
, error
)) {
1268 xpc_release(xpc_policies
);
1273 return xpc_policies
;
1276 static OSStatus
parseOidAndName(CFStringRef oidAndName
, CFStringRef
*oid
, CFStringRef
*name
) {
1277 OSStatus result
= errSecSuccess
;
1278 CFStringRef partial
= NULL
;
1280 CFRange delimiter
= CFStringFind(oidAndName
, CFSTR("++"), 0);
1281 if (delimiter
.length
!= 2) {
1285 /* get first half: oid */
1286 partial
= CFStringCreateWithSubstring(NULL
, oidAndName
, CFRangeMake(0, delimiter
.location
));
1287 if (oid
) { *oid
= CFRetainSafe(partial
); }
1288 CFReleaseNull(partial
);
1290 /* get second half: name */
1291 if (delimiter
.location
+ 2 >= CFStringGetLength(oidAndName
)) {
1292 return errSecSuccess
; // name is optional
1294 CFRange nameRange
= CFRangeMake(delimiter
.location
+2,
1295 CFStringGetLength(oidAndName
) - delimiter
.location
- 2);
1296 partial
= CFStringCreateWithSubstring(NULL
, oidAndName
, nameRange
);
1297 if (name
) { *name
= CFRetainSafe(partial
); }
1298 CFReleaseNull(partial
);
1302 static SecPolicyRef
SecPolicyCreateWithXPCObject(xpc_object_t xpc_policy
, CFErrorRef
*error
) {
1303 SecPolicyRef policy
= NULL
;
1304 CFTypeRef oidAndName
= NULL
;
1305 CFStringRef oid
= NULL
;
1306 CFStringRef name
= NULL
;
1307 CFTypeRef options
= NULL
;
1309 require_action_quiet(xpc_policy
, exit
, SecError(errSecParam
, error
, CFSTR("policy xpc value is NULL")));
1310 require_action_quiet(xpc_get_type(xpc_policy
) == XPC_TYPE_ARRAY
, exit
, SecError(errSecDecode
, error
, CFSTR("policy xpc value is not an array")));
1311 require_action_quiet(xpc_array_get_count(xpc_policy
) >= 2, exit
, SecError(errSecDecode
, error
, CFSTR("policy xpc array count < 2")));
1312 oidAndName
= _CFXPCCreateCFObjectFromXPCObject(xpc_array_get_value(xpc_policy
, 0));
1313 require_action_quiet(isString(oidAndName
), exit
,
1314 SecError(errSecParam
, error
, CFSTR("failed to convert xpc policy[0]=%@ to CFString"), oidAndName
));
1315 options
= _CFXPCCreateCFObjectFromXPCObject(xpc_array_get_value(xpc_policy
, 1));
1316 require_action_quiet(isDictionary(options
), exit
,
1317 SecError(errSecParam
, error
, CFSTR("failed to convert xpc policy[1]=%@ to CFDictionary"), options
));
1318 require_noerr_action_quiet(parseOidAndName(oidAndName
, &oid
, &name
), exit
,
1319 SecError(errSecParam
, error
, CFSTR("failed to convert combined %@ to name and oid"), oidAndName
));
1320 require_action_quiet(policy
= SecPolicyCreate(oid
, name
, options
), exit
,
1321 SecError(errSecDecode
, error
, CFSTR("Failed to create policy")));
1324 CFReleaseSafe(oidAndName
);
1326 CFReleaseSafe(name
);
1327 CFReleaseSafe(options
);
1331 CFArrayRef
SecPolicyXPCArrayCopyArray(xpc_object_t xpc_policies
, CFErrorRef
*error
) {
1332 CFMutableArrayRef policies
= NULL
;
1333 require_action_quiet(xpc_get_type(xpc_policies
) == XPC_TYPE_ARRAY
, exit
,
1334 SecError(errSecParam
, error
, CFSTR("policies xpc value is not an array")));
1335 size_t count
= xpc_array_get_count(xpc_policies
);
1336 require_action_quiet(policies
= CFArrayCreateMutable(kCFAllocatorDefault
, count
, &kCFTypeArrayCallBacks
), exit
,
1337 SecError(errSecAllocate
, error
, CFSTR("failed to create CFArray of capacity %zu"), count
));
1340 for (ix
= 0; ix
< count
; ++ix
) {
1341 SecPolicyRef policy
= SecPolicyCreateWithXPCObject(xpc_array_get_value(xpc_policies
, ix
), error
);
1343 CFRelease(policies
);
1346 CFArraySetValueAtIndex(policies
, ix
, policy
);
1355 static SEC_CONST_DECL (kSecPolicyOptions
, "policyOptions");
1357 static SecPolicyRef
SecPolicyCreateWithDictionary(CFDictionaryRef dict
) {
1358 SecPolicyRef policy
= NULL
;
1359 CFStringRef oid
= (CFStringRef
)CFDictionaryGetValue(dict
, kSecPolicyOid
);
1360 require_quiet(isString(oid
), errOut
);
1361 CFDictionaryRef options
= (CFDictionaryRef
)CFDictionaryGetValue(dict
, kSecPolicyOptions
);
1362 require_quiet(isDictionary(options
), errOut
);
1363 CFStringRef name
= (CFStringRef
)CFDictionaryGetValue(dict
, kSecPolicyPolicyName
);
1364 policy
= SecPolicyCreate(oid
, name
, options
);
1369 static void deserializePolicy(const void *value
, void *context
) {
1370 CFDictionaryRef policyDict
= (CFDictionaryRef
)value
;
1371 if (isDictionary(policyDict
)) {
1372 CFTypeRef deserializedPolicy
= SecPolicyCreateWithDictionary(policyDict
);
1373 if (deserializedPolicy
) {
1374 CFArrayAppendValue((CFMutableArrayRef
)context
, deserializedPolicy
);
1375 CFRelease(deserializedPolicy
);
1380 CFArrayRef
SecPolicyArrayCreateDeserialized(CFArrayRef serializedPolicies
) {
1381 CFMutableArrayRef result
= NULL
;
1382 require_quiet(isArray(serializedPolicies
), errOut
);
1383 CFIndex count
= CFArrayGetCount(serializedPolicies
);
1384 result
= CFArrayCreateMutable(kCFAllocatorDefault
, count
, &kCFTypeArrayCallBacks
);
1385 CFRange all_policies
= { 0, count
};
1386 CFArrayApplyFunction(serializedPolicies
, all_policies
, deserializePolicy
, result
);
1391 static CFDictionaryRef
SecPolicyCreateDictionary(SecPolicyRef policy
) {
1392 CFMutableDictionaryRef dict
= NULL
;
1393 dict
= CFDictionaryCreateMutable(NULL
, 3, &kCFTypeDictionaryKeyCallBacks
,
1394 &kCFTypeDictionaryValueCallBacks
);
1395 CFDictionaryAddValue(dict
, kSecPolicyOid
, policy
->_oid
);
1396 CFDictionaryAddValue(dict
, kSecPolicyOptions
, policy
->_options
);
1397 if (policy
->_name
) {
1398 CFDictionaryAddValue(dict
, kSecPolicyPolicyName
, policy
->_name
);
1403 static void serializePolicy(const void *value
, void *context
) {
1404 SecPolicyRef policy
= (SecPolicyRef
)value
;
1405 if (policy
&& SecPolicyGetTypeID() == CFGetTypeID(policy
)) {
1406 CFDictionaryRef serializedPolicy
= SecPolicyCreateDictionary(policy
);
1407 if (serializedPolicy
) {
1408 CFArrayAppendValue((CFMutableArrayRef
)context
, serializedPolicy
);
1409 CFRelease(serializedPolicy
);
1414 CFArrayRef
SecPolicyArrayCreateSerialized(CFArrayRef policies
) {
1415 CFMutableArrayRef result
= NULL
;
1416 require_quiet(isArray(policies
), errOut
);
1417 CFIndex count
= CFArrayGetCount(policies
);
1418 result
= CFArrayCreateMutable(NULL
, count
, &kCFTypeArrayCallBacks
);
1419 CFRange all_policies
= { 0, count
};
1420 CFArrayApplyFunction(policies
, all_policies
, serializePolicy
, result
);
1425 static void add_element(CFMutableDictionaryRef options
, CFStringRef key
,
1427 CFTypeRef old_value
= CFDictionaryGetValue(options
, key
);
1429 CFMutableArrayRef array
;
1430 if (CFGetTypeID(old_value
) == CFArrayGetTypeID()) {
1431 array
= (CFMutableArrayRef
)old_value
;
1433 array
= CFArrayCreateMutable(kCFAllocatorDefault
, 0,
1434 &kCFTypeArrayCallBacks
);
1435 CFArrayAppendValue(array
, old_value
);
1436 CFDictionarySetValue(options
, key
, array
);
1439 CFArrayAppendValue(array
, value
);
1441 CFDictionaryAddValue(options
, key
, value
);
1445 static void add_eku(CFMutableDictionaryRef options
, const DERItem
*ekuOid
) {
1446 CFDataRef eku
= CFDataCreate(kCFAllocatorDefault
,
1447 ekuOid
? ekuOid
->data
: NULL
,
1448 ekuOid
? ekuOid
->length
: 0);
1450 add_element(options
, kSecPolicyCheckExtendedKeyUsage
, eku
);
1455 static void add_eku_string(CFMutableDictionaryRef options
, CFStringRef ekuOid
) {
1457 add_element(options
, kSecPolicyCheckExtendedKeyUsage
, ekuOid
);
1461 static void set_ssl_ekus(CFMutableDictionaryRef options
, bool server
) {
1462 CFDictionaryRemoveValue(options
, kSecPolicyCheckExtendedKeyUsage
);
1464 /* If server and EKU ext present then EKU ext should contain one of
1465 ServerAuth or ExtendedKeyUsageAny or NetscapeSGC or MicrosoftSGC.
1466 else if !server and EKU ext present then EKU ext should contain one of
1467 ClientAuth or ExtendedKeyUsageAny. */
1469 /* We always allow certificates that specify oidAnyExtendedKeyUsage. */
1470 add_eku(options
, NULL
); /* eku extension is optional */
1471 add_eku(options
, &oidAnyExtendedKeyUsage
);
1473 add_eku(options
, &oidExtendedKeyUsageServerAuth
);
1474 add_eku(options
, &oidExtendedKeyUsageMicrosoftSGC
);
1475 add_eku(options
, &oidExtendedKeyUsageNetscapeSGC
);
1477 add_eku(options
, &oidExtendedKeyUsageClientAuth
);
1481 static void add_ku(CFMutableDictionaryRef options
, SecKeyUsage keyUsage
) {
1482 SInt32 dku
= keyUsage
;
1483 CFNumberRef ku
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt32Type
,
1486 add_element(options
, kSecPolicyCheckKeyUsage
, ku
);
1491 #ifdef TARGET_OS_OSX
1492 static void set_ku_from_properties(SecPolicyRef policy
, CFDictionaryRef properties
) {
1493 if (!policy
|| !properties
) {
1497 CFStringRef keyNames
[] = { kSecPolicyKU_DigitalSignature
, kSecPolicyKU_NonRepudiation
, kSecPolicyKU_KeyEncipherment
, kSecPolicyKU_DataEncipherment
,
1498 kSecPolicyKU_KeyAgreement
, kSecPolicyKU_KeyCertSign
, kSecPolicyKU_CRLSign
, kSecPolicyKU_EncipherOnly
, kSecPolicyKU_DecipherOnly
};
1500 uint32_t keyUsageValues
[] = { kSecKeyUsageDigitalSignature
, kSecKeyUsageNonRepudiation
, kSecKeyUsageKeyEncipherment
, kSecKeyUsageDataEncipherment
,
1501 kSecKeyUsageKeyAgreement
, kSecKeyUsageKeyCertSign
, kSecKeyUsageCRLSign
, kSecKeyUsageEncipherOnly
, kSecKeyUsageDecipherOnly
};
1503 bool haveKeyUsage
= false;
1504 CFTypeRef keyUsageBoolean
;
1505 for (uint32_t i
= 0; i
< sizeof(keyNames
) / sizeof(CFStringRef
); ++i
) {
1506 if (CFDictionaryGetValueIfPresent(properties
, keyNames
[i
], (const void**)&keyUsageBoolean
)) {
1507 if (CFEqual(keyUsageBoolean
, kCFBooleanTrue
)) {
1508 haveKeyUsage
= true;
1514 if (!haveKeyUsage
) {
1518 CFMutableDictionaryRef options
= (CFMutableDictionaryRef
) policy
->_options
;
1520 options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1521 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1522 if (!options
) return;
1523 policy
->_options
= options
;
1525 CFDictionaryRemoveValue(options
, kSecPolicyCheckKeyUsage
);
1528 for (uint32_t i
= 0; i
< sizeof(keyNames
) / sizeof(CFStringRef
); ++i
) {
1529 if (CFDictionaryGetValueIfPresent(properties
, keyNames
[i
], (const void**)&keyUsageBoolean
)) {
1530 if (CFEqual(keyUsageBoolean
, kCFBooleanTrue
)) {
1531 add_ku(options
, keyUsageValues
[i
]);
1538 static void add_oid(CFMutableDictionaryRef options
, CFStringRef policy_key
, const DERItem
*oid
) {
1539 CFDataRef oid_data
= CFDataCreate(kCFAllocatorDefault
,
1540 oid
? oid
->data
: NULL
,
1541 oid
? oid
->length
: 0);
1543 add_element(options
, policy_key
, oid_data
);
1544 CFRelease(oid_data
);
1548 static void add_leaf_marker_value(CFMutableDictionaryRef options
, const DERItem
*markerOid
, CFStringRef string_value
) {
1550 CFTypeRef policyData
= NULL
;
1552 if (NULL
== string_value
) {
1553 policyData
= CFDataCreate(kCFAllocatorDefault
,
1554 markerOid
? markerOid
->data
: NULL
,
1555 markerOid
? markerOid
->length
: 0);
1557 CFStringRef oid_as_string
= SecDERItemCopyOIDDecimalRepresentation(kCFAllocatorDefault
, markerOid
);
1559 const void *key
[1] = { oid_as_string
};
1560 const void *value
[1] = { string_value
};
1561 policyData
= CFDictionaryCreate(kCFAllocatorDefault
,
1563 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1564 CFReleaseNull(oid_as_string
);
1567 add_element(options
, kSecPolicyCheckLeafMarkerOid
, policyData
);
1569 CFReleaseNull(policyData
);
1573 static void add_leaf_marker(CFMutableDictionaryRef options
, const DERItem
*markerOid
) {
1574 add_leaf_marker_value(options
, markerOid
, NULL
);
1577 static void add_leaf_marker_value_string(CFMutableDictionaryRef options
, CFStringRef markerOid
, CFStringRef string_value
) {
1578 if (NULL
== string_value
) {
1579 add_element(options
, kSecPolicyCheckLeafMarkerOid
, markerOid
);
1581 CFDictionaryRef policyData
= NULL
;
1582 const void *key
[1] = { markerOid
};
1583 const void *value
[1] = { string_value
};
1584 policyData
= CFDictionaryCreate(kCFAllocatorDefault
,
1586 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1587 add_element(options
, kSecPolicyCheckLeafMarkerOid
, policyData
);
1589 CFReleaseNull(policyData
);
1593 static void add_leaf_marker_string(CFMutableDictionaryRef options
, CFStringRef markerOid
) {
1594 add_leaf_marker_value_string(options
, markerOid
, NULL
);
1597 static void add_leaf_prod_qa_element(CFMutableDictionaryRef options
, CFTypeRef prodValue
, CFTypeRef qaValue
)
1599 CFMutableDictionaryRef prodAndQADictionary
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
,
1600 &kCFTypeDictionaryValueCallBacks
);
1601 CFDictionaryRef old_value
= CFDictionaryGetValue(options
, kSecPolicyCheckLeafMarkersProdAndQA
);
1603 CFMutableArrayRef prodArray
= NULL
, qaArray
= NULL
;
1604 CFTypeRef old_prod_value
= CFDictionaryGetValue(old_value
, kSecPolicyLeafMarkerProd
);
1605 CFTypeRef old_qa_value
= CFDictionaryGetValue(old_value
, kSecPolicyLeafMarkerQA
);
1606 if (isArray(old_prod_value
) && isArray(old_qa_value
)) {
1607 prodArray
= (CFMutableArrayRef
)CFRetainSafe(old_prod_value
);
1608 qaArray
= (CFMutableArrayRef
)CFRetainSafe(old_qa_value
);
1610 prodArray
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1611 qaArray
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1612 CFArrayAppendValue(prodArray
, old_prod_value
);
1613 CFArrayAppendValue(qaArray
, old_qa_value
);
1615 CFArrayAppendValue(prodArray
, prodValue
);
1616 CFArrayAppendValue(qaArray
, qaValue
);
1617 CFDictionaryAddValue(prodAndQADictionary
, kSecPolicyLeafMarkerProd
, prodArray
);
1618 CFDictionaryAddValue(prodAndQADictionary
, kSecPolicyLeafMarkerQA
, qaArray
);
1619 CFReleaseNull(prodArray
);
1620 CFReleaseNull(qaArray
);
1623 CFDictionaryAddValue(prodAndQADictionary
, kSecPolicyLeafMarkerProd
, prodValue
);
1624 CFDictionaryAddValue(prodAndQADictionary
, kSecPolicyLeafMarkerQA
, qaValue
);
1626 CFDictionarySetValue(options
, kSecPolicyCheckLeafMarkersProdAndQA
, prodAndQADictionary
);
1627 CFReleaseNull(prodAndQADictionary
);
1631 static void add_leaf_prod_qa_markers(CFMutableDictionaryRef options
, const DERItem
*prodMarkerOid
, const DERItem
*qaMarkerOid
)
1633 CFDataRef prodData
= NULL
, qaData
= NULL
;
1634 prodData
= CFDataCreate(NULL
, prodMarkerOid
? prodMarkerOid
->data
: NULL
,
1635 prodMarkerOid
? prodMarkerOid
->length
: 0);
1636 qaData
= CFDataCreate(NULL
, qaMarkerOid
? qaMarkerOid
->data
: NULL
,
1637 qaMarkerOid
? qaMarkerOid
->length
: 0);
1638 add_leaf_prod_qa_element(options
, prodData
, qaData
);
1639 CFReleaseNull(prodData
);
1640 CFReleaseNull(qaData
);
1643 static void add_leaf_prod_qa_markers_string(CFMutableDictionaryRef options
, CFStringRef prodMarkerOid
, CFStringRef qaMarkerOid
)
1645 add_leaf_prod_qa_element(options
, prodMarkerOid
, qaMarkerOid
);
1648 static void add_leaf_prod_qa_markers_value_string(CFMutableDictionaryRef options
,
1649 CFStringRef prodMarkerOid
, CFStringRef prod_value
,
1650 CFStringRef qaMarkerOid
, CFStringRef qa_value
)
1652 if (!prod_value
&& !qa_value
) {
1653 add_leaf_prod_qa_element(options
, prodMarkerOid
, qaMarkerOid
);
1655 CFDictionaryRef prodData
= NULL
, qaData
= NULL
;
1656 const void *prodKey
[1] = { prodMarkerOid
}, *qaKey
[1] = { qaMarkerOid
};
1657 const void *prodValue
[1] = { prod_value
}, *qaValue
[1] = { qa_value
};
1658 prodData
= CFDictionaryCreate(NULL
, prodKey
, prodValue
, 1, &kCFTypeDictionaryKeyCallBacks
,
1659 &kCFTypeDictionaryValueCallBacks
);
1660 qaData
= CFDictionaryCreate(NULL
, qaKey
, qaValue
, 1, &kCFTypeDictionaryKeyCallBacks
,
1661 &kCFTypeDictionaryValueCallBacks
);
1662 add_leaf_prod_qa_element(options
, prodData
, qaData
);
1663 CFReleaseNull(prodData
);
1664 CFReleaseNull(qaData
);
1668 static void add_intermediate_marker_value_string(CFMutableDictionaryRef options
, CFStringRef markerOid
, CFStringRef string_value
) {
1669 if (NULL
== string_value
) {
1670 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, markerOid
);
1672 CFDictionaryRef policyData
= NULL
;
1673 const void *key
[1] = { markerOid
};
1674 const void *value
[1] = { string_value
};
1675 policyData
= CFDictionaryCreate(kCFAllocatorDefault
,
1677 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1678 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, policyData
);
1680 CFReleaseNull(policyData
);
1684 static void add_certificate_policy_oid(CFMutableDictionaryRef options
, const DERItem
*certificatePolicyOid
) {
1685 CFTypeRef certificatePolicyData
= NULL
;
1686 certificatePolicyData
= CFDataCreate(kCFAllocatorDefault
,
1687 certificatePolicyOid
? certificatePolicyOid
->data
: NULL
,
1688 certificatePolicyOid
? certificatePolicyOid
->length
: 0);
1689 if (certificatePolicyData
) {
1690 add_element(options
, kSecPolicyCheckCertificatePolicy
, certificatePolicyData
);
1691 CFRelease(certificatePolicyData
);
1695 static void add_certificate_policy_oid_string(CFMutableDictionaryRef options
, CFStringRef certificatePolicyOid
) {
1696 if (certificatePolicyOid
) {
1697 add_element(options
, kSecPolicyCheckCertificatePolicy
, certificatePolicyOid
);
1702 // Routines for adding dictionary entries for policies.
1705 // X.509, but missing validity requirements.
1706 static void SecPolicyAddBasicCertOptions(CFMutableDictionaryRef options
)
1708 //CFDictionaryAddValue(options, kSecPolicyCheckBasicCertificateProcessing, kCFBooleanTrue);
1709 // Happens automatically in SecPVCPathChecks
1710 CFDictionaryAddValue(options
, kSecPolicyCheckCriticalExtensions
, kCFBooleanTrue
);
1711 CFDictionaryAddValue(options
, kSecPolicyCheckIdLinkage
, kCFBooleanTrue
);
1712 CFDictionaryAddValue(options
, kSecPolicyCheckBasicConstraints
, kCFBooleanTrue
);
1713 CFDictionaryAddValue(options
, kSecPolicyCheckNonEmptySubject
, kCFBooleanTrue
);
1714 CFDictionaryAddValue(options
, kSecPolicyCheckQualifiedCertStatements
, kCFBooleanTrue
);
1715 CFDictionaryAddValue(options
, kSecPolicyCheckWeakIntermediates
, kCFBooleanTrue
);
1716 CFDictionaryAddValue(options
, kSecPolicyCheckWeakLeaf
, kCFBooleanTrue
);
1717 CFDictionaryAddValue(options
, kSecPolicyCheckWeakRoot
, kCFBooleanTrue
);
1720 static void SecPolicyAddBasicX509Options(CFMutableDictionaryRef options
)
1722 SecPolicyAddBasicCertOptions(options
);
1723 CFDictionaryAddValue(options
, kSecPolicyCheckValidIntermediates
, kCFBooleanTrue
);
1724 CFDictionaryAddValue(options
, kSecPolicyCheckValidLeaf
, kCFBooleanTrue
);
1725 CFDictionaryAddValue(options
, kSecPolicyCheckValidRoot
, kCFBooleanTrue
);
1727 // Make sure that black and gray leaf checks are performed for basic X509 chain building
1728 CFDictionaryAddValue(options
, kSecPolicyCheckBlackListedLeaf
, kCFBooleanTrue
);
1729 CFDictionaryAddValue(options
, kSecPolicyCheckGrayListedLeaf
, kCFBooleanTrue
);
1732 static bool SecPolicyAddChainLengthOptions(CFMutableDictionaryRef options
, CFIndex length
)
1734 bool result
= false;
1735 CFNumberRef lengthAsCF
= NULL
;
1737 require(lengthAsCF
= CFNumberCreate(kCFAllocatorDefault
,
1738 kCFNumberCFIndexType
, &length
), errOut
);
1739 CFDictionaryAddValue(options
, kSecPolicyCheckChainLength
, lengthAsCF
);
1744 CFReleaseSafe(lengthAsCF
);
1748 static bool SecPolicyAddAnchorSHA1Options(CFMutableDictionaryRef options
,
1749 const UInt8 anchorSha1
[kSecPolicySHA1Size
])
1751 bool success
= false;
1752 CFDataRef anchorData
= NULL
;
1754 require(anchorData
= CFDataCreate(kCFAllocatorDefault
, anchorSha1
, kSecPolicySHA1Size
), errOut
);
1755 add_element(options
, kSecPolicyCheckAnchorSHA1
, anchorData
);
1760 CFReleaseSafe(anchorData
);
1764 static bool SecPolicyAddAnchorSHA256Options(CFMutableDictionaryRef options
,
1765 const UInt8 anchorSha1
[kSecPolicySHA256Size
])
1767 bool success
= false;
1768 CFDataRef anchorData
= NULL
;
1770 require(anchorData
= CFDataCreate(kCFAllocatorDefault
, anchorSha1
, kSecPolicySHA256Size
), errOut
);
1771 add_element(options
, kSecPolicyCheckAnchorSHA256
, anchorData
);
1776 CFReleaseSafe(anchorData
);
1780 static bool SecPolicyAddStrongKeySizeOptions(CFMutableDictionaryRef options
) {
1781 bool success
= false;
1782 CFDictionaryRef keySizes
= NULL
;
1783 CFNumberRef rsaSize
= NULL
, ecSize
= NULL
;
1785 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
1786 require(rsaSize
= CFNumberCreateWithCFIndex(NULL
, 2048), errOut
);
1787 require(ecSize
= CFNumberCreateWithCFIndex(NULL
, 256), errOut
);
1788 const void *keys
[] = { kSecAttrKeyTypeRSA
, kSecAttrKeyTypeEC
};
1789 const void *values
[] = { rsaSize
, ecSize
};
1790 require(keySizes
= CFDictionaryCreate(NULL
, keys
, values
, 2,
1791 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
1792 add_element(options
, kSecPolicyCheckKeySize
, keySizes
);
1797 CFReleaseSafe(keySizes
);
1798 CFReleaseSafe(rsaSize
);
1799 CFReleaseSafe(ecSize
);
1803 static bool isAppleOid(CFStringRef oid
) {
1804 if (!SecCertificateIsOidString(oid
)) {
1807 if (CFStringHasPrefix(oid
, CFSTR("1.2.840.113635"))) {
1813 static bool isCFPreferenceInSecurityDomain(CFStringRef setting
) {
1814 /* For backwards compatibility reasons we have to check both "com.apple.security"
1815 and "com.apple.Security". */
1816 if (CFPreferencesGetAppBooleanValue(setting
, CFSTR("com.apple.Security"), NULL
)) {
1817 secwarning("DEPRECATION WARNING: Preference set in \"com.apple.Security\" domain. This domain is deprecated. Please use \"com.apple.security\" instead");
1819 return (CFPreferencesGetAppBooleanValue(setting
, CFSTR("com.apple.security"), NULL
) ||
1820 CFPreferencesGetAppBooleanValue(setting
, CFSTR("com.apple.Security"), NULL
));
1823 static bool allowTestHierarchyForPolicy(CFStringRef policyName
, bool isSSL
) {
1826 CFStringRef setting
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("ApplePinningAllowTestCerts%@"), policyName
);
1827 require(setting
, fail
);
1828 if (isCFPreferenceInSecurityDomain(setting
)) {
1831 secnotice("pinningQA", "could not enable test hierarchy: %@ not true", setting
);
1835 if (!allow
&& isSSL
) {
1836 if (isCFPreferenceInSecurityDomain(CFSTR("AppleServerAuthenticationAllowUAT"))) {
1839 secnotice("pinningQA", "could not enable test hierarchy: AppleServerAuthenticationAllowUAT not true");
1847 static bool SecPolicyAddAppleAnchorOptions(CFMutableDictionaryRef options
, CFStringRef policyName
)
1849 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
1850 appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
);
1851 if (!appleAnchorOptions
) {
1855 if (allowTestHierarchyForPolicy(policyName
, false)) {
1856 CFDictionarySetValue(appleAnchorOptions
,
1857 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
1859 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
1860 CFReleaseSafe(appleAnchorOptions
);
1865 // MARK: Policy Creation Functions
1867 SecPolicyRef
SecPolicyCreateBasicX509(void) {
1868 CFMutableDictionaryRef options
= NULL
;
1869 SecPolicyRef result
= NULL
;
1871 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1872 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
1874 SecPolicyAddBasicX509Options(options
);
1875 CFDictionaryAddValue(options
, kSecPolicyCheckNoNetworkAccess
,
1878 require(result
= SecPolicyCreate(kSecPolicyAppleX509Basic
, kSecPolicyNameBasicX509
, options
), errOut
);
1881 CFReleaseSafe(options
);
1882 return (SecPolicyRef _Nonnull
)result
;
1885 SecPolicyRef
SecPolicyCreateSSL(Boolean server
, CFStringRef hostname
) {
1886 CFMutableDictionaryRef options
= NULL
;
1887 SecPolicyRef result
= NULL
;
1889 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1890 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
1892 SecPolicyAddBasicX509Options(options
);
1895 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
1898 CFDictionaryAddValue(options
, kSecPolicyCheckBlackListedLeaf
, kCFBooleanTrue
);
1899 CFDictionaryAddValue(options
, kSecPolicyCheckGrayListedLeaf
, kCFBooleanTrue
);
1902 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
1905 set_ssl_ekus(options
, server
);
1907 require(result
= SecPolicyCreate(kSecPolicyAppleSSL
,
1908 server
? kSecPolicyNameSSLServer
: kSecPolicyNameSSLClient
,
1912 CFReleaseSafe(options
);
1913 return (SecPolicyRef _Nonnull
)result
;
1916 SecPolicyRef
SecPolicyCreateApplePinned(CFStringRef policyName
, CFStringRef intermediateMarkerOID
, CFStringRef leafMarkerOID
) {
1917 CFMutableDictionaryRef options
= NULL
;
1918 SecPolicyRef result
= NULL
;
1920 if (!policyName
|| !intermediateMarkerOID
|| !leafMarkerOID
) {
1924 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1925 &kCFTypeDictionaryKeyCallBacks
,
1926 &kCFTypeDictionaryValueCallBacks
), errOut
);
1928 SecPolicyAddBasicX509Options(options
);
1930 /* Anchored to the Apple Roots */
1931 require(SecPolicyAddAppleAnchorOptions(options
, policyName
), errOut
);
1933 /* Exactly 3 certs in the chain */
1934 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
1936 /* Intermediate marker OID matches input OID */
1937 if (!isAppleOid(intermediateMarkerOID
)) {
1938 secwarning("creating an Apple pinning policy with a non-Apple OID: %@", intermediateMarkerOID
);
1940 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, intermediateMarkerOID
);
1942 /* Leaf marker OID matches input OID */
1943 if (!isAppleOid(leafMarkerOID
)) {
1944 secwarning("creating an Apple pinning policy with a non-Apple OID: %@", leafMarkerOID
);
1946 add_leaf_marker_string(options
, leafMarkerOID
);
1948 /* Check revocation using any available method */
1949 add_element(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
1951 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
1952 require(SecPolicyAddStrongKeySizeOptions(options
), errOut
);
1954 /* Check for weak hashes */
1955 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
1956 require(result
= SecPolicyCreate(kSecPolicyAppleGenericApplePinned
,
1957 policyName
, options
), errOut
);
1960 CFReleaseSafe(options
);
1965 requireUATPinning(CFStringRef service
)
1967 bool pinningRequired
= true;
1969 if (SecIsInternalRelease()) {
1970 CFStringRef setting
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("AppleServerAuthenticationNoPinning%@"), service
);
1971 require(setting
, fail
);
1972 if(isCFPreferenceInSecurityDomain(setting
)) {
1973 pinningRequired
= false;
1975 secnotice("pinningQA", "could not disable pinning: %@ not true", setting
);
1979 if (!pinningRequired
) {
1983 if(isCFPreferenceInSecurityDomain(CFSTR("AppleServerAuthenticationNoPinning"))) {
1984 pinningRequired
= false;
1986 secnotice("pinningQA", "could not disable pinning: AppleServerAuthenticationNoPinning not true");
1989 secnotice("pinningQA", "could not disable pinning: not an internal release");
1992 return pinningRequired
;
1995 SecPolicyRef
SecPolicyCreateAppleSSLPinned(CFStringRef policyName
, CFStringRef hostname
,
1996 CFStringRef intermediateMarkerOID
, CFStringRef leafMarkerOID
) {
1997 CFMutableDictionaryRef options
= NULL
, appleAnchorOptions
= NULL
;
1998 SecPolicyRef result
= NULL
;
2000 if (!policyName
|| !hostname
|| !leafMarkerOID
) {
2004 if (requireUATPinning(policyName
)) {
2005 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2006 &kCFTypeDictionaryKeyCallBacks
,
2007 &kCFTypeDictionaryValueCallBacks
), errOut
);
2009 SecPolicyAddBasicX509Options(options
);
2011 /* Anchored to the Apple Roots */
2012 require_quiet(appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
), errOut
);
2013 if (allowTestHierarchyForPolicy(policyName
, true)) {
2014 CFDictionarySetValue(appleAnchorOptions
,
2015 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
2017 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
2019 /* Exactly 3 certs in the chain */
2020 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2022 if (intermediateMarkerOID
) {
2023 /* Intermediate marker OID matches input OID */
2024 if (!isAppleOid(intermediateMarkerOID
)) {
2025 secwarning("creating an Apple pinning policy with a non-Apple OID: %@", intermediateMarkerOID
);
2027 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, intermediateMarkerOID
);
2029 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.12"));
2032 /* Leaf marker OID matches input OID */
2033 if (!isAppleOid(leafMarkerOID
)) {
2034 secwarning("creating an Apple pinning policy with a non-Apple OID: %@", leafMarkerOID
);
2036 add_leaf_marker_string(options
, leafMarkerOID
);
2038 /* New leaf marker OID format */
2039 add_leaf_marker_value_string(options
, CFSTR("1.2.840.113635.100.6.48.1"), leafMarkerOID
);
2041 /* ServerAuth EKU is in leaf cert */
2042 add_eku_string(options
, CFSTR("1.3.6.1.5.5.7.3.1"));
2044 /* Hostname is in leaf cert */
2045 add_element(options
, kSecPolicyCheckSSLHostname
, hostname
);
2047 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
2048 require(SecPolicyAddStrongKeySizeOptions(options
), errOut
);
2050 /* Check for weak hashes */
2051 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
2053 /* Check revocation using any available method */
2054 add_element(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
2056 require(result
= SecPolicyCreate(kSecPolicyAppleGenericAppleSSLPinned
,
2057 policyName
, options
), errOut
);
2060 result
= SecPolicyCreateSSL(true, hostname
);
2061 SecPolicySetOid(result
, kSecPolicyAppleGenericAppleSSLPinned
);
2065 CFReleaseSafe(options
);
2066 CFReleaseSafe(appleAnchorOptions
);
2070 SecPolicyRef
SecPolicyCreateiPhoneActivation(void) {
2071 CFMutableDictionaryRef options
= NULL
;
2072 SecPolicyRef result
= NULL
;
2074 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2075 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2077 SecPolicyAddBasicCertOptions(options
);
2080 CFDictionaryAddValue(options
, kSecPolicyCheckKeyUsage
,
2082 CFDictionaryAddValue(options
, kSecPolicyCheckExtendedKeyUsage
,
2086 /* Basic X.509 policy with the additional requirements that the chain
2087 length is 3, it's anchored at the AppleCA and the leaf certificate
2088 has issuer "Apple iPhone Certification Authority" and
2089 subject "Apple iPhone Activation" for the common name. */
2090 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2091 CFSTR("Apple iPhone Certification Authority"));
2092 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonName
,
2093 CFSTR("Apple iPhone Activation"));
2095 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2096 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameiPhoneActivation
), errOut
);
2098 require(result
= SecPolicyCreate(kSecPolicyAppleiPhoneActivation
,
2099 kSecPolicyNameiPhoneActivation
, options
),
2103 CFReleaseSafe(options
);
2107 SecPolicyRef
SecPolicyCreateiPhoneDeviceCertificate(void) {
2108 CFMutableDictionaryRef options
= NULL
;
2109 SecPolicyRef result
= NULL
;
2111 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2112 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2114 SecPolicyAddBasicCertOptions(options
);
2117 CFDictionaryAddValue(options
, kSecPolicyCheckKeyUsage
,
2119 CFDictionaryAddValue(options
, kSecPolicyCheckExtendedKeyUsage
,
2123 /* Basic X.509 policy with the additional requirements that the chain
2124 length is 4, it's anchored at the AppleCA and the first intermediate
2125 has the subject "Apple iPhone Device CA". */
2126 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2127 CFSTR("Apple iPhone Device CA"));
2129 require(SecPolicyAddChainLengthOptions(options
, 4), errOut
);
2130 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameiPhoneDeviceCertificate
), errOut
);
2132 require(result
= SecPolicyCreate(kSecPolicyAppleiPhoneDeviceCertificate
,
2133 kSecPolicyNameiPhoneDeviceCertificate
, options
),
2137 CFReleaseSafe(options
);
2141 SecPolicyRef
SecPolicyCreateFactoryDeviceCertificate(void) {
2142 CFMutableDictionaryRef options
= NULL
;
2143 SecPolicyRef result
= NULL
;
2145 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2146 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2148 SecPolicyAddBasicCertOptions(options
);
2151 CFDictionaryAddValue(options
, kSecPolicyCheckKeyUsage
,
2153 CFDictionaryAddValue(options
, kSecPolicyCheckExtendedKeyUsage
,
2157 /* Basic X.509 policy with the additional requirements that the chain
2158 is anchored at the factory device certificate issuer. */
2159 require(SecPolicyAddAnchorSHA1Options(options
, kFactoryDeviceCASHA1
), errOut
);
2161 require(result
= SecPolicyCreate(kSecPolicyAppleFactoryDeviceCertificate
,
2162 kSecPolicyNameFactoryDeviceCertificate
, options
),
2166 CFReleaseSafe(options
);
2170 SecPolicyRef
SecPolicyCreateiAP(void) {
2171 CFMutableDictionaryRef options
= NULL
;
2172 SecPolicyRef result
= NULL
;
2173 CFTimeZoneRef tz
= NULL
;
2174 CFDateRef date
= NULL
;
2176 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2177 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2179 SecPolicyAddBasicCertOptions(options
);
2181 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonNamePrefix
,
2184 date
= CFDateCreateForGregorianZuluDay(NULL
, 2006, 5, 31);
2185 CFDictionaryAddValue(options
, kSecPolicyCheckNotValidBefore
, date
);
2187 require(result
= SecPolicyCreate(kSecPolicyAppleiAP
,
2188 kSecPolicyNameiAP
, options
),
2192 CFReleaseSafe(date
);
2194 CFReleaseSafe(options
);
2198 SecPolicyRef
SecPolicyCreateiTunesStoreURLBag(void) {
2199 CFMutableDictionaryRef options
= NULL
;
2200 SecPolicyRef result
= NULL
;
2203 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2204 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2206 SecPolicyAddBasicCertOptions(options
);
2208 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectOrganization
,
2209 CFSTR("Apple Inc."));
2210 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonName
,
2211 CFSTR("iTunes Store URL Bag"));
2213 require(SecPolicyAddChainLengthOptions(options
, 2), errOut
);
2214 require(SecPolicyAddAnchorSHA1Options(options
, kITMSCASHA1
), errOut
);
2216 require(result
= SecPolicyCreate(kSecPolicyAppleiTunesStoreURLBag
,
2217 kSecPolicyNameiTunesStoreURLBag
, options
), errOut
);
2220 CFReleaseSafe(options
);
2224 SecPolicyRef
SecPolicyCreateEAP(Boolean server
, CFArrayRef trustedServerNames
) {
2225 CFMutableDictionaryRef options
= NULL
;
2226 SecPolicyRef result
= NULL
;
2228 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2229 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2231 SecPolicyAddBasicX509Options(options
);
2233 /* Since EAP is used to setup the network we don't want evaluation
2234 using this policy to access the network. */
2235 CFDictionaryAddValue(options
, kSecPolicyCheckNoNetworkAccess
,
2238 if (trustedServerNames
) {
2239 CFDictionaryAddValue(options
, kSecPolicyCheckEAPTrustedServerNames
, trustedServerNames
);
2243 /* Check for weak hashes */
2244 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
2247 /* We need to check for EKU per rdar://22206018 */
2248 set_ssl_ekus(options
, server
);
2250 require(result
= SecPolicyCreate(kSecPolicyAppleEAP
,
2251 server
? kSecPolicyNameEAPServer
: kSecPolicyNameEAPClient
,
2255 CFReleaseSafe(options
);
2259 SecPolicyRef
SecPolicyCreateIPSec(Boolean server
, CFStringRef hostname
) {
2260 CFMutableDictionaryRef options
= NULL
;
2261 SecPolicyRef result
= NULL
;
2263 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2264 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2266 SecPolicyAddBasicX509Options(options
);
2269 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
2272 /* Require oidExtendedKeyUsageIPSec if Extended Keyusage Extention is
2274 /* Per <rdar://problem/6843827> Cisco VPN Certificate compatibility issue.
2275 We don't check the EKU for IPSec certs for now. If we do add eku
2276 checking back in the future, we should probably also accept the
2278 ipsecEndSystem 1.3.6.1.5.5.7.3.5
2280 ipsecTunnel 1.3.6.1.5.5.7.3.6
2281 ipsecUser 1.3.6.1.5.5.7.3.7
2283 //add_eku(options, NULL); /* eku extension is optional */
2284 //add_eku(options, &oidAnyExtendedKeyUsage);
2285 //add_eku(options, &oidExtendedKeyUsageIPSec);
2287 require(result
= SecPolicyCreate(kSecPolicyAppleIPsec
,
2288 server
? kSecPolicyNameIPSecServer
: kSecPolicyNameIPSecClient
,
2292 CFReleaseSafe(options
);
2296 SecPolicyRef
SecPolicyCreateiPhoneApplicationSigning(void) {
2297 CFMutableDictionaryRef options
= NULL
, appleAnchorOptions
= NULL
;
2298 SecPolicyRef result
= NULL
;
2300 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2301 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2303 SecPolicyAddBasicCertOptions(options
);
2305 appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
);
2306 require(appleAnchorOptions
, errOut
);
2308 if (allowTestHierarchyForPolicy(kSecPolicyNameiPhoneApplicationSigning
, false)) {
2309 /* Allow a test hierarchy-signed cert with prod name/OIDs */
2310 CFDictionarySetValue(appleAnchorOptions
,
2311 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
2315 if (SecIsInternalRelease()) {
2316 /* Allow a prod hierarchy-signed test cert */
2317 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonNameTEST
,
2318 CFSTR("Apple iPhone OS Application Signing"));
2319 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.3.1"));
2320 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.6.1"));
2322 /* or a test hierarchy-signed test cert */
2323 CFDictionarySetValue(appleAnchorOptions
,
2324 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
2327 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonName
,
2328 CFSTR("Apple iPhone OS Application Signing"));
2330 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.3"));
2331 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.6"));
2333 add_eku(options
, NULL
); /* eku extension is optional */
2334 add_eku(options
, &oidAnyExtendedKeyUsage
);
2335 add_eku(options
, &oidExtendedKeyUsageCodeSigning
);
2337 /* Intermediate check */
2338 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2339 CFSTR("Apple iPhone Certification Authority"));
2341 /* Chain length check */
2342 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2344 /* Anchored to the Apple Roots */
2345 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
2347 require(result
= SecPolicyCreate(kSecPolicyAppleiPhoneApplicationSigning
,
2348 kSecPolicyNameiPhoneApplicationSigning
, options
),
2352 CFReleaseSafe(options
);
2353 CFReleaseSafe(appleAnchorOptions
);
2357 SecPolicyRef
SecPolicyCreateiPhoneProfileApplicationSigning(void) {
2358 CFMutableDictionaryRef options
= NULL
;
2359 SecPolicyRef result
= NULL
;
2361 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2362 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2363 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
2364 CFDictionaryAddValue(options
, kSecPolicyCheckValidLeaf
, kCFBooleanFalse
);
2366 require(result
= SecPolicyCreate(kSecPolicyAppleiPhoneProfileApplicationSigning
,
2367 kSecPolicyNameiPhoneProfileApplicationSigning
,
2371 CFReleaseSafe(options
);
2375 SecPolicyRef
SecPolicyCreateiPhoneProvisioningProfileSigning(void) {
2376 CFMutableDictionaryRef options
= NULL
;
2377 SecPolicyRef result
= NULL
;
2379 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2380 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2382 SecPolicyAddBasicCertOptions(options
);
2384 /* Basic X.509 policy with the additional requirements that the chain
2385 length is 3, it's anchored at the AppleCA and the leaf certificate
2386 has issuer "Apple iPhone Certification Authority" and
2387 subject "Apple iPhone OS Provisioning Profile Signing" for the common name. */
2388 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2389 CFSTR("Apple iPhone Certification Authority"));
2390 if (SecIsInternalRelease()) {
2391 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonNameTEST
,
2392 CFSTR("Apple iPhone OS Provisioning Profile Signing"));
2395 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonName
,
2396 CFSTR("Apple iPhone OS Provisioning Profile Signing"));
2399 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2400 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameiPhoneProvisioningProfileSigning
), errOut
);
2402 require(result
= SecPolicyCreate(kSecPolicyAppleiPhoneProvisioningProfileSigning
,
2403 kSecPolicyNameiPhoneProvisioningProfileSigning
, options
),
2406 /* 1.2.840.113635.100.6.2.2.1, non-critical: DER:05:00 - provisioning profile */
2409 CFReleaseSafe(options
);
2413 SecPolicyRef
SecPolicyCreateAppleTVOSApplicationSigning(void) {
2414 CFMutableDictionaryRef options
= NULL
;
2415 SecPolicyRef result
= NULL
;
2416 CFDataRef atvProdOid
= NULL
;
2417 CFDataRef atvTestOid
= NULL
;
2418 CFArrayRef oids
= NULL
;
2420 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2421 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2423 SecPolicyAddBasicCertOptions(options
);
2425 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2427 require_quiet(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleTVOSApplicationSigning
),
2430 /* Check for intermediate: Apple Worldwide Developer Relations */
2431 /* 1.2.840.113635.100.6.2.1 */
2432 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleWWDR
);
2434 add_ku(options
, kSecKeyUsageDigitalSignature
);
2436 /* Check for prod or test AppleTV Application Signing OIDs */
2437 /* Prod: 1.2.840.113635.100.6.1.24 */
2438 /* ProdQA: 1.2.840.113635.100.6.1.24.1 */
2439 add_leaf_marker(options
, &oidAppleTVOSApplicationSigningProd
);
2440 add_leaf_marker(options
, &oidAppleTVOSApplicationSigningProdQA
);
2442 require(result
= SecPolicyCreate(kSecPolicyAppleTVOSApplicationSigning
,
2443 kSecPolicyNameAppleTVOSApplicationSigning
, options
),
2447 CFReleaseSafe(options
);
2448 CFReleaseSafe(oids
);
2449 CFReleaseSafe(atvProdOid
);
2450 CFReleaseSafe(atvTestOid
);
2454 SecPolicyRef
SecPolicyCreateOCSPSigner(void) {
2455 CFMutableDictionaryRef options
= NULL
;
2456 SecPolicyRef result
= NULL
;
2458 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2459 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2461 SecPolicyAddBasicX509Options(options
);
2463 /* Require id-kp-OCSPSigning extendedKeyUsage to be present, not optional. */
2464 add_eku(options
, &oidExtendedKeyUsageOCSPSigning
);
2466 require(result
= SecPolicyCreate(kSecPolicyAppleOCSPSigner
,
2467 kSecPolicyNameOCSPSigner
, options
), errOut
);
2470 CFReleaseSafe(options
);
2474 const CFOptionFlags kSecRevocationOnlineCheck
= (1 << 5);
2476 SecPolicyRef
SecPolicyCreateRevocation(CFOptionFlags revocationFlags
) {
2477 CFMutableDictionaryRef options
= NULL
;
2478 SecPolicyRef result
= NULL
;
2480 require(revocationFlags
!= 0, errOut
);
2482 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2483 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2485 if (revocationFlags
& kSecRevocationOCSPMethod
&& revocationFlags
& kSecRevocationCRLMethod
) {
2486 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
2488 else if (revocationFlags
& kSecRevocationOCSPMethod
) {
2489 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
2491 else if (revocationFlags
& kSecRevocationCRLMethod
) {
2492 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationCRL
);
2495 if (revocationFlags
& kSecRevocationRequirePositiveResponse
) {
2496 CFDictionaryAddValue(options
, kSecPolicyCheckRevocationResponseRequired
, kCFBooleanTrue
);
2499 if (revocationFlags
& kSecRevocationNetworkAccessDisabled
) {
2500 CFDictionaryAddValue(options
, kSecPolicyCheckNoNetworkAccess
, kCFBooleanTrue
);
2502 /* If the caller didn't explicitly disable network access, the revocation policy
2503 * should override any other policy's network setting.
2504 * In particular, pairing a revocation policy with BasicX509 should result in
2505 * allowing network access for revocation unless explicitly disabled.
2506 * Note that SecTrustSetNetworkFetchAllowed can override even this. */
2507 CFDictionaryAddValue(options
, kSecPolicyCheckNoNetworkAccess
, kCFBooleanFalse
);
2510 if (revocationFlags
& kSecRevocationOnlineCheck
) {
2511 CFDictionaryAddValue(options
, kSecPolicyCheckRevocationOnline
, kCFBooleanTrue
);
2514 /* Only flag bits 0-5 are currently defined */
2515 require(((revocationFlags
>> 6) == 0), errOut
);
2517 require(result
= SecPolicyCreate(kSecPolicyAppleRevocation
,
2518 kSecPolicyNameRevocation
, options
), errOut
);
2521 CFReleaseSafe(options
);
2525 SecPolicyRef
SecPolicyCreateSMIME(CFIndex smimeUsage
, CFStringRef email
) {
2526 CFMutableDictionaryRef options
= NULL
;
2527 SecPolicyRef result
= NULL
;
2529 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2530 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2532 SecPolicyAddBasicX509Options(options
);
2534 /* We call add_ku for each combination of bits we are willing to allow. */
2535 if (smimeUsage
& kSecSignSMIMEUsage
) {
2536 add_ku(options
, kSecKeyUsageUnspecified
);
2537 add_ku(options
, kSecKeyUsageDigitalSignature
);
2538 add_ku(options
, kSecKeyUsageNonRepudiation
);
2540 if (smimeUsage
& kSecKeyEncryptSMIMEUsage
) {
2541 add_ku(options
, kSecKeyUsageKeyEncipherment
);
2543 if (smimeUsage
& kSecDataEncryptSMIMEUsage
) {
2544 add_ku(options
, kSecKeyUsageDataEncipherment
);
2546 if (smimeUsage
& kSecKeyExchangeDecryptSMIMEUsage
) {
2547 add_ku(options
, kSecKeyUsageKeyAgreement
| kSecKeyUsageDecipherOnly
);
2549 if (smimeUsage
& kSecKeyExchangeEncryptSMIMEUsage
) {
2550 add_ku(options
, kSecKeyUsageKeyAgreement
| kSecKeyUsageEncipherOnly
);
2552 if (smimeUsage
& kSecKeyExchangeBothSMIMEUsage
) {
2553 add_ku(options
, kSecKeyUsageKeyAgreement
| kSecKeyUsageEncipherOnly
| kSecKeyUsageDecipherOnly
);
2557 CFDictionaryAddValue(options
, kSecPolicyCheckEmail
, email
);
2560 /* RFC 3850 paragraph 4.4.4
2562 If the extended key usage extension is present in the certificate
2563 then interpersonal message S/MIME receiving agents MUST check that it
2564 contains either the emailProtection or the anyExtendedKeyUsage OID as
2565 defined in [KEYM]. S/MIME uses other than interpersonal messaging
2566 MAY require the explicit presence of the extended key usage extension
2567 or other OIDs to be present in the extension or both.
2569 add_eku(options
, NULL
); /* eku extension is optional */
2570 add_eku(options
, &oidAnyExtendedKeyUsage
);
2571 add_eku(options
, &oidExtendedKeyUsageEmailProtection
);
2573 #if !TARGET_OS_IPHONE
2574 // Check revocation on OS X
2575 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
2578 require(result
= SecPolicyCreate(kSecPolicyAppleSMIME
, kSecPolicyNameSMIME
, options
), errOut
);
2581 CFReleaseSafe(options
);
2585 SecPolicyRef
SecPolicyCreateApplePackageSigning(void) {
2586 CFMutableDictionaryRef options
= NULL
;
2587 SecPolicyRef result
= NULL
;
2589 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2590 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2592 SecPolicyAddBasicCertOptions(options
);
2594 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2595 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNamePackageSigning
), errOut
);
2597 add_ku(options
, kSecKeyUsageDigitalSignature
);
2598 add_eku(options
, &oidExtendedKeyUsageCodeSigning
);
2600 require(result
= SecPolicyCreate(kSecPolicyApplePackageSigning
,
2601 kSecPolicyNamePackageSigning
, options
),
2605 CFReleaseSafe(options
);
2610 SecPolicyRef
SecPolicyCreateAppleSWUpdateSigning(void) {
2611 CFMutableDictionaryRef options
= NULL
;
2612 SecPolicyRef result
= NULL
;
2614 * OS X rules for this policy:
2615 * -- Must have one intermediate cert
2616 * -- intermediate must have basic constraints with path length 0
2617 * -- intermediate has CSSMOID_APPLE_EKU_CODE_SIGNING EKU
2618 * -- leaf cert has either CODE_SIGNING or CODE_SIGN_DEVELOPMENT EKU (the latter of
2619 * which triggers a CSSMERR_APPLETP_CODE_SIGN_DEVELOPMENT error)
2621 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2622 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2624 SecPolicyAddBasicX509Options(options
);
2626 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2627 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleSWUpdateSigning
), errOut
);
2629 add_eku(options
, &oidAppleExtendedKeyUsageCodeSigning
);
2630 add_oid(options
, kSecPolicyCheckIntermediateEKU
, &oidAppleExtendedKeyUsageCodeSigning
);
2632 require(result
= SecPolicyCreate(kSecPolicyAppleSWUpdateSigning
,
2633 kSecPolicyNameAppleSWUpdateSigning
, options
),
2637 CFReleaseSafe(options
);
2642 SecPolicyRef
SecPolicyCreateCodeSigning(void) {
2643 CFMutableDictionaryRef options
= NULL
;
2644 SecPolicyRef result
= NULL
;
2646 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2647 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2649 SecPolicyAddBasicX509Options(options
);
2651 /* If the key usage extension is present, we accept it having either of
2653 add_ku(options
, kSecKeyUsageDigitalSignature
);
2654 add_ku(options
, kSecKeyUsageNonRepudiation
);
2656 /* We require an extended key usage extension with the codesigning
2657 eku purpose. (The Apple codesigning eku is not accepted here
2658 since it's valid only for SecPolicyCreateAppleSWUpdateSigning.) */
2659 add_eku(options
, &oidExtendedKeyUsageCodeSigning
);
2660 #if TARGET_OS_IPHONE
2661 /* Accept the 'any' eku on iOS only to match prior behavior.
2662 This may be further restricted in future releases. */
2663 add_eku(options
, &oidAnyExtendedKeyUsage
);
2666 require(result
= SecPolicyCreate(kSecPolicyAppleCodeSigning
,
2667 kSecPolicyNameCodeSigning
, options
),
2671 CFReleaseSafe(options
);
2675 /* Explicitly leave out empty subject/subjectaltname check */
2676 SecPolicyRef
SecPolicyCreateLockdownPairing(void) {
2677 CFMutableDictionaryRef options
= NULL
;
2678 SecPolicyRef result
= NULL
;
2680 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2681 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2682 //CFDictionaryAddValue(options, kSecPolicyCheckBasicCertificateProcessing,
2683 // kCFBooleanTrue); // Happens automatically in SecPVCPathChecks
2684 CFDictionaryAddValue(options
, kSecPolicyCheckCriticalExtensions
,
2686 CFDictionaryAddValue(options
, kSecPolicyCheckIdLinkage
,
2688 CFDictionaryAddValue(options
, kSecPolicyCheckBasicConstraints
,
2690 CFDictionaryAddValue(options
, kSecPolicyCheckQualifiedCertStatements
,
2692 CFDictionaryAddValue(options
, kSecPolicyCheckWeakIntermediates
, kCFBooleanTrue
);
2693 CFDictionaryAddValue(options
, kSecPolicyCheckWeakLeaf
, kCFBooleanTrue
);
2694 CFDictionaryAddValue(options
, kSecPolicyCheckWeakRoot
, kCFBooleanTrue
);
2696 require(result
= SecPolicyCreate(kSecPolicyAppleLockdownPairing
,
2697 kSecPolicyNameLockdownPairing
, options
), errOut
);
2700 CFReleaseSafe(options
);
2704 SecPolicyRef
SecPolicyCreateURLBag(void) {
2705 CFMutableDictionaryRef options
= NULL
;
2706 SecPolicyRef result
= NULL
;
2708 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2709 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2711 SecPolicyAddBasicCertOptions(options
);
2713 add_eku(options
, &oidExtendedKeyUsageCodeSigning
);
2715 require(result
= SecPolicyCreate(kSecPolicyAppleURLBag
,
2716 kSecPolicyNameURLBag
, options
), errOut
);
2719 CFReleaseSafe(options
);
2723 static bool SecPolicyAddAppleCertificationAuthorityOptions(CFMutableDictionaryRef options
, bool honorValidity
, CFStringRef policyName
)
2725 bool success
= false;
2728 SecPolicyAddBasicX509Options(options
);
2730 SecPolicyAddBasicCertOptions(options
);
2733 CFDictionaryAddValue(options
, kSecPolicyCheckKeyUsage
,
2735 CFDictionaryAddValue(options
, kSecPolicyCheckExtendedKeyUsage
,
2739 /* Basic X.509 policy with the additional requirements that the chain
2740 length is 3, it's anchored at the AppleCA and the leaf certificate
2741 has issuer "Apple iPhone Certification Authority". */
2742 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2743 CFSTR("Apple iPhone Certification Authority"));
2745 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2746 require(SecPolicyAddAppleAnchorOptions(options
, policyName
), errOut
);
2754 static SecPolicyRef
SecPolicyCreateAppleCertificationAuthorityPolicy(CFStringRef policyOID
, CFStringRef policyName
,
2755 CFStringRef leafName
, bool honorValidity
)
2757 CFMutableDictionaryRef options
= NULL
;
2758 SecPolicyRef result
= NULL
;
2760 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2761 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
), errOut
);
2763 require(SecPolicyAddAppleCertificationAuthorityOptions(options
, honorValidity
, policyName
), errOut
);
2765 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectCommonName
, leafName
);
2767 require(result
= SecPolicyCreate(policyOID
, policyName
, options
),
2771 CFReleaseSafe(options
);
2776 SecPolicyRef
SecPolicyCreateOTATasking(void)
2778 return SecPolicyCreateAppleCertificationAuthorityPolicy(kSecPolicyAppleOTATasking
,
2779 kSecPolicyNameOTATasking
,
2780 CFSTR("OTA Task Signing"), true);
2783 SecPolicyRef
SecPolicyCreateMobileAsset(void)
2785 return SecPolicyCreateAppleCertificationAuthorityPolicy(kSecPolicyAppleMobileAsset
,
2786 kSecPolicyNameMobileAsset
,
2787 CFSTR("Asset Manifest Signing"), false);
2790 SecPolicyRef
SecPolicyCreateAppleIDAuthorityPolicy(void)
2792 SecPolicyRef result
= NULL
;
2793 CFMutableDictionaryRef options
= NULL
;
2794 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2795 &kCFTypeDictionaryKeyCallBacks
,
2796 &kCFTypeDictionaryValueCallBacks
), out
);
2798 //Leaf appears to be a SSL only cert, so policy should expand on that policy
2799 SecPolicyAddBasicX509Options(options
);
2801 // Apple CA anchored
2802 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleIDAuthority
), out
);
2804 // with the addition of the existence check of an extension with "Apple ID Sharing Certificate" oid (1.2.840.113635.100.4.7)
2805 // NOTE: this obviously intended to have gone into Extended Key Usage, but evidence of existing certs proves the contrary.
2806 add_leaf_marker(options
, &oidAppleExtendedKeyUsageAppleID
);
2808 // and validate that intermediate has extension with CSSMOID_APPLE_EXTENSION_AAI_INTERMEDIATE oid (1.2.840.113635.100.6.2.3) and goes back to the Apple Root CA.
2809 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleID
);
2810 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleID2
);
2812 require(result
= SecPolicyCreate(kSecPolicyAppleIDAuthority
,
2813 kSecPolicyNameAppleIDAuthority
, options
), out
);
2816 CFReleaseSafe(options
);
2820 SecPolicyRef
SecPolicyCreateMacAppStoreReceipt(void)
2822 SecPolicyRef result
= NULL
;
2823 CFMutableDictionaryRef options
= NULL
;
2824 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2825 &kCFTypeDictionaryKeyCallBacks
,
2826 &kCFTypeDictionaryValueCallBacks
), out
);
2828 SecPolicyAddBasicX509Options(options
);
2830 // Apple CA anchored
2831 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameMacAppStoreReceipt
), out
);
2833 // Chain length of 3
2834 require(SecPolicyAddChainLengthOptions(options
, 3), out
);
2836 // MacAppStoreReceipt policy OID
2837 add_certificate_policy_oid_string(options
, CFSTR("1.2.840.113635.100.5.6.1"));
2839 // Intermediate marker OID
2840 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.1"));
2843 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.11.1"));
2846 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
2848 require(result
= SecPolicyCreate(kSecPolicyMacAppStoreReceipt
,
2849 kSecPolicyNameMacAppStoreReceipt
, options
), out
);
2852 CFReleaseSafe(options
);
2857 static SecPolicyRef
_SecPolicyCreatePassbookCardSigner(CFStringRef cardIssuer
, CFStringRef teamIdentifier
, bool requireTeamID
)
2859 SecPolicyRef result
= NULL
;
2860 CFMutableDictionaryRef options
= NULL
;
2861 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2862 &kCFTypeDictionaryKeyCallBacks
,
2863 &kCFTypeDictionaryValueCallBacks
), out
);
2865 SecPolicyAddBasicX509Options(options
);
2866 SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameApplePassbook
);
2868 // Chain length of 3
2869 require(SecPolicyAddChainLengthOptions(options
, 3), out
);
2871 if (teamIdentifier
) {
2872 // If supplied, teamIdentifier must match subject OU field
2873 CFDictionaryAddValue(options
, kSecPolicyCheckSubjectOrganizationalUnit
, teamIdentifier
);
2876 // If not supplied, and it was required, fail
2877 require(!requireTeamID
, out
);
2880 // Must be both push and 3rd party package signing
2881 add_leaf_marker_value(options
, &oidAppleInstallerPackagingSigningExternal
, cardIssuer
);
2883 // We should check that it also has push marker, but we don't support requiring both, only either.
2884 // add_independent_oid(options, kSecPolicyCheckLeafMarkerOid, &oidApplePushServiceClient);
2886 //WWDR Intermediate marker OID
2887 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.1"));
2889 // And Passbook signing eku
2890 add_eku(options
, &oidAppleExtendedKeyUsagePassbook
);
2892 require(result
= SecPolicyCreate(kSecPolicyApplePassbookSigning
,
2893 kSecPolicyNameApplePassbook
, options
), out
);
2896 CFReleaseSafe(options
);
2900 SecPolicyRef
SecPolicyCreatePassbookCardSigner(CFStringRef cardIssuer
, CFStringRef teamIdentifier
)
2902 return _SecPolicyCreatePassbookCardSigner(cardIssuer
, teamIdentifier
, true);
2906 static SecPolicyRef
CreateMobileStoreSigner(Boolean forTest
)
2909 SecPolicyRef result
= NULL
;
2910 CFMutableDictionaryRef options
= NULL
;
2911 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2912 &kCFTypeDictionaryKeyCallBacks
,
2913 &kCFTypeDictionaryValueCallBacks
), errOut
);
2914 SecPolicyAddBasicX509Options(options
);
2915 SecPolicyAddAppleAnchorOptions(options
,
2916 ((forTest
) ? kSecPolicyNameAppleTestMobileStore
:
2917 kSecPolicyNameAppleMobileStore
));
2919 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
2921 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
2922 CFSTR("Apple System Integration 2 Certification Authority"));
2924 add_ku(options
, kSecKeyUsageDigitalSignature
);
2926 const DERItem
* pOID
= (forTest
) ? &oidApplePolicyMobileStoreProdQA
: &oidApplePolicyMobileStore
;
2928 add_certificate_policy_oid(options
, pOID
);
2930 require(result
= SecPolicyCreate((forTest
) ? kSecPolicyAppleTestMobileStore
: kSecPolicyAppleMobileStore
,
2931 (forTest
) ? kSecPolicyNameAppleTestMobileStore
: kSecPolicyNameAppleMobileStore
,
2935 CFReleaseSafe(options
);
2939 SecPolicyRef
SecPolicyCreateMobileStoreSigner(void)
2941 return CreateMobileStoreSigner(false);
2944 SecPolicyRef
SecPolicyCreateTestMobileStoreSigner(void)
2946 return CreateMobileStoreSigner(true);
2950 CF_RETURNS_RETAINED SecPolicyRef
SecPolicyCreateEscrowServiceSigner(void)
2952 SecPolicyRef result
= NULL
;
2953 CFMutableDictionaryRef options
= NULL
;
2954 CFArrayRef anArray
= NULL
;
2955 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2956 &kCFTypeDictionaryKeyCallBacks
,
2957 &kCFTypeDictionaryValueCallBacks
), errOut
);
2959 // X509, ignoring date validity
2960 SecPolicyAddBasicCertOptions(options
);
2963 add_ku(options
, kSecKeyUsageKeyEncipherment
);
2965 //add_leaf_marker(options, &oidApplePolicyEscrowService);
2966 require(SecPolicyAddChainLengthOptions(options
, 2), errOut
);
2969 Boolean anchorAdded
= false;
2970 // Get the roots by calling the SecCertificateCopyEscrowRoots
2971 anArray
= SecCertificateCopyEscrowRoots(kSecCertificateProductionEscrowRoot
);
2972 CFIndex numRoots
= 0;
2973 if (NULL
== anArray
|| 0 == (numRoots
= CFArrayGetCount(anArray
)))
2978 for (CFIndex iCnt
= 0; iCnt
< numRoots
; iCnt
++)
2980 SecCertificateRef aCert
= (SecCertificateRef
)CFArrayGetValueAtIndex(anArray
, iCnt
);
2984 CFDataRef sha_data
= SecCertificateGetSHA1Digest(aCert
);
2985 if (NULL
!= sha_data
)
2987 const UInt8
* pSHAData
= CFDataGetBytePtr(sha_data
);
2988 if (NULL
!= pSHAData
)
2990 SecPolicyAddAnchorSHA1Options(options
, pSHAData
);
2996 CFReleaseNull(anArray
);
3004 require(result
= SecPolicyCreate(kSecPolicyAppleEscrowService
,
3005 kSecPolicyNameAppleEscrowService
, options
), errOut
);
3008 CFReleaseSafe(anArray
);
3009 CFReleaseSafe(options
);
3013 CF_RETURNS_RETAINED SecPolicyRef
SecPolicyCreatePCSEscrowServiceSigner(void)
3015 SecPolicyRef result
= NULL
;
3016 CFMutableDictionaryRef options
= NULL
;
3017 CFArrayRef anArray
= NULL
;
3018 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3019 &kCFTypeDictionaryKeyCallBacks
,
3020 &kCFTypeDictionaryValueCallBacks
), errOut
);
3022 SecPolicyAddBasicX509Options(options
);
3025 add_ku(options
, kSecKeyUsageKeyEncipherment
);
3027 //add_leaf_marker(options, &oidApplePolicyEscrowService);
3028 require(SecPolicyAddChainLengthOptions(options
, 2), errOut
);
3031 Boolean anchorAdded
= false;
3032 anArray
= SecCertificateCopyEscrowRoots(kSecCertificateProductionPCSEscrowRoot
);
3033 CFIndex numRoots
= 0;
3034 if (NULL
== anArray
|| 0 == (numRoots
= CFArrayGetCount(anArray
)))
3039 for (CFIndex iCnt
= 0; iCnt
< numRoots
; iCnt
++)
3041 SecCertificateRef aCert
= (SecCertificateRef
)CFArrayGetValueAtIndex(anArray
, iCnt
);
3045 CFDataRef sha_data
= SecCertificateGetSHA1Digest(aCert
);
3046 if (NULL
!= sha_data
)
3048 const UInt8
* pSHAData
= CFDataGetBytePtr(sha_data
);
3049 if (NULL
!= pSHAData
)
3051 SecPolicyAddAnchorSHA1Options(options
, pSHAData
);
3057 CFReleaseNull(anArray
);
3065 require(result
= SecPolicyCreate(kSecPolicyApplePCSEscrowService
,
3066 kSecPolicyNameApplePCSEscrowService
, options
), errOut
);
3069 CFReleaseSafe(anArray
);
3070 CFReleaseSafe(options
);
3074 static SecPolicyRef
CreateConfigurationProfileSigner(bool forTest
) {
3075 SecPolicyRef result
= NULL
;
3076 CFMutableDictionaryRef options
= NULL
;
3077 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3078 &kCFTypeDictionaryKeyCallBacks
,
3079 &kCFTypeDictionaryValueCallBacks
), errOut
);
3081 SecPolicyAddBasicX509Options(options
);
3082 SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleProfileSigner
);
3085 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3087 // Require the profile signing EKU
3088 const DERItem
* pOID
= (forTest
) ? &oidAppleExtendedKeyUsageQAProfileSigning
:&oidAppleExtendedKeyUsageProfileSigning
;
3089 add_eku(options
, pOID
);
3091 // Require the Apple Application Integration CA marker OID
3092 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.3"));
3094 require(result
= SecPolicyCreate((forTest
) ? kSecPolicyAppleQAProfileSigner
: kSecPolicyAppleProfileSigner
,
3095 (forTest
) ? kSecPolicyNameAppleQAProfileSigner
: kSecPolicyNameAppleProfileSigner
,
3099 CFReleaseSafe(options
);
3103 SecPolicyRef
SecPolicyCreateConfigurationProfileSigner(void)
3105 return CreateConfigurationProfileSigner(false);
3109 SecPolicyRef
SecPolicyCreateQAConfigurationProfileSigner(void)
3111 if (SecIsInternalRelease()) {
3112 return CreateConfigurationProfileSigner(true);
3114 return CreateConfigurationProfileSigner(false);
3118 SecPolicyRef
SecPolicyCreateOSXProvisioningProfileSigning(void)
3120 SecPolicyRef result
= NULL
;
3121 CFMutableDictionaryRef options
= NULL
;
3122 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3123 &kCFTypeDictionaryKeyCallBacks
,
3124 &kCFTypeDictionaryValueCallBacks
), errOut
);
3125 // Require valid chain from the Apple root
3126 SecPolicyAddBasicX509Options(options
);
3127 SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleOSXProvisioningProfileSigning
);
3129 // Require provisioning profile leaf marker OID (1.2.840.113635.100.4.11)
3130 add_leaf_marker(options
, &oidAppleCertExtOSXProvisioningProfileSigning
);
3132 // Require intermediate marker OID (1.2.840.113635.100.6.2.1)
3133 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleWWDR
);
3135 // Require key usage that allows signing
3136 add_ku(options
, kSecKeyUsageDigitalSignature
);
3138 // Ensure that revocation is checked (OCSP)
3139 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
3141 require(result
= SecPolicyCreate(kSecPolicyAppleOSXProvisioningProfileSigning
,
3142 kSecPolicyNameAppleOSXProvisioningProfileSigning
, options
), errOut
);
3145 CFReleaseSafe(options
);
3150 SecPolicyRef
SecPolicyCreateOTAPKISigner(void)
3152 SecPolicyRef result
= NULL
;
3153 CFMutableDictionaryRef options
= NULL
;
3154 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3155 &kCFTypeDictionaryKeyCallBacks
,
3156 &kCFTypeDictionaryValueCallBacks
), errOut
);
3157 SecPolicyAddBasicX509Options(options
);
3159 SecPolicyAddAnchorSHA1Options(options
, kApplePKISettingsAuthority
);
3160 require(SecPolicyAddChainLengthOptions(options
, 2), errOut
);
3162 require(result
= SecPolicyCreate(kSecPolicyAppleOTAPKISigner
,
3163 kSecPolicyNameAppleOTAPKIAssetSigner
, options
), errOut
);
3166 CFReleaseSafe(options
);
3172 SecPolicyRef
SecPolicyCreateTestOTAPKISigner(void)
3174 /* Guard against use on production devices */
3175 if (!SecIsInternalRelease()) {
3176 return SecPolicyCreateOTAPKISigner();
3179 SecPolicyRef result
= NULL
;
3180 CFMutableDictionaryRef options
= NULL
;
3181 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3182 &kCFTypeDictionaryKeyCallBacks
,
3183 &kCFTypeDictionaryValueCallBacks
), errOut
);
3184 SecPolicyAddBasicX509Options(options
);
3186 SecPolicyAddAnchorSHA1Options(options
, kAppleTestPKISettingsAuthority
);
3187 require(SecPolicyAddChainLengthOptions(options
, 2), errOut
);
3189 require(result
= SecPolicyCreate(kSecPolicyAppleTestOTAPKISigner
,
3190 kSecPolicyNameAppleTestOTAPKIAssetSigner
, options
), errOut
);
3193 CFReleaseSafe(options
);
3198 @function SecPolicyCreateAppleSMPEncryption
3199 @abstract Check for intermediate certificate 'Apple System Integration CA - G3' by name,
3200 and root certificate 'Apple Root CA - G3' by hash.
3201 Leaf cert must have Key Encipherment usage.
3202 Leaf cert must have Apple SMP Encryption marker OID (1.2.840.113635.100.6.30).
3203 Intermediate must have marker OID (1.2.840.113635.100.6.2.13).
3205 SecPolicyRef
SecPolicyCreateAppleSMPEncryption(void)
3207 SecPolicyRef result
= NULL
;
3208 CFMutableDictionaryRef options
= NULL
;
3209 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3210 &kCFTypeDictionaryKeyCallBacks
,
3211 &kCFTypeDictionaryValueCallBacks
), errOut
);
3212 SecPolicyAddBasicCertOptions(options
);
3214 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleSMPEncryption
),
3216 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3218 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
3219 CFSTR("Apple System Integration CA - G3"));
3221 // Check that leaf has extension with "Apple SMP Encryption" oid (1.2.840.113635.100.6.30)
3222 add_leaf_marker(options
, &oidAppleCertExtAppleSMPEncryption
);
3224 // Check that intermediate has extension (1.2.840.113635.100.6.2.13)
3225 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleSystemIntgG3
);
3227 add_ku(options
, kSecKeyUsageKeyEncipherment
);
3229 // Ensure that revocation is checked (OCSP)
3230 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
3232 require(result
= SecPolicyCreate(kSecPolicyAppleSMPEncryption
,
3233 kSecPolicyNameAppleSMPEncryption
, options
), errOut
);
3236 CFReleaseSafe(options
);
3241 @function SecPolicyCreateTestAppleSMPEncryption
3242 @abstract Check for intermediate certificate 'Test Apple System Integration CA - ECC' by name,
3243 and root certificate 'Test Apple Root CA - ECC' by hash.
3244 Leaf cert must have Key Encipherment usage. Other checks TBD.
3246 SecPolicyRef
SecPolicyCreateTestAppleSMPEncryption(void)
3248 SecPolicyRef result
= NULL
;
3249 CFMutableDictionaryRef options
= NULL
;
3250 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3251 &kCFTypeDictionaryKeyCallBacks
,
3252 &kCFTypeDictionaryValueCallBacks
), errOut
);
3253 SecPolicyAddBasicCertOptions(options
);
3255 SecPolicyAddAnchorSHA1Options(options
, kTestAppleRootCA_ECC_SHA1
);
3256 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3258 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
3259 CFSTR("Test Apple System Integration CA - ECC"));
3261 add_ku(options
, kSecKeyUsageKeyEncipherment
);
3263 // Ensure that revocation is checked (OCSP)
3264 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
3266 require(result
= SecPolicyCreate(kSecPolicyAppleTestSMPEncryption
,
3267 kSecPolicyNameAppleTestSMPEncryption
, options
), errOut
);
3270 CFReleaseSafe(options
);
3275 SecPolicyRef
SecPolicyCreateAppleIDValidationRecordSigningPolicy(void)
3277 SecPolicyRef result
= NULL
;
3278 CFMutableDictionaryRef options
= NULL
;
3279 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3280 &kCFTypeDictionaryKeyCallBacks
,
3281 &kCFTypeDictionaryValueCallBacks
), errOut
);
3283 //Leaf appears to be a SSL only cert, so policy should expand on that policy
3284 SecPolicyAddBasicX509Options(options
);
3286 // Apple CA anchored
3287 require(SecPolicyAddAppleAnchorOptions(options
,
3288 kSecPolicyNameAppleIDValidationRecordSigningPolicy
),
3291 // Check for an extension with " Apple ID Validation Record Signing" oid (1.2.840.113635.100.6.25)
3292 add_leaf_marker(options
, &oidAppleCertExtensionAppleIDRecordValidationSigning
);
3294 // and validate that intermediate has extension
3295 // Application Integration Intermediate Certificate (1.2.840.113635.100.6.2.3)
3296 // and also validate that intermediate has extension
3297 // System Integration 2 Intermediate Certificate (1.2.840.113635.100.6.2.10)
3298 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleID
);
3299 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleSystemIntg2
);
3301 // Ensure that revocation is checked (OCSP)
3302 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
3304 require(result
= SecPolicyCreate(kSecPolicyAppleIDValidationRecordSigning
,
3305 kSecPolicyNameAppleIDValidationRecordSigningPolicy
, options
), errOut
);
3308 CFReleaseSafe(options
);
3313 allowUATRoot(CFStringRef service
, CFDictionaryRef context
)
3315 bool UATAllowed
= false;
3316 CFStringRef setting
= NULL
;
3317 setting
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("AppleServerAuthenticationAllowUAT%@"), service
);
3318 CFTypeRef value
= NULL
;
3319 require(setting
, fail
);
3322 CFDictionaryGetValueIfPresent(context
, setting
, &value
) &&
3324 CFBooleanGetValue(value
))
3329 /* CFPreference for this service */
3330 if (isCFPreferenceInSecurityDomain(setting
)) {
3335 secnotice("pinningQA", "could not enable test cert: %@ not true", setting
);
3340 /* Generic CFPreference */
3341 if (isCFPreferenceInSecurityDomain(CFSTR("AppleServerAuthenticationAllowUAT"))) {
3344 secnotice("pinningQA", "could not enable test hierarchy: AppleServerAuthenticationAllowUAT not true");
3348 CFReleaseNull(setting
);
3353 @function SecPolicyCreateAppleServerAuthCommon
3354 @abstract Generic policy for server authentication Sub CAs
3356 Allows control for both if pinning is required at all and if UAT environments should be added
3357 to the trust policy.
3359 No pinning is for developer/QA that needs to use proxy to debug the protocol, while UAT
3360 environment is for QA/internal developer that have no need allow fake servers.
3362 Both the noPinning and allowUAT are gated on that you run on internal hardware.
3367 SecPolicyCreateAppleServerAuthCommon(CFStringRef hostname
,
3368 CFDictionaryRef __unused context
,
3369 CFStringRef policyOID
, CFStringRef service
,
3370 const DERItem
*leafMarkerOID
,
3371 const DERItem
*UATLeafMarkerOID
)
3373 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
3374 CFMutableDictionaryRef options
= NULL
;
3375 SecPolicyRef result
= NULL
;
3376 CFDataRef oid
= NULL
, uatoid
= NULL
;
3378 options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
3379 require(options
, errOut
);
3381 SecPolicyAddBasicX509Options(options
);
3383 require(hostname
, errOut
);
3384 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
3386 CFDictionaryAddValue(options
, kSecPolicyCheckBlackListedLeaf
, kCFBooleanTrue
);
3387 CFDictionaryAddValue(options
, kSecPolicyCheckGrayListedLeaf
, kCFBooleanTrue
);
3389 add_eku(options
, &oidExtendedKeyUsageServerAuth
);
3391 if (requireUATPinning(service
)) {
3392 bool allowUAT
= allowUATRoot(service
, context
);
3395 * Require pinning to the Apple CA's (and if UAT environment,
3396 * include the Apple Test CA's as anchors).
3398 appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
);
3399 require(appleAnchorOptions
, errOut
);
3401 if (allowUAT
|| allowTestHierarchyForPolicy(service
, true)) {
3402 /* Note: SecPolicyServer won't allow the test roots for non-internal devices */
3403 CFDictionarySetValue(appleAnchorOptions
,
3404 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
3407 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
3410 * Check if we also should allow the UAT variant of the leafs
3411 * as some variants of the UAT environment uses that instead
3412 * of the test Apple CA's.
3414 if (allowUAT
&& UATLeafMarkerOID
) {
3415 add_leaf_prod_qa_markers(options
, leafMarkerOID
, UATLeafMarkerOID
);
3417 add_leaf_marker(options
, leafMarkerOID
);
3420 /* new-style leaf marker OIDs */
3421 CFStringRef leafMarkerOIDStr
= NULL
, UATLeafMarkerOIDStr
= NULL
;
3422 leafMarkerOIDStr
= SecDERItemCopyOIDDecimalRepresentation(NULL
, leafMarkerOID
);
3423 if (UATLeafMarkerOID
) {
3424 UATLeafMarkerOIDStr
= SecDERItemCopyOIDDecimalRepresentation(NULL
, UATLeafMarkerOID
);
3427 if (allowUAT
&& leafMarkerOIDStr
&& UATLeafMarkerOIDStr
) {
3428 add_leaf_prod_qa_markers_value_string(options
,
3429 CFSTR("1.2.840.113635.100.6.48.1"), leafMarkerOIDStr
,
3430 CFSTR("1.2.840.113635.100.6.48.1"), UATLeafMarkerOIDStr
);
3431 } else if (leafMarkerOIDStr
) {
3432 add_leaf_marker_value_string(options
, CFSTR("1.2.840.113635.100.6.48.1"), leafMarkerOIDStr
);
3435 CFReleaseNull(leafMarkerOIDStr
);
3436 CFReleaseNull(UATLeafMarkerOIDStr
);
3438 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleServerAuthentication
);
3441 /* Check for weak hashes */
3442 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
3444 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
3446 result
= SecPolicyCreate(policyOID
, service
, options
);
3447 require(result
, errOut
);
3450 CFReleaseSafe(appleAnchorOptions
);
3451 CFReleaseSafe(options
);
3453 CFReleaseSafe(uatoid
);
3458 @function SecPolicyCreateAppleIDSService
3459 @abstract Ensure we're appropriately pinned to the IDS service (SSL + Apple restrictions)
3461 SecPolicyRef
SecPolicyCreateAppleIDSService(CFStringRef hostname
)
3463 SecPolicyRef result
= SecPolicyCreateSSL(true, hostname
);
3465 SecPolicySetOid(result
, kSecPolicyAppleIDSService
);
3466 SecPolicySetName(result
, kSecPolicyNameAppleIDSServiceContext
);
3472 @function SecPolicyCreateAppleIDSService
3473 @abstract Ensure we're appropriately pinned to the IDS service (SSL + Apple restrictions)
3475 SecPolicyRef
SecPolicyCreateAppleIDSServiceContext(CFStringRef hostname
, CFDictionaryRef context
)
3477 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleIDSServiceContext
,
3478 kSecPolicyNameAppleIDSServiceContext
,
3479 &oidAppleCertExtAppleServerAuthenticationIDSProd
,
3480 &oidAppleCertExtAppleServerAuthenticationIDSProdQA
);
3484 @function SecPolicyCreateAppleGSService
3485 @abstract Ensure we're appropriately pinned to the GS service
3487 SecPolicyRef
SecPolicyCreateAppleGSService(CFStringRef hostname
, CFDictionaryRef context
)
3489 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleGSService
,
3490 kSecPolicyNameAppleGSService
,
3491 &oidAppleCertExtAppleServerAuthenticationGS
,
3496 @function SecPolicyCreateApplePushService
3497 @abstract Ensure we're appropriately pinned to the Push service (SSL + Apple restrictions)
3499 SecPolicyRef
SecPolicyCreateApplePushService(CFStringRef hostname
, CFDictionaryRef context
)
3501 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyApplePushService
,
3502 kSecPolicyNameApplePushService
,
3503 &oidAppleCertExtAppleServerAuthenticationAPNProd
,
3504 &oidAppleCertExtAppleServerAuthenticationAPNProdQA
);
3508 @function SecPolicyCreateApplePPQService
3509 @abstract Ensure we're appropriately pinned to the PPQ service (SSL + Apple restrictions)
3511 SecPolicyRef
SecPolicyCreateApplePPQService(CFStringRef hostname
, CFDictionaryRef context
)
3513 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyApplePPQService
,
3514 kSecPolicyNameApplePPQService
,
3515 &oidAppleCertExtAppleServerAuthenticationPPQProd
,
3516 &oidAppleCertExtAppleServerAuthenticationPPQProdQA
);
3520 @function SecPolicyCreateAppleAST2Service
3521 @abstract Ensure we're appropriately pinned to the AST2 Diagnostic service (SSL + Apple restrictions)
3523 SecPolicyRef
SecPolicyCreateAppleAST2Service(CFStringRef hostname
, CFDictionaryRef context
)
3525 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleAST2DiagnosticsServerAuth
,
3526 kSecPolicyNameAppleAST2Service
,
3527 &oidAppleCertExtAST2DiagnosticsServerAuthProd
,
3528 &oidAppleCertExtAST2DiagnosticsServerAuthProdQA
);
3532 @function SecPolicyCreateAppleEscrowProxyService
3533 @abstract Ensure we're appropriately pinned to the iCloud Escrow Proxy service (SSL + Apple restrictions)
3535 SecPolicyRef
SecPolicyCreateAppleEscrowProxyService(CFStringRef hostname
, CFDictionaryRef context
)
3537 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleEscrowProxyServerAuth
,
3538 kSecPolicyNameAppleEscrowProxyService
,
3539 &oidAppleCertExtEscrowProxyServerAuthProd
,
3540 &oidAppleCertExtEscrowProxyServerAuthProdQA
);
3543 /* subject:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA */
3544 /* SKID: C0:7A:98:68:8D:89:FB:AB:05:64:0C:11:7D:AA:7D:65:B8:CA:CC:4E */
3545 /* Not Before: May 21 04:00:00 2002 GMT, Not After : May 21 04:00:00 2022 GMT */
3546 /* Signature Algorithm: sha1WithRSAEncryption */
3547 unsigned char GeoTrust_Global_CA_sha256
[kSecPolicySHA256Size
] = {
3548 0xff, 0x85, 0x6a, 0x2d, 0x25, 0x1d, 0xcd, 0x88, 0xd3, 0x66, 0x56, 0xf4, 0x50, 0x12, 0x67, 0x98,
3549 0xcf, 0xab, 0xaa, 0xde, 0x40, 0x79, 0x9c, 0x72, 0x2d, 0xe4, 0xd2, 0xb5, 0xdb, 0x36, 0xa7, 0x3a
3552 static SecPolicyRef
SecPolicyCreateAppleGeoTrustServerAuthCommon(CFStringRef hostname
, CFStringRef policyOid
,
3553 CFStringRef policyName
,
3554 CFStringRef leafMarkerOid
,
3555 CFStringRef qaLeafMarkerOid
) {
3556 CFMutableDictionaryRef options
= NULL
;
3557 CFDataRef spkiDigest
= NULL
;
3558 SecPolicyRef result
= NULL
;
3560 require(options
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
,
3561 &kCFTypeDictionaryValueCallBacks
), errOut
);
3564 SecPolicyAddBasicX509Options(options
);
3566 require(hostname
, errOut
);
3567 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
3569 add_eku(options
, &oidExtendedKeyUsageServerAuth
);
3572 if (requireUATPinning(policyName
)) {
3574 SecPolicyAddAnchorSHA256Options(options
, GeoTrust_Global_CA_sha256
);
3576 /* Issued to Apple Inc. in the US */
3577 add_element(options
, kSecPolicyCheckIntermediateCountry
, CFSTR("US"));
3578 add_element(options
, kSecPolicyCheckIntermediateOrganization
, CFSTR("Apple Inc."));
3580 require_action(SecPolicyAddChainLengthOptions(options
, 3), errOut
, CFReleaseNull(result
));
3582 /* Marker OIDs in both formats */
3583 if (qaLeafMarkerOid
&& allowUATRoot(policyName
, NULL
)) {
3584 add_leaf_prod_qa_markers_string(options
, leafMarkerOid
, qaLeafMarkerOid
);
3585 add_leaf_prod_qa_markers_value_string(options
,
3586 CFSTR("1.2.840.113635.100.6.48.1"), leafMarkerOid
,
3587 CFSTR("1.2.840.113635.100.6.48.1"), qaLeafMarkerOid
);
3589 add_leaf_marker_string(options
, leafMarkerOid
);
3590 add_leaf_marker_value_string(options
, CFSTR("1.2.840.113635.100.6.48.1"), leafMarkerOid
);
3594 /* Check for weak hashes */
3595 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
3597 /* See <rdar://25344801> for more details */
3599 result
= SecPolicyCreate(policyOid
, policyName
, options
);
3602 CFReleaseSafe(options
);
3603 CFReleaseSafe(spkiDigest
);
3607 SecPolicyRef
SecPolicyCreateAppleCompatibilityEscrowProxyService(CFStringRef hostname
) {
3608 return SecPolicyCreateAppleGeoTrustServerAuthCommon(hostname
, kSecPolicyAppleEscrowProxyCompatibilityServerAuth
,
3609 kSecPolicyNameAppleEscrowProxyService
,
3610 CFSTR("1.2.840.113635.100.6.27.7.2"),
3611 CFSTR("1.2.840.113635.100.6.27.7.1"));
3615 @function SecPolicyCreateAppleFMiPService
3616 @abstract Ensure we're appropriately pinned to the Find My iPhone service (SSL + Apple restrictions)
3618 SecPolicyRef
SecPolicyCreateAppleFMiPService(CFStringRef hostname
, CFDictionaryRef context
)
3620 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleFMiPServerAuth
,
3621 kSecPolicyNameAppleFMiPService
,
3622 &oidAppleCertExtFMiPServerAuthProd
,
3623 &oidAppleCertExtFMiPServerAuthProdQA
);
3627 /* should use verbatim copy, but since this is the deprecated way, don't care right now */
3628 static const UInt8 entrustSPKIL1C
[kSecPolicySHA256Size
] = {
3629 0x54, 0x5b, 0xf9, 0x35, 0xe9, 0xad, 0xa1, 0xda,
3630 0x11, 0x7e, 0xdc, 0x3c, 0x2a, 0xcb, 0xc5, 0x6f,
3631 0xc0, 0x28, 0x09, 0x6c, 0x0e, 0x24, 0xbe, 0x9b,
3632 0x38, 0x94, 0xbe, 0x52, 0x2d, 0x1b, 0x43, 0xde
3636 @function SecPolicyCreateApplePushServiceLegacy
3637 @abstract Ensure we're appropriately pinned to the Push service (via Entrust)
3639 SecPolicyRef
SecPolicyCreateApplePushServiceLegacy(CFStringRef hostname
)
3641 CFMutableDictionaryRef options
= NULL
;
3642 SecPolicyRef result
= NULL
;
3643 CFDataRef digest
= NULL
;
3645 digest
= CFDataCreateWithBytesNoCopy(kCFAllocatorDefault
, entrustSPKIL1C
, sizeof(entrustSPKIL1C
), kCFAllocatorNull
);
3646 require(digest
, errOut
);
3648 options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
3649 require(options
, errOut
);
3651 SecPolicyAddBasicX509Options(options
);
3653 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
3655 CFDictionaryAddValue(options
, kSecPolicyCheckBlackListedLeaf
, kCFBooleanTrue
);
3656 CFDictionaryAddValue(options
, kSecPolicyCheckGrayListedLeaf
, kCFBooleanTrue
);
3658 CFDictionaryAddValue(options
, kSecPolicyCheckIntermediateSPKISHA256
, digest
);
3660 add_eku(options
, &oidExtendedKeyUsageServerAuth
);
3662 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
3664 result
= SecPolicyCreate(kSecPolicyAppleLegacyPushService
,
3665 kSecPolicyNameAppleLegacyPushService
, options
);
3666 require(result
, errOut
);
3669 CFReleaseSafe(digest
);
3670 CFReleaseSafe(options
);
3675 @function SecPolicyCreateAppleMMCSService
3676 @abstract Ensure we're appropriately pinned to the IDS service (SSL + Apple restrictions)
3678 SecPolicyRef
SecPolicyCreateAppleMMCSService(CFStringRef hostname
, CFDictionaryRef context
)
3680 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleMMCSService
,
3681 kSecPolicyNameAppleMMCSService
,
3682 &oidAppleCertExtAppleServerAuthenticationMMCSProd
,
3683 &oidAppleCertExtAppleServerAuthenticationMMCSProdQA
);
3686 SecPolicyRef
SecPolicyCreateAppleCompatibilityMMCSService(CFStringRef hostname
) {
3687 return SecPolicyCreateAppleGeoTrustServerAuthCommon(hostname
, kSecPolicyAppleMMCSCompatibilityServerAuth
,
3688 kSecPolicyNameAppleMMCSService
,
3689 CFSTR("1.2.840.113635.100.6.27.11.2"),
3690 CFSTR("1.2.840.113635.100.6.27.11.1"));
3694 SecPolicyRef
SecPolicyCreateAppleiCloudSetupService(CFStringRef hostname
, CFDictionaryRef context
)
3696 return SecPolicyCreateAppleServerAuthCommon(hostname
, context
, kSecPolicyAppleiCloudSetupServerAuth
,
3697 kSecPolicyNameAppleiCloudSetupService
,
3698 &oidAppleCertExtAppleServerAuthenticationiCloudSetupProd
,
3699 &oidAppleCertExtAppleServerAuthenticationiCloudSetupProdQA
);
3702 SecPolicyRef
SecPolicyCreateAppleCompatibilityiCloudSetupService(CFStringRef hostname
)
3704 return SecPolicyCreateAppleGeoTrustServerAuthCommon(hostname
, kSecPolicyAppleiCloudSetupCompatibilityServerAuth
,
3705 kSecPolicyNameAppleiCloudSetupService
,
3706 CFSTR("1.2.840.113635.100.6.27.15.2"),
3707 CFSTR("1.2.840.113635.100.6.27.15.1"));
3711 @function SecPolicyCreateAppleSSLService
3712 @abstract Ensure we're appropriately pinned to an Apple server (SSL + Apple restrictions)
3714 SecPolicyRef
SecPolicyCreateAppleSSLService(CFStringRef hostname
)
3716 // SSL server, pinned to an Apple intermediate
3717 SecPolicyRef policy
= SecPolicyCreateSSL(true, hostname
);
3718 CFMutableDictionaryRef options
= NULL
;
3719 require(policy
, errOut
);
3721 // change options for SSL policy evaluation
3722 require((options
=(CFMutableDictionaryRef
)policy
->_options
) != NULL
, errOut
);
3724 // Apple CA anchored
3725 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleSSLService
), errOut
);
3727 // Check leaf for Apple Server Authentication marker oid (1.2.840.113635.100.6.27.1)
3728 add_leaf_marker(options
, &oidAppleCertExtAppleServerAuthentication
);
3730 // Check intermediate for Apple Server Authentication intermediate marker (1.2.840.113635.100.6.2.12)
3731 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleServerAuthentication
);
3733 /* Check for weak hashes */
3734 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
3736 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
3738 SecPolicySetOid(policy
, kSecPolicyAppleServerAuthentication
);
3739 SecPolicySetName(policy
, kSecPolicyNameAppleSSLService
);
3744 CFReleaseSafe(options
);
3745 CFReleaseSafe(policy
);
3750 @function SecPolicyCreateApplePPQSigning
3751 @abstract Check for intermediate certificate 'Apple System Integration 2 Certification Authority' by name,
3753 Leaf cert must have Digital Signature usage.
3754 Leaf cert must have Apple PPQ Signing marker OID (1.2.840.113635.100.6.38.2).
3755 Intermediate must have marker OID (1.2.840.113635.100.6.2.10).
3757 SecPolicyRef
SecPolicyCreateApplePPQSigning(void)
3759 SecPolicyRef result
= NULL
;
3760 CFMutableDictionaryRef options
= NULL
;
3761 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3762 &kCFTypeDictionaryKeyCallBacks
,
3763 &kCFTypeDictionaryValueCallBacks
), errOut
);
3764 SecPolicyAddBasicCertOptions(options
);
3766 SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameApplePPQSigning
);
3767 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3769 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
3770 CFSTR("Apple System Integration 2 Certification Authority"));
3772 // Check that leaf has extension with "Apple PPQ Signing" prod oid (1.2.840.113635.100.6.38.2)
3773 add_leaf_marker(options
, &oidAppleCertExtApplePPQSigningProd
);
3775 // Check that intermediate has extension (1.2.840.113635.100.6.2.10)
3776 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleSystemIntg2
);
3778 add_ku(options
, kSecKeyUsageDigitalSignature
);
3780 require(result
= SecPolicyCreate(kSecPolicyApplePPQSigning
,
3781 kSecPolicyNameApplePPQSigning
, options
), errOut
);
3784 CFReleaseSafe(options
);
3789 @function SecPolicyCreateTestApplePPQSigning
3790 @abstract Check for intermediate certificate 'Apple System Integration 2 Certification Authority' by name,
3792 Leaf cert must have Digital Signature usage.
3793 Leaf cert must have Apple PPQ Signing Test marker OID (1.2.840.113635.100.6.38.1).
3794 Intermediate must have marker OID (1.2.840.113635.100.6.2.10).
3796 SecPolicyRef
SecPolicyCreateTestApplePPQSigning(void)
3798 /* Guard against use of test policy on production devices */
3799 if (!SecIsInternalRelease()) {
3800 return SecPolicyCreateApplePPQSigning();
3803 SecPolicyRef result
= NULL
;
3804 CFMutableDictionaryRef options
= NULL
;
3805 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3806 &kCFTypeDictionaryKeyCallBacks
,
3807 &kCFTypeDictionaryValueCallBacks
), errOut
);
3808 SecPolicyAddBasicCertOptions(options
);
3810 SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleTestPPQSigning
);
3811 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3813 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
3814 CFSTR("Apple System Integration 2 Certification Authority"));
3816 // Check that leaf has extension with "Apple PPQ Signing" test oid (1.2.840.113635.100.6.38.1)
3817 add_leaf_marker(options
, &oidAppleCertExtApplePPQSigningProdQA
);
3819 // Check that intermediate has extension (1.2.840.113635.100.6.2.10)
3820 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleSystemIntg2
);
3822 add_ku(options
, kSecKeyUsageDigitalSignature
);
3824 require(result
= SecPolicyCreate(kSecPolicyAppleTestPPQSigning
,
3825 kSecPolicyNameAppleTestPPQSigning
, options
), errOut
);
3828 CFReleaseSafe(options
);
3832 @function SecPolicyCreateAppleTimeStamping
3833 @abstract Check for RFC3161 timestamping EKU.
3835 SecPolicyRef
SecPolicyCreateAppleTimeStamping(void)
3837 SecPolicyRef result
= NULL
;
3838 CFMutableDictionaryRef options
= NULL
;
3839 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3840 &kCFTypeDictionaryKeyCallBacks
,
3841 &kCFTypeDictionaryValueCallBacks
), errOut
);
3843 SecPolicyAddBasicX509Options(options
);
3845 /* Require id-kp-timeStamping extendedKeyUsage to be present. */
3846 add_eku(options
, &oidExtendedKeyUsageTimeStamping
);
3848 require(result
= SecPolicyCreate(kSecPolicyAppleTimeStamping
,
3849 kSecPolicyNameAppleTimeStamping
, options
), errOut
);
3852 CFReleaseSafe(options
);
3857 @function SecPolicyCreateApplePayIssuerEncryption
3858 @abstract Check for intermediate certificate 'Apple Worldwide Developer Relations CA - G2' by name,
3859 and ECC apple anchor.
3860 Leaf cert must have Key Encipherment and Key Agreement usage.
3861 Leaf cert must have Apple Pay Issuer Encryption marker OID (1.2.840.113635.100.6.39).
3863 SecPolicyRef
SecPolicyCreateApplePayIssuerEncryption(void)
3865 SecPolicyRef result
= NULL
;
3866 CFMutableDictionaryRef options
= NULL
;
3867 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3868 &kCFTypeDictionaryKeyCallBacks
,
3869 &kCFTypeDictionaryValueCallBacks
), errOut
);
3870 SecPolicyAddBasicCertOptions(options
);
3872 require(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameApplePayIssuerEncryption
),
3874 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3876 CFDictionaryAddValue(options
, kSecPolicyCheckIssuerCommonName
,
3877 CFSTR("Apple Worldwide Developer Relations CA - G2"));
3879 // Check that leaf has extension with "Apple Pay Issuer Encryption" oid (1.2.840.113635.100.6.39)
3880 add_leaf_marker(options
, &oidAppleCertExtCryptoServicesExtEncryption
);
3882 add_ku(options
, kSecKeyUsageKeyEncipherment
);
3884 require(result
= SecPolicyCreate(kSecPolicyApplePayIssuerEncryption
,
3885 kSecPolicyNameApplePayIssuerEncryption
, options
), errOut
);
3888 CFReleaseSafe(options
);
3893 @function SecPolicyCreateAppleATVVPNProfileSigning
3894 @abstract Check for leaf marker OID 1.2.840.113635.100.6.43,
3895 intermediate marker OID 1.2.840.113635.100.6.2.10,
3896 chains to Apple Root CA, path length 3
3898 SecPolicyRef
SecPolicyCreateAppleATVVPNProfileSigning(void)
3900 SecPolicyRef result
= NULL
;
3901 CFMutableDictionaryRef options
= NULL
;
3902 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
3903 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3904 &kCFTypeDictionaryKeyCallBacks
,
3905 &kCFTypeDictionaryValueCallBacks
), errOut
);
3907 SecPolicyAddBasicCertOptions(options
);
3909 // Require pinning to the Apple CAs (including test CA for internal releases)
3910 appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
);
3911 require(appleAnchorOptions
, errOut
);
3913 if (SecIsInternalRelease()) {
3914 CFDictionarySetValue(appleAnchorOptions
,
3915 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
3918 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
3920 // Cert chain length 3
3921 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3923 // Check leaf for Apple ATV VPN Profile Signing OID (1.2.840.113635.100.6.43)
3924 add_leaf_marker(options
, &oidAppleCertExtATVVPNProfileSigning
);
3926 // Check intermediate for Apple System Integration 2 CA intermediate marker (1.2.840.113635.100.6.2.10)
3927 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleSystemIntg2
);
3929 // Ensure that revocation is checked (OCSP only)
3930 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationOCSP
);
3932 require(result
= SecPolicyCreate(kSecPolicyAppleATVVPNProfileSigning
,
3933 kSecPolicyNameAppleATVVPNProfileSigning
, options
), errOut
);
3936 CFReleaseSafe(options
);
3937 CFReleaseSafe(appleAnchorOptions
);
3941 SecPolicyRef
SecPolicyCreateAppleHomeKitServerAuth(CFStringRef hostname
) {
3942 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
3943 CFMutableDictionaryRef options
= NULL
;
3944 SecPolicyRef result
= NULL
;
3945 CFDataRef oid
= NULL
;
3947 options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
3948 require(options
, errOut
);
3950 SecPolicyAddBasicX509Options(options
);
3952 CFDictionaryAddValue(options
, kSecPolicyCheckSSLHostname
, hostname
);
3954 add_eku(options
, &oidExtendedKeyUsageServerAuth
);
3956 if (requireUATPinning(kSecPolicyNameAppleHomeKitServerAuth
)) {
3957 bool allowUAT
= allowUATRoot(kSecPolicyNameAppleHomeKitServerAuth
, NULL
);
3959 // Cert chain length 3
3960 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
3962 // Apple anchors, allowing test anchors for internal releases properly configured
3963 appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
);
3964 require(appleAnchorOptions
, errOut
);
3965 if (allowUAT
|| allowTestHierarchyForPolicy(kSecPolicyNameAppleHomeKitServerAuth
, true)) {
3966 CFDictionarySetValue(appleAnchorOptions
,
3967 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
3969 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
3971 add_leaf_marker(options
, &oidAppleCertExtHomeKitServerAuth
);
3973 add_oid(options
, kSecPolicyCheckIntermediateMarkerOid
, &oidAppleIntmMarkerAppleHomeKitServerCA
);
3976 /* Check for weak hashes */
3977 CFDictionaryAddValue(options
, kSecPolicyCheckSystemTrustedWeakHash
, kCFBooleanTrue
);
3979 CFDictionaryAddValue(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
3981 result
= SecPolicyCreate(kSecPolicyAppleHomeKitServerAuth
,
3982 kSecPolicyNameAppleHomeKitServerAuth
, options
);
3983 require(result
, errOut
);
3986 CFReleaseSafe(appleAnchorOptions
);
3987 CFReleaseSafe(options
);
3992 SecPolicyRef
SecPolicyCreateAppleExternalDeveloper(void) {
3993 CFMutableDictionaryRef options
= NULL
;
3994 SecPolicyRef result
= NULL
;
3996 /* Create basic Apple pinned policy */
3997 require(result
= SecPolicyCreateApplePinned(kSecPolicyNameAppleExternalDeveloper
,
3998 CFSTR("1.2.840.113635.100.6.2.1"), // WWDR Intermediate OID
3999 CFSTR("1.2.840.113635.100.6.1.2")), // "iPhone Developer" leaf OID
4002 require_action(options
= CFDictionaryCreateMutableCopy(NULL
, 0, result
->_options
), errOut
, CFReleaseNull(result
));
4004 /* Additional intermediate OIDs */
4005 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
,
4006 CFSTR("1.2.840.113635.100.6.2.6")); // "Developer ID" Intermediate OID
4008 /* Addtional leaf OIDS */
4009 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.4")); // "iPhone Distribution" leaf OID
4010 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.5")); // "Safari Developer" leaf OID
4011 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.7")); // "3rd Party Mac Developer Application" leaf OID
4012 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.8")); // "3rd Party Mac Developer Installer" leaf OID
4013 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.12")); // "Mac Developer" leaf OID
4014 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.13")); // "Developer ID Application" leaf OID
4015 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.1.14")); // "Developer ID Installer" leaf OID
4018 add_eku_string(options
, CFSTR("1.3.6.1.5.5.7.3.3")); // CodeSigning EKU
4019 add_eku_string(options
, CFSTR("1.2.840.113635.100.4.8")); // "Safari Developer" EKU
4020 add_eku_string(options
, CFSTR("1.2.840.113635.100.4.9")); // "3rd Party Mac Developer Installer" EKU
4021 add_eku_string(options
, CFSTR("1.2.840.113635.100.4.13")); // "Developer ID Installer" EKU
4023 CFReleaseSafe(result
->_options
);
4024 result
->_options
= CFRetainSafe(options
);
4026 SecPolicySetOid(result
, kSecPolicyAppleExternalDeveloper
);
4029 CFReleaseSafe(options
);
4033 /* This one is special because the intermediate has no marker OID */
4034 SecPolicyRef
SecPolicyCreateAppleSoftwareSigning(void) {
4035 CFMutableDictionaryRef options
= NULL
;
4036 CFDictionaryRef keySizes
= NULL
;
4037 CFNumberRef rsaSize
= NULL
, ecSize
= NULL
;
4038 SecPolicyRef result
= NULL
;
4040 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
4041 &kCFTypeDictionaryKeyCallBacks
,
4042 &kCFTypeDictionaryValueCallBacks
), errOut
);
4044 SecPolicyAddBasicX509Options(options
);
4046 /* Anchored to the Apple Roots */
4047 require_quiet(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleSoftwareSigning
),
4050 /* Exactly 3 certs in the chain */
4051 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
4053 /* Intermediate Common Name matches */
4054 add_element(options
, kSecPolicyCheckIssuerCommonName
, CFSTR("Apple Code Signing Certification Authority"));
4056 /* Leaf marker OID matches */
4057 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.22"));
4059 /* Leaf has CodeSigning EKU */
4060 add_eku_string(options
, CFSTR("1.3.6.1.5.5.7.3.3"));
4062 /* Check revocation using any available method */
4063 add_element(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
4065 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
4066 require(SecPolicyAddStrongKeySizeOptions(options
), errOut
);
4068 require(result
= SecPolicyCreate(kSecPolicyAppleSoftwareSigning
,
4069 kSecPolicyNameAppleSoftwareSigning
, options
), errOut
);
4072 CFReleaseSafe(options
);
4073 CFReleaseSafe(keySizes
);
4074 CFReleaseSafe(rsaSize
);
4075 CFReleaseSafe(ecSize
);
4079 /* subject:/CN=SEP Root CA/O=Apple Inc./ST=California */
4080 /* SKID: 58:EF:D6:BE:C5:82:B0:54:CD:18:A6:84:AD:A2:F6:7B:7B:3A:7F:CF */
4081 /* Not Before: Jun 24 21:43:24 2014 GMT, Not After : Jun 24 21:43:24 2029 GMT */
4082 /* Signature Algorithm: ecdsa-with-SHA384 */
4083 const uint8_t SEPRootCA_SHA256
[kSecPolicySHA256Size
] = {
4084 0xd1, 0xdf, 0x82, 0x00, 0xf3, 0x89, 0x4e, 0xe9, 0x96, 0xf3, 0x77, 0xdf, 0x76, 0x3b, 0x0a, 0x16,
4085 0x8f, 0xd9, 0x6c, 0x58, 0xc0, 0x3e, 0xc9, 0xb0, 0x5f, 0xa5, 0x64, 0x79, 0xc0, 0xe8, 0xc9, 0xe7
4088 SecPolicyRef
SecPolicyCreateAppleUniqueDeviceCertificate(CFDataRef testRootHash
) {
4089 CFMutableDictionaryRef options
= NULL
;
4090 CFDictionaryRef keySizes
= NULL
;
4091 CFNumberRef ecSize
= NULL
;
4092 SecPolicyRef result
= NULL
;
4094 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
4095 &kCFTypeDictionaryKeyCallBacks
,
4096 &kCFTypeDictionaryValueCallBacks
), errOut
);
4098 /* Device certificate should never expire */
4099 SecPolicyAddBasicCertOptions(options
);
4101 /* Anchored to the SEP Root CA. Allow alternative root for developers */
4102 require(SecPolicyAddAnchorSHA256Options(options
, SEPRootCA_SHA256
),errOut
);
4103 if (testRootHash
&& SecIsInternalRelease() &&
4104 allowTestHierarchyForPolicy(kSecPolicyNameAppleUniqueDeviceCertificate
, false)
4105 && (kSecPolicySHA256Size
== CFDataGetLength(testRootHash
))) {
4106 add_element(options
, kSecPolicyCheckAnchorSHA256
, testRootHash
);
4109 /* Exactly 3 certs in the chain */
4110 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
4112 /* Intermediate has marker OID with value */
4113 add_intermediate_marker_value_string(options
, CFSTR("1.2.840.113635.100.6.44"), CFSTR("ucrt"));
4115 /* Leaf has marker OID with varying value that can't be pre-determined */
4116 add_element(options
, kSecPolicyCheckLeafMarkerOidWithoutValueCheck
, CFSTR("1.2.840.113635.100.10.1"));
4118 /* RSA key sizes are disallowed. EC key sizes are P-256 or larger. */
4119 require(ecSize
= CFNumberCreateWithCFIndex(NULL
, 256), errOut
);
4120 require(keySizes
= CFDictionaryCreate(NULL
, (const void**)&kSecAttrKeyTypeEC
,
4121 (const void**)&ecSize
, 1,
4122 &kCFTypeDictionaryKeyCallBacks
,
4123 &kCFTypeDictionaryValueCallBacks
), errOut
);
4124 add_element(options
, kSecPolicyCheckKeySize
, keySizes
);
4127 require(result
= SecPolicyCreate(kSecPolicyAppleUniqueDeviceIdentifierCertificate
,
4128 kSecPolicyNameAppleUniqueDeviceCertificate
, options
), errOut
);
4131 CFReleaseSafe(options
);
4132 CFReleaseSafe(keySizes
);
4133 CFReleaseSafe(ecSize
);
4137 SecPolicyRef
SecPolicyCreateAppleWarsaw(void) {
4138 CFMutableDictionaryRef options
= NULL
;
4139 CFDictionaryRef keySizes
= NULL
;
4140 CFNumberRef rsaSize
= NULL
, ecSize
= NULL
;
4141 SecPolicyRef result
= NULL
;
4142 #if TARGET_OS_BRIDGE
4143 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
4146 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
4147 &kCFTypeDictionaryKeyCallBacks
,
4148 &kCFTypeDictionaryValueCallBacks
), errOut
);
4150 SecPolicyAddBasicX509Options(options
);
4152 /* Anchored to the Apple Roots. */
4153 #if TARGET_OS_BRIDGE
4154 /* On the bridge, test roots are gated in the trust and policy servers. */
4155 require_quiet(appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
), errOut
);
4156 CFDictionarySetValue(appleAnchorOptions
,
4157 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
4158 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
4159 CFReleaseSafe(appleAnchorOptions
);
4161 require_quiet(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleWarsaw
),
4165 /* Exactly 3 certs in the chain */
4166 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
4168 /* Intermediate marker OID matches input OID */
4169 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.14"));
4171 /* Leaf marker OID matches input OID */
4172 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.29"));
4174 /* Check revocation using any available method */
4175 add_element(options
, kSecPolicyCheckRevocation
, kSecPolicyCheckRevocationAny
);
4177 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
4178 require(SecPolicyAddStrongKeySizeOptions(options
), errOut
);
4180 require(result
= SecPolicyCreate(kSecPolicyAppleWarsaw
,
4181 kSecPolicyNameAppleWarsaw
, options
), errOut
);
4184 CFReleaseSafe(options
);
4185 CFReleaseSafe(keySizes
);
4186 CFReleaseSafe(rsaSize
);
4187 CFReleaseSafe(ecSize
);
4191 SecPolicyRef
SecPolicyCreateAppleSecureIOStaticAsset(void) {
4192 CFMutableDictionaryRef options
= NULL
;
4193 CFDictionaryRef keySizes
= NULL
;
4194 CFNumberRef rsaSize
= NULL
, ecSize
= NULL
;
4195 SecPolicyRef result
= NULL
;
4196 #if TARGET_OS_BRIDGE
4197 CFMutableDictionaryRef appleAnchorOptions
= NULL
;
4200 require(options
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
4201 &kCFTypeDictionaryKeyCallBacks
,
4202 &kCFTypeDictionaryValueCallBacks
), errOut
);
4204 /* This certificate cannot expire so that assets always load */
4205 SecPolicyAddBasicCertOptions(options
);
4207 /* Anchored to the Apple Roots. */
4208 #if TARGET_OS_BRIDGE
4209 /* On the bridge, test roots are gated in the trust and policy servers. */
4210 require_quiet(appleAnchorOptions
= CFDictionaryCreateMutableForCFTypes(NULL
), errOut
);
4211 CFDictionarySetValue(appleAnchorOptions
,
4212 kSecPolicyAppleAnchorIncludeTestRoots
, kCFBooleanTrue
);
4213 add_element(options
, kSecPolicyCheckAnchorApple
, appleAnchorOptions
);
4214 CFReleaseSafe(appleAnchorOptions
);
4216 require_quiet(SecPolicyAddAppleAnchorOptions(options
, kSecPolicyNameAppleSecureIOStaticAsset
),
4220 /* Exactly 3 certs in the chain */
4221 require(SecPolicyAddChainLengthOptions(options
, 3), errOut
);
4223 /* Intermediate marker OID matches input OID */
4224 add_element(options
, kSecPolicyCheckIntermediateMarkerOid
, CFSTR("1.2.840.113635.100.6.2.10"));
4226 /* Leaf marker OID matches input OID */
4227 add_leaf_marker_string(options
, CFSTR("1.2.840.113635.100.6.50"));
4229 /* RSA key sizes are 2048-bit or larger. EC key sizes are P-256 or larger. */
4230 require(SecPolicyAddStrongKeySizeOptions(options
), errOut
);
4232 require(result
= SecPolicyCreate(kSecPolicyAppleSecureIOStaticAsset
,
4233 kSecPolicyNameAppleSecureIOStaticAsset
, options
), errOut
);
4236 CFReleaseSafe(options
);
4237 CFReleaseSafe(keySizes
);
4238 CFReleaseSafe(rsaSize
);
4239 CFReleaseSafe(ecSize
);