]> git.saurik.com Git - apple/security.git/blob - sec/securityd/SecOCSPCache.h
Security-55163.44.tar.gz
[apple/security.git] / sec / securityd / SecOCSPCache.h
1 /*
2 * Copyright (c) 2009-2010 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * Created by Michael Brouwer on 1/15/09.
24 */
25
26 /*!
27 @header SecOCSPCache
28 The functions provided in SecOCSPCache.h provide an interface to
29 an OCSP caching module.
30 */
31
32 #ifndef _SECURITY_SECOCSPCACHE_H_
33 #define _SECURITY_SECOCSPCACHE_H_
34
35 #include <securityd/SecOCSPRequest.h>
36 #include <securityd/SecOCSPResponse.h>
37 #include <CoreFoundation/CFURL.h>
38
39 #if defined(__cplusplus)
40 extern "C" {
41 #endif
42
43
44 void SecOCSPCacheAddResponse(SecOCSPResponseRef response,
45 CFURLRef localResponderURI);
46
47 SecOCSPResponseRef SecOCSPCacheCopyMatching(SecOCSPRequestRef request,
48 CFURLRef localResponderURI /* may be NULL */);
49
50 /* This should be called on a normal non emergency exit. */
51 void SecOCSPCacheGC(void);
52
53 /* Call this periodically or perhaps when we are exiting due to low memory. */
54 void SecOCSPCacheFlush(void);
55
56 #if defined(__cplusplus)
57 }
58 #endif
59
60 #endif /* _SECURITY_SECOCSPCACHE_H_ */
61
62 #if 0
63 /*
64 Experation policy assumptions:
65 - We never check revocation status of anchors, whether they be system anchors,
66 passed in anchors or anchors hardcoded in a policy.
67 - Revocation information is cached for positive reponses for a limited time.
68 - Revocation information can be cached for negative reponses for an unlimited time.
69 - Revocation information need never be kept around after the certificate has expired (unless we still check after the cert has expired like we were talking about for EERI).
70 - Revocation information records that are used and still valid should be kept longer.
71 - We can set an upper limit in number of records (or certificates) in the cache.
72 - We can set an upper limit on total space consumed by the cache.
73 Questions:
74 - Remember bad server responses too? some ocsp responders required signed requests which we don't support, so we could consider caching the 6 (Not Authorized or something) response.
75
76 Data needed per type of revocation record to implement this policy.
77
78 Caching policy:
79 - Deleting cache should not be user option.
80 - Cache should surrvive backups.
81 - Negative caching as long as possible.
82
83 CRL certificate stati:
84 unspecified, keyCompromise, cACompromise,
85 affiliationChanged, superseded, cessationOfOperation,
86 certificateHold, removeFromCRL, privilegeWithdrawn,
87 aACompromise, the special value UNREVOKED, or the special
88 value UNDETERMINED. This variable is initialized to the
89 special value UNREVOKED.
90
91 CRL Timestamp values:
92 - thisUpdate
93 - nextUpdate (optional but not really 5280 says CAs must provide it even though ASN.1 is optional)
94 (no producedAt in CRLs, that's what thisUpdate is by definition it seems).
95
96
97 OCSP Timestamp values:
98 thisUpdate = May 1, 2005 01:00:00 GMT
99 nextUpdate = May 3, 2005 01:00:00 GMT (optional abscence means update available any time)
100 productedAt = May 1, 2005 01:00:00 GMT
101
102 PER CERTIFICATE RETURN in INFO
103
104 Revocation object used: OCSP Response, mapping from
105 reasons-> (CRL + most current delta CRL), Error Object (with status code).
106 -- good
107 -- revoked
108 -- unknown
109
110 other exceptions (unsigned responses):
111 -- malformedRequest
112 -- internalError
113 -- tryLater
114 -- sigRequired
115 -- unauthorized (5019 The response "unauthorized" is returned in cases where the client
116 is not authorized to make this query to this server or the server
117 is not capable of responding authoritatively. (Expired certs might get this answer too))
118
119
120 CRL signer chain rules:
121 1) Must use same anchor as cert itself.
122 This implies that we can only cache the validity of a leaf or intermediate certificate for CRL checking based on the mapping:
123 (certificate, path anchor, use_deltas) -> Revocation_status (unspecified, keyCompromise, cACompromise,
124 affiliationChanged, superseded, cessationOfOperation,certificateHold, removeFromCRL, privilegeWithdrawn,aACompromise, UNREVOKED, UNDETERMINED).
125
126 OCSP signer chain rules:
127 (Wikipedia confirmed in rfc): The key that signs a response need not be the same key that signed the certificate. The certificate's issuer may delegate another authority to be the OCSP responder. In this case, the responder's certificate (the one that is used to sign the response) must be issued by the issuer of the certificate in question, and must include a certain extension that marks it as an OCSP signing authority (more precisely, an extended key usage extension with the OID {iso(1) identified-organization(3) dod(6) internet(1) security(5) mechanisms(5) pkix(7) keyPurpose(3) ocspSigning(9)})
128
129 rfc text of the wikipedia: Therefore, a certificate's issuer MUST either sign the OCSP
130 responses itself or it MUST explicitly designate this authority to
131 another entity. OCSP signing delegation SHALL be designated by the
132 inclusion of id-kp-OCSPSigning in an extendedKeyUsage certificate
133 extension included in the OCSP response signer's certificate. This
134 certificate MUST be issued directly by the CA that issued the
135 certificate in question.
136
137 rfc: If ocsp signing cert has id-pkix-ocsp-nocheck extension we don't check it's revocation status.
138
139 (certificate, direct issuer certificate) -> Revocation_status good (UNREVOKED) revoked revocationTime, CRLReason (unspecified, keyCompromise, cACompromise,affiliationChanged, superseded, cessationOfOperation,certificateHold, removeFromCRL, privilegeWithdrawn,aACompromise) unknown (UNDETERMINED).
140
141 ocsp CertID ::= SEQUENCE {
142 hashAlgorithm AlgorithmIdentifier,
143 issuerNameHash OCTET STRING, -- Hash of Issuer's DN
144 issuerKeyHash OCTET STRING, -- Hash of Issuers public key
145 serialNumber CertificateSerialNumber }
146 )
147
148 In order to accomadate the responder using a different hashAlgorithm than we used in the request we need to recalc these from the cert itself.
149
150 If all we have is a list of ocspresponses without knowing where they came from, we have to calculate the hashes of our issuerName and issuerKey for each hashAlgorithm we have cached ocsp responses for (optionally after limiting our candidates to those with matching serialNumbers first).
151
152 SELECT from ocsp_cache hashAlgorithm WHERE serialNumber = <SERIAL>
153
154 for hix = 0 hix < hashAlgorithms.count
155 ALG(hix).id = hashAlgorithms(hix)
156
157 SELECT from ocsp_cache response WHERE serialNumber = <SERIAL> hashAlgorithm = ALG(hix).id issuerNameHash = ALG(hix).hash(issuer) issuerKeyHash = ALG(hix).hash(key)
158
159
160
161
162
163
164 Notes for Matt:
165 - ttl in amfi cache (to force recheck when ocsp response is invalid)?
166 - Periodic check before launch to remove in band waiting for ocsp response?
167
168 Notes on Nonces in ocsp request and responses. Only ask for nonce if we think server supports it (no way to know today). Fall back on time based validity checking if reponse has no nonce, even if we asked for one
169
170 Note on CRL checking and experation and retries of OCSP checking.
171 Clients MAY attempt to retrieve the CRL if no
172 OCSPResponse is received from the responder after a locally
173 configured timeout and number of retries..
174
175
176
177 CRL/OCSP cache design idea:
178
179 revocation status table:
180
181 rowid certhash issuer-rowid lastUsed thisUpdate producedAt nextUpdate revocationTime revocationStatus
182
183 cacheAddOCSP(path, index_of_cert_resp_is_for, ocspResp)
184 cacheAddCRLStatus(path, index_of_cert_in_path, nextUpdate, revocationTime, revocationStatus)
185 (revocationTime, revocationStatus) = cacheLookupStatus(path, ix)
186
187 Return a list of parent certificate hashes for the current leaf. If a result is returned, we have a candiate path leading up to an anchor, for which we already trust the signature in the chain and revocation information has been checked.
188
189 CFArrayRef cacheSuggestParentsHashesFor(cert)
190
191 for crl based status root must match root of path. For ocsp status issuer must match issuer of leaf in path
192
193 presence in the cache means cert chain leading to an anchor is valid, and signed properly and trusted by the ocsp or crl policy, revocation status for cert is valid until the time indicated by nextUpdate. Cert chain itself may or may not be valid but that's checked by the policy engine.
194
195 If a chain isn't properly signed or fails to satisfy the crl policy, it should not be in the cache.
196
197 ocsp cache
198
199 rowid ocspResponse (responder) lastUsed nextUpdate
200
201 hashAlgorithm->(issuerNameHash,issuerKeyHash,serialNumber)->response
202
203
204 crl cache ()
205
206 crlDistributionPoint (reasons) crl thisUpdate nextUpdate isDelta
207
208
209 crlEntry cache table
210 (certHash anchorHash) crlIssuer revocationStatus revocationTime expires lastUsed
211 crlTable
212 (crlIssuer anchorHash distributionPointURL?) crl sigVerified expires
213 ocspEntry cache table
214 (certHash parentHash ocspReponderID) hashAlg revocationStatus revocationTime expires lastUsed
215 ocspTable
216 ((hashAlg, pubKeyHash, issuerHash, serialNum) anchorHash) ocspResponse sigVerified expires
217
218 or
219 cert cache table
220 (certHash parentHash anchorHash) crlEntryID ocspID
221
222 crlEntry cache table
223 (crlEntryID anchorHash) crlIssuer revocationStatus revocationTime
224
225 crlIssuerTable
226 (crlIssuer anchorHash) crl sigVerified
227
228 ocsp table
229 (ocspID) ocspResponse
230
231
232 but so does caching the raw response as a link to a blob table containing crls
233 and ocsp-responses
234 But also cache the revocationStatus for a (cert,parent) or (cert,anchor) via
235 a link to a cached ocspResponse or revocationStatus and revocationTime entry from crl
236 */
237
238 #endif