2 * Copyright (c) 2017 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 * SecCertificateServer.h - SecCertificate and SecCertificatePath types
26 * with additonal validation context.
30 #ifndef _SECURITY_SECCERTIFICATESERVER_H_
31 #define _SECURITY_SECCERTIFICATESERVER_H_
33 #include <CoreFoundation/CoreFoundation.h>
35 #include <Security/SecCertificate.h>
37 #include <securityd/policytree.h>
40 typedef struct SecCertificateVC
*SecCertificateVCRef
;
42 SecCertificateVCRef
SecCertificateVCCreate(SecCertificateRef certificate
, CFArrayRef usageContraints
);
44 typedef struct SecCertificatePathVC
*SecCertificatePathVCRef
;
46 /* Create a new certificate path from an old one. */
47 SecCertificatePathVCRef
SecCertificatePathVCCreate(SecCertificatePathVCRef path
,
48 SecCertificateRef certificate
, CFArrayRef usageConstraints
);
50 SecCertificatePathVCRef
SecCertificatePathVCCopyAddingLeaf(SecCertificatePathVCRef path
,
51 SecCertificateRef leaf
);
53 /* Return a new certificate path without the first skipCount certificates. */
54 SecCertificatePathVCRef
SecCertificatePathVCCopyFromParent(SecCertificatePathVCRef path
, CFIndex skipCount
);
56 /* Create an array of SecCertificateRefs from a certificate path. */
57 CFArrayRef
SecCertificatePathVCCopyCertificates(SecCertificatePathVCRef path
);
59 /* Create an array of CFDataRefs from a certificate path. */
60 CFArrayRef
SecCertificatePathVCCreateSerialized(SecCertificatePathVCRef path
);
62 /* Record the fact that we found our own root cert as our parent
64 void SecCertificatePathVCSetSelfIssued(SecCertificatePathVCRef certificatePath
);
65 bool SecCertificatePathVCIsCertificateAtIndexSelfIssued(SecCertificatePathVCRef path
, CFIndex ix
);
67 void SecCertificatePathVCSetIsAnchored(SecCertificatePathVCRef certificatePath
);
69 /* Return the index of the first non anchor certificate in the chain that is
70 self signed counting from the leaf up. Return -1 if there is none. */
71 CFIndex
SecCertificatePathVCSelfSignedIndex(SecCertificatePathVCRef certificatePath
);
73 Boolean
SecCertificatePathVCIsAnchored(SecCertificatePathVCRef certificatePath
);
75 void SecCertificatePathVCSetNextSourceIndex(SecCertificatePathVCRef certificatePath
, CFIndex sourceIndex
);
77 CFIndex
SecCertificatePathVCGetNextSourceIndex(SecCertificatePathVCRef certificatePath
);
79 CFIndex
SecCertificatePathVCGetCount(SecCertificatePathVCRef certificatePath
);
81 SecCertificateRef
SecCertificatePathVCGetCertificateAtIndex(SecCertificatePathVCRef certificatePath
, CFIndex ix
);
83 void SecCertificatePathVCForEachCertificate(SecCertificatePathVCRef path
, void(^operation
)(SecCertificateRef certificate
, bool *stop
));
85 /* Return the index of certificate in path or kCFNotFound if certificate is
87 CFIndex
SecCertificatePathVCGetIndexOfCertificate(SecCertificatePathVCRef path
,
88 SecCertificateRef certificate
);
90 /* Return the root certificate for certificatePath. Note that root is just
91 the top of the path as far as it is constructed. It may or may not be
92 trusted or self signed. */
93 SecCertificateRef
SecCertificatePathVCGetRoot(SecCertificatePathVCRef certificatePath
);
95 CFArrayRef
SecCertificatePathVCGetUsageConstraintsAtIndex(SecCertificatePathVCRef certificatePath
, CFIndex ix
);
97 void SecCertificatePathVCSetUsageConstraintsAtIndex(SecCertificatePathVCRef certificatePath
,
98 CFArrayRef newConstraints
, CFIndex ix
);
100 SecKeyRef
SecCertificatePathVCCopyPublicKeyAtIndex(SecCertificatePathVCRef certificatePath
, CFIndex ix
);
102 typedef CFIndex SecPathVerifyStatus
;
104 kSecPathVerifiesUnknown
= -1,
105 kSecPathVerifySuccess
= 0,
106 kSecPathVerifyFailed
= 1
109 SecPathVerifyStatus
SecCertificatePathVCVerify(SecCertificatePathVCRef certificatePath
);
111 bool SecCertificatePathVCIsCycleInGraph(SecCertificatePathVCRef path
);
113 bool SecCertificatePathVCIsValid(SecCertificatePathVCRef certificatePath
, CFAbsoluteTime verifyTime
);
115 bool SecCertificatePathVCHasWeakHash(SecCertificatePathVCRef certificatePath
);
117 bool SecCertificatePathVCHasWeakKeySize(SecCertificatePathVCRef certificatePath
);
120 CFIndex
SecCertificatePathVCScore(SecCertificatePathVCRef certificatePath
,
121 CFAbsoluteTime verifyTime
);
122 CFIndex
SecCertificatePathVCGetScore(SecCertificatePathVCRef certificatePath
);
123 void SecCertificatePathVCSetScore(SecCertificatePathVCRef certificatePath
, CFIndex score
); // only sets score if new score is higher
124 void SecCertificatePathVCResetScore(SecCertificatePathVCRef certificatePath
); // reset score to 0
127 void SecCertificatePathVCDeleteRVCs(SecCertificatePathVCRef path
);
128 bool SecCertificatePathVCIsRevocationDone(SecCertificatePathVCRef certificatePath
);
129 void SecCertificatePathVCAllocateRVCs(SecCertificatePathVCRef certificatePath
, CFIndex certCount
);
130 CFAbsoluteTime
SecCertificatePathVCGetEarliestNextUpdate(SecCertificatePathVCRef path
);
131 void *SecCertificatePathVCGetRVCAtIndex(SecCertificatePathVCRef certificatePath
, CFIndex ix
); // Returns a SecRVCRef
132 bool SecCertificatePathVCIsRevocationRequiredForCertificateAtIndex(SecCertificatePathVCRef certificatePath
,
134 void SecCertificatePathVCSetRevocationRequiredForCertificateAtIndex(SecCertificatePathVCRef certificatePath
,
137 bool SecCertificatePathVCCheckedIssuers(SecCertificatePathVCRef certificatePath
);
138 void SecCertificatePathVCSetCheckedIssuers(SecCertificatePathVCRef certificatePath
, bool checked
);
139 CFIndex
SecCertificatePathVCUnknownCAIndex(SecCertificatePathVCRef certificatePath
);
140 void SecCertificatePathVCSetUnknownCAIndex(SecCertificatePathVCRef certificatePath
, CFIndex index
);
142 /* Did we already validate this path (setting EV, CT, RVC, etc.) */
143 bool SecCertificatePathVCIsPathValidated(SecCertificatePathVCRef certificatePath
);
144 void SecCertificatePathVCSetPathValidated(SecCertificatePathVCRef certificatePath
);
147 bool SecCertificatePathVCIsEV(SecCertificatePathVCRef certificatePath
);
148 void SecCertificatePathVCSetIsEV(SecCertificatePathVCRef certificatePath
, bool isEV
);
149 bool SecCertificatePathVCIsOptionallyEV(SecCertificatePathVCRef certificatePath
);
152 typedef CFIndex SecPathCTPolicy
;
154 kSecPathCTNotRequired
= 0,
155 kSecPathCTRequiredOverridable
= 1,
156 kSecPathCTRequired
= 2
158 bool SecCertificatePathVCIsCT(SecCertificatePathVCRef certificatePath
);
159 void SecCertificatePathVCSetIsCT(SecCertificatePathVCRef certificatePath
, bool isCT
);
160 SecPathCTPolicy
SecCertificatePathVCRequiresCT(SecCertificatePathVCRef certificatePath
);
161 void SecCertificatePathVCSetRequiresCT(SecCertificatePathVCRef certificatePath
, SecPathCTPolicy requiresCT
);
162 CFAbsoluteTime
SecCertificatePathVCIssuanceTime(SecCertificatePathVCRef certificatePath
);
163 void SecCertificatePathVCSetIssuanceTime(SecCertificatePathVCRef certificatePath
, CFAbsoluteTime issuanceTime
);
166 bool SecCertificatePathVCIsAllowlisted(SecCertificatePathVCRef certificatePath
);
167 void SecCertificatePathVCSetIsAllowlisted(SecCertificatePathVCRef certificatePath
, bool isAllowlisted
);
170 bool SecCertificatePathVCVerifyPolicyTree(SecCertificatePathVCRef path
, bool anchor_trusted
);
172 #endif /* _SECURITY_SECCERTIFICATESERVER_H_ */